2

Both of these tend to shrink the image and then crop it to the dimensions listed.

What I want is to just crop out the center of the image at 475 x 310

add_image_size( 'test', 475, 310, array( 'center', 'center' ) );
add_image_size( 'test2', 475, 310, true );

BTW I'm using the regenerate-thumbnails plugin to recreate all the images after I make a new add_image_size() deceleration.

Here is an image 1400 x 788 pixels, where I added a pink box directly in the center which is 475 x 310 pixels enter image description here

I've uploaded the image to though my post. Rather than what I want which is crop the image at the pink box it is first scaled down and then cropped to the smaller dimension. Seen below is the new image from my wp-content/uploads directory produced from add_image_size( 'test', 475, 310, array( 'center', 'center' ) ); also the same result when I change that bit to add_image_size( 'test', 475, 310, TRUE ); enter image description here

What am I doing wrong?

2

You cant do that with the add_image_size() function, after a lot of research and digging in the core files, what the Hard Crop option of the add_image_size() function actually does is resize the image using the lower dimension, then it will crop the size specified

by example if you create a new image size:

add_image_size( 'test2', 475, 310, true );

and upload an image like this one:

enter image description here

it will resize the image using the height 310 (since is the lower value) keeping the aspect ratio, like this:

enter image description here

then it will proceed to crop the image using the resized image, based in the position that was send or the default center , center, the red square overlapping is the size 475, 310 and is the area that will be cropped:

enter image description here

enter image description here

enter image description here

it may look like the top and bottom dont matter, but that is because the image was resized using the height, if it was the other way around, the width being the lower the image would be tall and the left and right would look like they dont matter.

To accomplish what you are trying to do, you will need a plugin or a developer who will add the necessary code to your theme, it cant be done right now with the default built-in tools of wordpress.

These functions are the ones that are doing all this:

  • I added a new image with a box marked in the center with my dimensions from in add_image_size('test2', 475, 310, TRUE); Still the image seems to be scaled down to 475 and then cropped at 310 vertically. This is with regenerating thumbnails and a fresh upload. – winchendonsprings Feb 15 '17 at 22:19
  • can you add to your question the original image and the resized one wordpress is creating please – David Lee Feb 15 '17 at 23:51
  • I've edited my question with image descriptions. Hope this helps – winchendonsprings Feb 17 '17 at 5:13
  • I've tested this now. @DavidLee from my test using center center hard crop to a 300x130 size. It first resizes to 300px wide and then crops the top and bottom of the pic. It doesn't resize to the lowest value. At least not for me. – Michael Rogers Feb 6 '18 at 14:59
  • yeah, my answer is based on his image, i am guessing that your original image is tall and not wider? (height > width) – David Lee Feb 6 '18 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.