Opened 3 weeks ago
Last modified 7 days ago
#62389 new defect (bug)
add_image_size "crop" does not crop
Reported by: | kkmuffme | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | minor | Version: | |
Component: | Media | Keywords: | has-patch |
Focuses: | docs | Cc: |
Description
e.g. take an 500x500 picture and run this code:
<?php $editor = wp_get_image_editor( $path_to_a_jpg ); if ( $editor instanceof WP_Image_Editor_Imagick ) { $editor->make_subsize( array( 'width' => 147, 'height' => 147, 'crop' => true, ) ); }
Whether you run it with crop true or false, you get the same image.
Bc logically, "crop" in WP context only refers to the initial dimensions, not the final dimensions.
If you look at https://developer.wordpress.org/reference/functions/add_image_size/
Image cropping behavior. If false, the image will be scaled (default).
If true, image will be cropped to the specified dimensions using center positions.
However, this is misleading. Since the image will be scaled in BOTH cases.
The difference is not that the image gets scaled in one, but not scaled in the other.
The difference is simply, that crop true guarantees that both specified dimensions are used.
While crop false, only ensures this for one dimension.
I guess this should be improved in the docs?
Thanks for this @kkmuffme. Would you be able to create a patch with a suggested alternative?