脚本宝典收集整理的这篇文章主要介绍了php – 挂钩进入WordPress图片上传,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我写了一个小侧插件,我激活它以挂钩上传动作.我的问题是,我应该挂钩哪个wp上传操作来生成上传图像的额外大小.
欢迎获取当前上载和写入额外图像条目的示例.
谢谢!
add_filter('wp_handle_upload_prefilter','custom_upload_filter' ); function custom_upload_filter( $file ){ $file['name'] = 'wordpress-is-awesome-' . $file['name']; return $file; }
function generate_image($src_file,$dst_file) { $src_img = imagecreatefromgif($src_file); $w = imagesx($src_img); $h = imagesy($src_img); $new_width = 520; $new_height = floor($new_width * $h / $w); if(function_exists("imagecopyresampled")){ $new_img = imagecreatetruecolor($new_width,$new_height); imagealphablending($new_img,false); imagecopyresampled($new_img,$src_img,$new_width,$new_height,$w,$h); } else { $new_img = imagecreate($new_width,false); imagecopyresized($new_img,$h); } imagesavealpha($new_img,true); imagejPEg($new_img,$dst_file); imageDestroy($src_img); imageDestroy($new_img); return $dst_file; }
以上是脚本宝典为你收集整理的php – 挂钩进入WordPress图片上传全部内容,希望文章能够帮你解决php – 挂钩进入WordPress图片上传所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。