Crop image without scaling or resizing with add_image_size()

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:

Leave a Comment