[wp-trac] [WordPress Trac] #62389: add_image_size "crop" does not crop

WordPress Trac noreply at wordpress.org
Tue Nov 12 09:28:34 UTC 2024


#62389: add_image_size "crop" does not crop
--------------------------+-----------------------------
 Reporter:  kkmuffme      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:
 Severity:  minor         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 e.g. take an 500x500 picture and run this code:

 {{{#!php
 <?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?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62389>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list