[wp-trac] [WordPress Trac] #43930: Inaccurate width and height returned when using wp_get_attachment_image_src on the backend.

WordPress Trac noreply at wordpress.org
Wed May 2 16:20:07 UTC 2018


#43930: Inaccurate width and height returned when using wp_get_attachment_image_src
on the backend.
-------------------------------+------------------------------
 Reporter:  jwoolsch           |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Media              |     Version:  4.9.5
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------
Changes (by subrataemfluence):

 * keywords:   => reporter-feedback
 * version:   => 4.9.5


Comment:

 Welcome to Trac and thanks for the ticket!

 I tried my hand but could not reproduce the issue at my end with a fresh
 WordPress 4.9.5 install and `twentyseventeen` theme activated.

 The above theme provides us the following two custom image sizes:

 {{{#!php
 <?php
 add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true );
 add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );
 }}}


 and I added another:
 {{{#!php
 <?php
 add_image_size( 'custom-image-size', 300, 300, true );
 }}}


 Then I uploaded an image of dimension 4000x1973

 `wp_get_attachment_image_src` got me the right dimension of image with
 correct image path. Here are the results:

 {{{#!php
 <?php
 $thumbnail_id = 175;
 wp_get_attachment_image_src($thumbnail_id, 'twentyseventeen-thumbnail-
 avatar'); // 100 x 100

 array(4) { [0]=> string(76) "http://local.storelocator.com/wp-
 content/uploads/2018/05/fclarge-100x100.jpg" [1]=> int(100) [2]=> int(100)
 [3]=> bool(true) }
 }}}


 as you see the image dimension is only 100x100, which is way small than
 the one originally uploaded and I am still getting the right file name.

 {{{#!php
 <?php
 wp_get_attachment_image_src(175, 'twentyseventeen-featured-image'); //
 2000 x 1200

 array(4) { [0]=> string(78) "http://local.storelocator.com/wp-
 content/uploads/2018/05/fclarge-2000x1200.jpg" [1]=> int(2000) [2]=>
 int(1200) [3]=> bool(true) }
 }}}


 and finally, the custom one:

 {{{#!php
 <?php
 wp_get_attachment_image_src(175, 'custom-image-size'); // 300 x 300

 array(4) { [0]=> string(76) "http://local.storelocator.com/wp-
 content/uploads/2018/05/fclarge-300x300.jpg" [1]=> int(300) [2]=> int(300)
 [3]=> bool(true) }

 }}}

 here also the image dimension is much smaller than the original one but I
 get the correct file name.

 If I have understood the issue correctly and followed the right steps to
 recreate the issue as you stated, I would like to know if there is any
 third party plugin activated along with a third party theme. If this is
 the case I would suggest to use a native theme like `twentyseventeen`,
 disable all plugins that you might have an then try to reproduce.

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


More information about the wp-trac mailing list