Opened 6 years ago
Last modified 6 years ago
#43930 new defect (bug)
Inaccurate width and height returned when using wp_get_attachment_image_src on the backend.
Reported by: | jwoolsch | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.9.5 |
Component: | Media | Keywords: | |
Focuses: | Cc: |
Description
I'm using wp_get_attachment_image_src on the backend to do image validation for a custom image selector meta box. When the image is large enough for the requested image size the source of the original image is returned but the dimensions are smaller.
This is my call:
<?php wp_get_attachment_image_src($thumbnail_id, 'custom-image-size');
and return:
array(4) { [0]=> string(70) "http://localhost:8888/wp-content/uploads/2018/05/image.jpg" [1]=> int(400) [2]=> int(400) [3]=> bool(false) }
The actual image dimensions are 1200x1200.
The image_constrain_size_for_editor call in the image_downsize function seems to be where the problem lies. I can comment out that line and it works as expected.
Change History (2)
Note: See
TracTickets for help on using
tickets.
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:
and I added another:
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: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.
and finally, the custom one:
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.