New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Photon does not return dimensions with `wp_get_attachment_image_src` #2281

Closed
bfintal opened this Issue Jun 20, 2015 · 5 comments

Comments

Projects
None yet
7 participants
@bfintal
Copy link

bfintal commented Jun 20, 2015

If you do this:

$attachmentImage = wp_get_attachment_image_src( 1234, 'full' );
$url = $attachmentImage[0];
$width = $attachmentImage[1];
$height = $attachmentImage[2];

$width and $height should give out the image dimensions, but when Photon is activated, both don't get returned.

The workaround for this is discussed here: https://wordpress.org/support/topic/wp_get_attachment_image_src-changed?replies=5#post-3950371

The workaround is to get the dimensions without Photon, then get the image URL normally:

add_filter( 'jetpack_photon_override_image_downsize', '__return_true' );
$imageInfo = wp_get_attachment_image_src( 1234, 'full' );
remove_filter( 'jetpack_photon_override_image_downsize', '__return_true' );

$attachmentImage = wp_get_attachment_image_src( 1234, 'full' );
$url = $attachmentImage[0];
$width = $imageInfo[1];
$height = $imageInfo[2];

Fix should be that those dimensions should still be applied when Photon is activated.

@kraftbj kraftbj added this to the 3.7 milestone Jun 20, 2015

@georgestephanis

This comment has been minimized.

Copy link
Member

georgestephanis commented Jun 22, 2015

From what I recall this was an intentional decision early on, but I don't recall the exact details.

@jeherve

This comment has been minimized.

Copy link
Member

jeherve commented Jun 22, 2015

cc @ethitter, who will probably know more.

Related issue: #607

@bfintal

This comment has been minimized.

Copy link

bfintal commented Jun 24, 2015

I would like to revisit this.

@georgestephanis & @jeherve I found the old thread, and here's the reason why it's closed:

From @ethitter:

We made this decision when first building the module because while we know the original dimensions, and images are likely to come back from Photon at the same dimensions, we can't be sure that this is the case. The Photon service doesn't return any meta about the resized image, so to avoid possible distortion of the image, we omit the dimensions.

Since Photon essentially modifies the url of the image to serve it from another location, I would think that the only thing changed in the behavior in WP functions is the url of an image.

In my case, I use the dimensions returned by wp_get_attachment_image_src for position calculations. It doesn't feel right that my plugin gets division by zero errors when Photon is activated. The workaround by @georgestephanis works great, but this adds 3-4 lines of Jetpack specific code.

In my opinion, the function should work like before, only that that the url is now different. Since the Photon service doesn't return any image meta data, then if we use the width & height data of what WordPress has stored already, then the original function behavior can be upheld.

What do you guys think?

@kraftbj

This comment has been minimized.

Copy link
Contributor

kraftbj commented Nov 18, 2015

Fixed via #3029 in support of #2919. Any and all testing on JP 3.8.1-beta1 (shipping soon) is greatly appreciated.

@kraftbj kraftbj closed this Nov 18, 2015

@kraftbj kraftbj modified the milestones: 3.8.1, Needs Triage Nov 18, 2015

@bfintal

This comment has been minimized.

Copy link

bfintal commented Nov 19, 2015

Thank you for fixing this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment