-
Notifications
You must be signed in to change notification settings - Fork 383
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
How to make small images stretch to full width #1137
Comments
So I noticed that replacing the default "intrinsic" layout with "responsive" fixes the issue. Though, I had to do this is the plugin's code for now to make it work. Is there any filter I can use to change the layout from "intrinsic" to "responsive" on images in functions.php ? Thank you. |
In the meantime, I've edited class-amp-img-sanitizer.php to add a filter to be able to choose between the "intrinsic" layout and "responsive": Change the following lines in class-amp-img-sanitizer.php:
To this:
Add this to your functions.php and replace "responsive" with whatever layout you want:
P.S. This will NOT stick through updates. I'm still wondering if the small images not stretching to the full width of the viewport is the expected behaviour of the "intrinsic" layout. Could somebody enlighten me on this please ? Thanks. |
Thanks, Looking At This Now Hi @janvitos, In the meantime, it's also possible to set a layout directly on the image. Though I'd imagine you're looking for a more programmatic solution. When the plugin finds this in the post content (or anywhere in Native AMP or Paired Mode): <img data-amp-layout="responsive" ...> It will convert it on AMP endpoints to: <amp-img layout="responsive" ...> Update: I just corrected the attribute from |
Expected Behavior Of layout="intrinsic" Hi @janvitos, It looks like
(emphasis mine) This is a little different from how I thought If the default layout were https://legacy-ampconfdemo.pantheonsite.io/2018/05/11/test-small-image-layout/amp/ But let me see if there's a programmatic way to get the effect you're looking for. |
Hi @kienstra, thanks for the reply and all the info. After reading your reply, I understand that layout="intrinsic" does not stretch to fill the viewport by default. This is a behaviour I currently use a lot on my site, especially for animated gifs that often have a much smaller resolution than other images because of file size limitations. So since layout="intrinsic" seems to be the default way the AMP plugin is going, what I did is add a filter in the code to be able to change layout="intrinsic" to layout="responsive" in my theme's functions.php file (see my third post) according to my needs. Though, I know this won't stick with updates. I was thinking maybe it would be a good idea to have this filter added to the plugin so people can choose between "intrinsic" and "responsive"? Or maybe there's already a way to do it without changing the plugin's code? Thank you. |
Question About Use Case Hi @janvitos, Are there a lot of images that you'd like to make There's a new feature in the upcoming |
Hi @janvitos, We could consider that as a use case where |
I honestly think layout="responsive" is still a better fit for all my images since they aren't always properly sized and identically sized. I'd be interested to see if others might also prefer this behaviour for their sites. I assume most blogs would want it. But maybe I'm wrong ;) Most images fit properly in the viewport with layout="intrinsic", but it does leave the smaller ones looking pretty bad when displayed alongside bigger images. I can show you a screenshot to show you what I mean. Give me a few moments. |
So here's the first screenshot with layout="intrinsic": Here's the second screenshot with layout="responsive": If you'd like to inspect the code, just let me know and I'll provide you the URL. |
Thanks! Hi @janvitos, If you're comfortable with it, it'd be great if you could share a URL of the site, so we can see the display on different viewports. And how many images there are. But no pressure 😄 |
Instead of a filter, in the current |
Hi @kienstra, it's my pleasure. Here's an AMP URL to that same post shown in the screenshots: https://www.ipnoze.com/shibas-chiens-droles/amp/ The current layout is "responsive". Should you need to do some tests with the "intrinsic" layout on that URL, I could easily change that for you. Thanks. |
So I got your suggestion working @kienstra and used the following filter to add the data-amp-layout attribute on all images:
This is exactly what I wanted. Should I mark this ticket closed? If you still want to investigate on the matter I'll be glad to assist. But for my part, everything is now working properly. Thank you so much for your time and expertise. |
Thanks! Hi @janvitos, |
Hi,
So I've been playing with the amp plugin and its CSS to make small images stretch to full width (100%), but I can't seem to figure out how.
Sometimes I have images that are smaller than the viewport, and for some reason, they don't take the full width although they are added automatically to the content with layout="intrinsic" by the plugin. The only way I was able to make the images stretch properly was to set "display: block" on the "amp-img" tag and "width: 100%" on the "i-amphtml-intrinsic-sizer" tag. If not setting "width: 100%", the image takes the full width but ratio is not maintained and the image looks stretched.
Though, after changing the CSS for the "i-amphtml-intrinsic-sizer" tag, Google started reporting issues, stating I could not modify that tag. So now I'm all out of ideas.
Any help will greatly be appreciated.
Thank you.
The text was updated successfully, but these errors were encountered: