Skip to content
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: srcset support for post thumbnails #2919

Closed
ChrisBegley opened this issue Oct 29, 2015 · 13 comments · Fixed by #3029
Closed

Photon: srcset support for post thumbnails #2919

ChrisBegley opened this issue Oct 29, 2015 · 13 comments · Fixed by #3029
Assignees
Labels
[Feature] Photon aka "Image CDN". Feature developed in the Image CDN package and shipped in multiple plugins [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Milestone

Comments

@ChrisBegley
Copy link

I'm a huge fan of Photon and I've been following the responsive images project for the 4.4 release. I just tested out the latest Photon changes in the Master build of Jetpack with WordPress 4.4-beta2-35426 and the latest version of TwentySixteen. I noticed a few problems, here's my test site:
http://super.techyourworld.com/4-4-responsive-images-test/

It doesn't look like Photon is working on the post thumbnails. With Photon disabled, the scrset and sizes attributes are added as expected:

<img src="http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Batman_1989_0331" srcset="http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-300x202.jpg 300w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-1600x1076.jpg 1600w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-800x538.jpg 800w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-355x239.jpg 355w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-394x265.jpg 394w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-480x323.jpg 480w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-580x390.jpg 580w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-600x403.jpg 600w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-710x477.jpg 710w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-760x511.jpg 760w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-900x605.jpg 900w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-960x645.jpg 960w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-1065x716.jpg 1065w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-1160x780.jpg 1160w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-1182x795.jpg 1182w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-1440x968.jpg 1440w, http://super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331-1520x1022.jpg 1520w" sizes="(max-width: 1200px) 100vw, 1200px" data-id="5459" height="807" width="1200">

But with Photon activated, it strips out the srcset and sizes attributes:

<img src="http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=1200&amp;quality=85&amp;strip=info" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="Batman_1989_0331" data-id="5459">

This only appears to be happening on post thumbnails. The image I inserted into the actual post displays srcset and sizes, even with Photon activated:

<img src="http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?resize=840%2C1277&amp;quality=85&amp;strip=info" alt="~" class="aligncenter size-full wp-image-5460" srcset="http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=197&amp;quality=85&amp;strip=info 197w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=745&amp;quality=85&amp;strip=info 745w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=800&amp;quality=85&amp;strip=info 800w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=300&amp;quality=85&amp;strip=info 300w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=355&amp;quality=85&amp;strip=info 355w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=394&amp;quality=85&amp;strip=info 394w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=480&amp;quality=85&amp;strip=info 480w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=580&amp;quality=85&amp;strip=info 580w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=600&amp;quality=85&amp;strip=info 600w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=710&amp;quality=85&amp;strip=info 710w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=760&amp;quality=85&amp;strip=info 760w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=900&amp;quality=85&amp;strip=info 900w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=960&amp;quality=85&amp;strip=info 960w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=1065&amp;quality=85&amp;strip=info 1065w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=1160&amp;quality=85&amp;strip=info 1160w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=1182&amp;quality=85&amp;strip=info 1182w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=1440&amp;quality=85&amp;strip=info 1440w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=1520&amp;quality=85&amp;strip=info 1520w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_010.jpg?w=1600&amp;quality=85&amp;strip=info 1600w" sizes="(max-width: 1738px) 100vw, 1738px" height="912" width="600">

@kraftbj kraftbj added [Feature] Photon aka "Image CDN". Feature developed in the Image CDN package and shipped in multiple plugins [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it labels Oct 29, 2015
@kraftbj kraftbj changed the title Latest Photon changes + 4.4 responsive images Photon: srcset support for post thumbnails Oct 29, 2015
@kraftbj kraftbj added this to the 3.8.1 milestone Oct 29, 2015
@kraftbj
Copy link
Contributor

kraftbj commented Oct 29, 2015

Related: #2804 , which we've been tackling to add Photon + srcset support.

Confirmed that we're not playing nicely with Twenty Sixteen's post thumbnail. Not sure why yet :)

@ChrisBegley
Copy link
Author

Cool. I'm not a developer but I'd be more than happy to help out any way I can by testing.

@kraftbj
Copy link
Contributor

kraftbj commented Oct 29, 2015

Thanks @ChrisBegley! Core thumbnail retrieval happens in filter_image_downsize via the image_downsize filter, which looks like we need to adapt for srcset. This will be a little trickier since our support elsewhere will just be ignored if not running 4.4, while this would need to be versioned.

Confirmed the general area by trying add_filter( 'jetpack_photon_override_image_downsize', '__return_true' );, which short-circuits our filter on image_downsize, which returns the expected tags.

Notes for testing: Test on a single post page, not an archive, unless you also have Carousel deactivated. Of note, when we disable our filter, the srcset values are Photonized, just not the img src tag.

@zinigor zinigor self-assigned this Nov 6, 2015
@kraftbj
Copy link
Contributor

kraftbj commented Nov 10, 2015

This is actually a result of #2281. With the image_downsize filter, the URL, width, and height are returned as an array. Typically, all three have values when used generically with WordPress.

When Photon returns it, we return the URL, and, usually, false for both the width and height (see discussion on 2281 for the rationale).

The functions that filter and insert the srcset into the image tag for the thumbnail, though, use those values.

@dereksmart
Copy link
Member

@ChrisBegley, we've merged a patch for this in our master and master-stable branch. I'd like to take you up on your offer to test it out :)

If you'd rather wait for a beta, we'll be releasing one within a day or two.

Thanks in advance!

@ChrisBegley
Copy link
Author

No problem! I just tested it out. The srcset attributes are added to the post thumbnails now. However, it's not respecting the crops of the thumbnails. It's adding "?w" instead of "?resize" to the srcset Photon URLs. For example:

This:
http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=408

Should be this:
http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?resize=408,227

This is what I have in my functions.php file for the homepage thumbnails:

add_image_size( 'home-panel', 408, 227, true );
add_image_size( 'home-panel-300', 300, 167, true );
add_image_size( 'home-panel-353', 353, 196, true );
add_image_size( 'home-panel-392', 392, 218, true );
add_image_size( 'home-panel-555', 555, 309, true );
add_image_size( 'home-panel-600', 600, 334, true );
add_image_size( 'home-panel-706', 706, 393, true );
add_image_size( 'home-panel-784', 784, 436, true );
add_image_size( 'home-panel-816', 816, 454, true );
add_image_size( 'home-panel-900', 900, 501, true );
add_image_size( 'home-panel-1059', 1059, 589, true );
add_image_size( 'home-panel-1110', 1110, 618, true );
add_image_size( 'home-panel-1176', 1176, 654, true );
add_image_size( 'home-panel-1224', 1224, 681, true );
add_image_size( 'home-panel-1665', 1665, 926, true );

@kraftbj
Copy link
Contributor

kraftbj commented Nov 18, 2015

@ChrisBegley Is that the primary src, the srcset(s), or all of them?

@ChrisBegley
Copy link
Author

@kraftbj it's only the srcsets that aren't respecting the thumbnail crops. The primary src is correct. Here's what it's outputting:

<img src="http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?resize=408%2C227" class="attachment-home-panel size-home-panel wp-post-image" alt="Batman_1989_0331" srcset="http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=305 305w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=408 408w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=500 500w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=610 610w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=816 816w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=915 915w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=1000 1000w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=1224 1224w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=1500 1500w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=300 300w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=353 353w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=392 392w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=555 555w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=600 600w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=706 706w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=784 784w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=900 900w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=1059 1059w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=1110 1110w, http://i1.wp.com/super.techyourworld.com/wp-content/uploads/2015/10/Batman_1989_0331.jpg?w=1176 1176w" sizes="(max-width: 408px) 100vw, 408px" data-id="5459" data-comments-opened="" data-image-title="" data-image-description="" height="227" width="408">

@kraftbj
Copy link
Contributor

kraftbj commented Nov 18, 2015

Well, that's good news... this specific issue is being resolved, but failing at https://github.com/Automattic/jetpack/blob/master/class.photon.php#L582 that was fixed previously :)

Not sure if I'll be able to hit this today, but noting for @dereksmart and @zinigor that we'd need to checkout what is available to us via the core filter, probably, and set the args smarter than just using the w.

(Noting that the other issue should probably be re-opened, but I'm okay tracking this here since we'll get it fixed in the next day or so anyhow. #2804 )

@dereksmart
Copy link
Member

There was some discussion in #2885 about whether we should be grabbing the height as well through the 2nd param of the filter $size_array, and went against it b/c it "worked" with minimal intrusion. seems like we need them for custom image sizes. Let's try and add them in.

@dereksmart
Copy link
Member

of course as I was writing this @kraftbj wrote a patch <3

@dereksmart
Copy link
Member

@ChrisBegley we've pushed another patch for height dimensions. Mind giving it another spin?

@ChrisBegley
Copy link
Author

@dereksmart everything looks good!

One side note... When I just overwrote all of the files in the plugin folder, it was acting like Photon wasn't active. I had to deactivate Photon and reactivate Photon in order to see the changes here, but everything looks like it's working fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Photon aka "Image CDN". Feature developed in the Image CDN package and shipped in multiple plugins [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants