[wp-trac] [WordPress Trac] #40370: add_image_sizes does not create the "crop position" versions of the image

WordPress Trac noreply at wordpress.org
Wed Oct 10 13:36:37 UTC 2018


#40370: add_image_sizes does not create the "crop position" versions of the image
-------------------------------------------------+-------------------------
 Reporter:  piejesus                             |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Media                                |     Version:  2.9
 Severity:  normal                               |  Resolution:
 Keywords:  needs-patch needs-unit-tests good-   |     Focuses:
  first-bug                                      |
-------------------------------------------------+-------------------------
Changes (by joemcgill):

 * keywords:  dev-feedback => needs-patch needs-unit-tests good-first-bug
 * milestone:  Awaiting Review => Future Release


Old description:

> I wanted to introduce 3 different version of post thumbnails - each with
> different cropping position (top, center, left) , so i added them like
> this:
>
> {{{#!php
> add_image_size( 'newscentered', 400, 400, array( 'center', 'center') );
> add_image_size( 'newstop', 400, 400, array( 'center', 'top' ) );
> add_image_size( 'newsbottom', 400, 400, array( 'center', 'bottom' ) );
> }}}
>

> Now, whenever i use the the_post_thumbnail() with the name of my custom
> image size i always get the same image, cropped to the default WordPress
> crop position of ('center', 'center') .
>
> Why is that happening? I did 'refresh' the thumbnails and tried also
> uploading fresh image files and still i can't get 3 differently cropped
> versions of the image.
>
> I noticed that when i set the cropping defaults using the following
> function and set the cropping there, then it works:
>
> {{{#!php
> set_post_thumbnail_size( 400, 400, array('center', 'bottom'));
> }}}
>

> ... but it affects the cropping of all of my thumbnails, so i can only
> get one "crop position" for all my images.
>
> Guys, is this some kind of bug or do i configure something in a wrong
> way?
>
> I'm using the newest official Wordpress version

New description:

 I wanted to introduce 3 different version of post thumbnails - each with
 different cropping position (top, center, left) , so i added them like
 this:

 {{{#!php
 add_image_size( 'newscentered', 400, 400, array( 'center', 'center') );
 add_image_size( 'newstop', 400, 400, array( 'center', 'top' ) );
 add_image_size( 'newsbottom', 400, 400, array( 'center', 'bottom' ) );
 }}}


 Now, whenever i use the the_post_thumbnail() with the name of my custom
 image size i always get the same image, cropped to the default WordPress
 crop position of ('center', 'center') .

 Why is that happening? I did 'refresh' the thumbnails and tried also
 uploading fresh image files and still i can't get 3 differently cropped
 versions of the image.

 I noticed that when i set the cropping defaults using the following
 function and set the cropping there, then it works:

 {{{#!php
 set_post_thumbnail_size( 400, 400, array('center', 'bottom'));
 }}}


 ... but it affects the cropping of all of my thumbnails, so i can only get
 one "crop position" for all my images.

 Guys, is this some kind of bug or do i configure something in a wrong way?

 I'm using the newest official WordPress version

--

Comment:

 This is indeed an oversight in the way file naming occurs. I'd be +1 for a
 patch that adds a hash to the end of the filename whenever a crop position
 is included in the image size. So something like:
 `filename-{width}x{height}-{hash}.ext`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/40370#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list