Automattic / jetpack

Security, performance, marketing, and design tools — Jetpack is made by WordPress experts to make WP sites safer and faster, and help you grow your traffic.
https://jetpack.com/
Other
1.59k stars 799 forks source link

Photon: Image sizes added based on containing element, not $content_width #7291

Open laurelfulford opened 7 years ago

laurelfulford commented 7 years ago

An issue has been reported with the Espied theme on self-hosted sites, where Photon is enabled.

On the Portfolio Project pages, the theme uses a larger image size, and uses JavaScript to add a CSS class for images over 1272px in width, which is used to style the images larger than the content. You can see an example of that here:

https://espieddemo.wordpress.com/portfolio/chrome-for-ios7-2/

The special class is being applied to self-hosted sites running Photon, but the image is not displaying at the correct size.

Steps to reproduce the issue

  1. On a self-hosted, non-local site, apply the Espied theme.

  2. Make sure Jetpack is installed. Under Jetpack > Settings, turn off "Speed up images and photos".

  3. Create a Portfolio Project, and insert an image larger than 1272px wide. Make sure to set the image is set to display at the 'Custom' or 'Full Size'.

  4. Publish the project, and view on the front end. You'll see a larger image:

image

The output for the image will look something like:

<img data-attachment-id="21" data-permalink="http://www.testsite.com/portfolio/project-1/photo-1416339306562-f3d12fefd36f/" data-orig-file="http://www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg" data-orig-size="4000,3000" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="photo-1416339306562-f3d12fefd36f" data-image-description="" data-medium-file="http://www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f-300x225.jpeg" data-large-file="http://www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f-1024x768.jpeg" class="alignnone size-full wp-image-21 size-big" src="http://www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg" alt="" width="4000" height="3000" srcset="http://www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg 4000w, http://www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f-300x225.jpeg 300w, http://www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f-768x576.jpeg 768w, http://www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f-1024x768.jpeg 1024w, http://www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f-840x630.jpeg 840w, http://www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f-480x360.jpeg 480w" sizes="(max-width: 4000px) 100vw, 4000px">

  1. Go back to Jetpack > Settings, and turn on "Speed up images and photos".

  2. View the portfolio post again.

What I expected

That the image would look the same.

What happened instead

The image displays at a smaller size. However, the JavaScript in the theme still applies the class to the image, as though it's a larger image, so it's outdented to the left:

image

The output for this image is:

<img data-attachment-id="21" data-permalink="http://www.testsite.com/portfolio/project-1/photo-1416339306562-f3d12fefd36f/" data-orig-file="https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?fit=4000%2C3000" data-orig-size="4000,3000" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="photo-1416339306562-f3d12fefd36f" data-image-description="" data-medium-file="https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?fit=300%2C225" data-large-file="https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?fit=1024%2C768" class="alignnone size-full wp-image-21 size-big" src="https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?resize=1272%2C954" alt="" srcset="https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?w=4000 4000w, https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?resize=300%2C225 300w, https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?resize=768%2C576 768w, https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?resize=1024%2C768 1024w, https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?resize=840%2C630 840w, https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?resize=480%2C360 480w, https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?w=2544 2544w, https://i1.wp.com/www.testsite.com/wp-content/uploads/2017/06/photo-1416339306562-f3d12fefd36f.jpeg?w=3816 3816w" sizes="(max-width: 1272px) 100vw, 1272px" width="552" height="414">

The problematic bit is the width="552" height="414" at the end.

I've experimented with this a bit. Adjusting the $content_width for the theme does not affect this. However, changing the width of the containing element via CSS does.

For example, if I remove this from the style.css, the image will display at full width:

@media screen and (min-width: 37.5em) {
    .page-content,
    .entry-content,
    .entry-summary {
        width: 552px;
    }
}

It will still include an inline width attribute, but it will use the width set by the theme's $content_width.

If I change the width to 800, the width attribute will match that. If I change it to something higher than the image, it'll stick to the width set by the $content_width.

In Espied, the issue seems to be that Photon gets the image's width on load, and uses that; then the theme's JavaScript checks to see the actual image size (which is still large, even though a width attribute is being used to make it look smaller) and adds the class used by the theme for large images. Then the styles are applied, but the image stays small.

I was wondering why the size is being inserted? It doesn't actually change the image's physical size (which uses the $content_width), just the size it displays at. If it's to make sure it doesn't display too large, themes should be doing that via a max-width in the CSS.

It may be possible to strip out the height and width attributes in the theme via JavaScript, but that seemed a bit hacky. I wanted to double-check why Photon's inserting the sizes first.

laurelfulford commented 7 years ago

Related theme tickets:

4024-wpcom-themes 3965-wpcom-themes

jeherve commented 7 years ago

Related: #4175

laurelfulford commented 6 years ago

There's another report of this, with the Intergalactic 2 theme:

5013-wpcom-themes, 972453-zd

sixhours commented 6 years ago

When this is fixed, this thread needs follow up: https://wordpress.org/support/topic/portfolio-image-size-problem-with-photon-plugin?replies=1

zinigor commented 6 years ago

Related: 973272-zen In this particular case Photon overrides the element width and height attributes and just sets the width to the parent element.

thesacredpath commented 6 years ago

Wondering if this issue is going to be fixed. A self-hosted user first posted about it here, https://wordpress.org/support/topic/full-image-and-jetpack-photon/, and then reposted just recently here, https://wordpress.org/support/topic/conflict-with-photon-still-not-fixed/.

jeherve commented 6 years ago

@thesacredpath We don't have an ETA at the moment, but we will update this issue when we make some progress on this.

cc @RavanH

thesacredpath commented 6 years ago

Thanks @jeherve, I'll let the user know.

RavanH commented 6 years ago

Thanks @jeherve for alerting me to this thread. I'm currently using the CSS (added to Custom CSS) kindly suggested by @dcoleonline on https://wordpress.org/support/topic/full-image-and-jetpack-photon/ and it seems to work well...

stale[bot] commented 6 years ago

This issue has been marked as stale. This happened because:

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.

stale[bot] commented 5 years ago

This issue has been marked as stale. This happened because:

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.

Robertght commented 3 years ago

This is still happening. Found it in #4284341-zen with Morden.

sguzovskaia commented 2 years ago

Another one. Found it in #4645708-zen with Exford.