You are viewing an old revision of this post, from April 14, 2015 @ 07:06:33. See below for differences between this version and the current revision.

WordPress custom image size cropping

Taken from: http://www.danielauener.com/wordpress-custom-image-size-crop-how-to-fix/ [php]if (function_exists('add_image_size')) { add_image_size( 'dummy-1', 940, 450, true ); add_image_size( 'dummy-2', 480, 0 ); } global $_wp_additional_image_sizes; foreach ( $_wp_additional_image_sizes as $name => $image_size ){ update_option( $name."_size_w", $image_size['width'] ); update_option( $name."_size_h", $image_size['height'] ); update_option( $name."_crop", $image_size['crop'] ); } add_filter( 'intermediate_image_sizes', 'regenerate_custom_image_sizes' ); function regenerate_custom_image_sizes( $sizes ){ global $_wp_additional_image_sizes; foreach ( $_wp_additional_image_sizes as $name => $size ){ $sizes[] = $name; } return $sizes; }[/php] If you are using custom image sizes in your WordPress theme you likely know the problem. Cropping, rotating or flipping an image via the WordPress image editor, works just on the original. After editing the image is not available in your custom sizes anymore, all you get in your theme is the edited version in original size. I thought that there has to be a simple solution to this problem, because it is pretty basic after all. But a quick google search just got me not working code. Finally I found some code on pastebin that pointed me in the right direction. Copy and paste the above code into your functions.php, adjust the image sizes and even your cropped images should be available in your custom sizes.

Revisions

  • April 14, 2015 @ 07:06:33 [Current Revision] by PeterLugg
  • April 14, 2015 @ 07:06:33 by PeterLugg

Revision Differences

There are no differences between the April 14, 2015 @ 07:06:33 revision and the current revision. (Maybe only post meta information was changed.)

Tags: ,

No comments yet.

Leave a Reply