admin管理员组

文章数量:1122846

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

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 );

What am I doing wrong?

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

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 );

What am I doing wrong?

Share Improve this question edited Feb 17, 2017 at 5:11 winchendonsprings asked Feb 14, 2017 at 0:03 winchendonspringswinchendonsprings 1233 silver badges9 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 4

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:

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

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:

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:

  • multiresize
  • _resize
  • image_resize_dimensions

6yrs later, does anyone know if its still the case that you cannot set up add_image_size() in such a way as to do what the OP desired here? I'm also looking to create a cropped thumbnail from the original image without scaling it down first. Thanks

本文标签: Crop image without scaling or resizing with addimagesize()