0
當上傳到wordpress我想保存圖像兩次,一次黑色和白色,一次作爲其默認值。我有以下的代碼做這個:克隆一個背面和白色的圖像到wordpress
add_action('after_setup_theme','bw_images_size');
function bw_images_size() {
add_image_size('themename-bw-image', get_option('thumbnail_size_w'), get_option('thumbnail_size_h'), false);
}
add_filter('wp_generate_attachment_metadata','themename_bw_filter');
function themename_bw_filter($meta) {
$file = wp_upload_dir();
$file = trailingslashit($file['path']).$meta['sizes']['themename-bw-image']['file'];
list($orig_w, $orig_h, $orig_type) = @getimagesize($file);
$image = wp_load_image($file);
imagefilter($image, IMG_FILTER_GRAYSCALE);
switch ($orig_type) {
case IMAGETYPE_GIF:
imagegif($image, $file);
break;
case IMAGETYPE_PNG:
imagepng($image, $file);
break;
case IMAGETYPE_JPEG:
imagejpeg($image, $file);
break;
}
return $meta;
}
的問題是,它保存在縮略圖大小的黑色和白色版本,但我希望它保存在原來的尺寸。我知道這發生在以下行:
add_image_size('themename-bw-image', get_option('thumbnail_size_w'), get_option('thumbnail_size_h'), false);
但我不知道如何在這裏得到原始大小。如何才能做到這一點?