How to reduce the file size of large background images by over 93%(peterhrynkow.com)
peterhrynkow.com
How to reduce the file size of large background images by over 93%
https://peterhrynkow.com/performance/2019/01/13/blowing-up-images-to-make-them-small.html
16 comments
I got excited for a moment.
There is also a way to have a size reduction for somewhat intricate backgrounds: background-repeat.
https://en.wikipedia.org/wiki/Wallpaper_group
There is also a way to have a size reduction for somewhat intricate backgrounds: background-repeat.
https://en.wikipedia.org/wiki/Wallpaper_group
If you have flatter colors, no complex gradients, using PNG-8 can significantly reduce size. Photoshop can do this.
A very specific use case but a good thing to know. Click-bait title makes people here unhappy though.
About https://news.ycombinator.com/item?id=18931957 and https://news.ycombinator.com/item?id=18932740
Don't repost too much, read the part of the FAQ about reposts https://news.ycombinator.com/newsfaq.html
If you repost too much the mods may notice and ban your account, your site and other nasty stuff.
Also, try to stick to the original title https://news.ycombinator.com/newsguidelines.html
---
About this post: I think it would have been better to use another title like "How to use browser interpolation to reduce smooth mage size by 93%". The current title is misleading.
Don't repost too much, read the part of the FAQ about reposts https://news.ycombinator.com/newsfaq.html
If you repost too much the mods may notice and ban your account, your site and other nasty stuff.
Also, try to stick to the original title https://news.ycombinator.com/newsguidelines.html
---
About this post: I think it would have been better to use another title like "How to use browser interpolation to reduce smooth mage size by 93%". The current title is misleading.
[deleted]
Thanks for letting me know about the rules. I’ve updated the blog post title as you suggested.
I’ve added another example to demonstrate how the technique can be used on blurry photographic backgrounds as well: https://peterhrynkow.com/performance/2019/01/13/blowing-up-i...
There isn't any sort of spec to ask the browser to use specific scaling algorithms, right?
I think the general idea is safe enough -- images of gradients are probably going to look fine upscaled in any algo that would actually get shipped. But there's no guarantee that tomorrow Mozilla won't decide their new mission statement is to spread the gospel of nearest neighbor.
I think the general idea is safe enough -- images of gradients are probably going to look fine upscaled in any algo that would actually get shipped. But there's no guarantee that tomorrow Mozilla won't decide their new mission statement is to spread the gospel of nearest neighbor.
I think bicubic is here to stay since so many responsive websites depend on the browser to scale images smoothly.
Not really, closest thing is https://developer.mozilla.org/en-US/docs/Web/CSS/image-rende...
Spoilers: make them smaller
you could also achieve the same (or very close) result with CSS gradients alone.
Layering CSS gradients doesn’t work, unfortunately: https://stackoverflow.com/questions/14926189/creating-a-grad...
Or SVG gradients I believe.
To achieve the same effect, you would need a “gradient mesh” which is not supported by the current version of SVG.
Mesh gradients were slotted for SVG 2.0 but the feature has since been removed from the roadmap.
http://libregraphicsworld.org/blog/entry/gradient-meshes-and...
Mesh gradients were slotted for SVG 2.0 but the feature has since been removed from the roadmap.
http://libregraphicsworld.org/blog/entry/gradient-meshes-and...
Reminds me of this: https://jmperezperez.com/svg-placeholders/
Reminds me of the early 2000 years when I, as a teen, was fiddling around with 16x16 images for striped backgrounds etc.
That said: Sorry if you only found this out in 2019.
That said: Sorry if you only found this out in 2019.
Why would any website have a background image where this would work? Just use a solid color if you want to use gradients.
Or layer CSS gradients. Images of any kind are unnecessary.
That doesn’t work, unfortunately: https://stackoverflow.com/questions/14926189/creating-a-grad...
Another method that I've personally used I explained over a year ago; you can see my explanation here https://news.ycombinator.com/item?id=15704879
Thanks for all the comments. I’ve updated the title and some of the wording to address the feedback given here.
The "technique" shown here is to convert a jpg to a png. As you would expect, this does not work for all images.
No, the "technique" is to
1. use only smooth gradients for your background (LOL)
2. remove most of your pixels
3. assume that the browser will interpolate for you (Also LOL)
If this had been called "pictures of smooth gradients don't need to be high res if your viewer interpolates them sufficiently well" then it would be accurate and sound a lot less noobish.
1. use only smooth gradients for your background (LOL)
2. remove most of your pixels
3. assume that the browser will interpolate for you (Also LOL)
If this had been called "pictures of smooth gradients don't need to be high res if your viewer interpolates them sufficiently well" then it would be accurate and sound a lot less noobish.
I agree, but your comment would have been much better without the "LOL".
about 3: most browsers have a good interpolation method for smooth images. It's a safe assumption if you have time to read all the documentation and you drop the support for IE6. (Perhaps IE6 can also interpolate correctly. I don't know and I'm not going to try to find the docs. IIRC I once had problems with the autostretching of the background image in IE6.)
about 3: most browsers have a good interpolation method for smooth images. It's a safe assumption if you have time to read all the documentation and you drop the support for IE6. (Perhaps IE6 can also interpolate correctly. I don't know and I'm not going to try to find the docs. IIRC I once had problems with the autostretching of the background image in IE6.)
Are you familiar with any web browsers that would not do a "sufficiently well" job of interpolating? I wouldn't expect a browser to use anything less than bilinear, which is fine for the use case presented. The author freely admitted that the technique isn't universal for all images.
I'm no web design expert, but I'm surprised gradients such as that aren't defined via CSS or some other programmatic means.
CSS definitely supports gradients in theory but perhaps the way they work is not to the liking of designers / their audience / their clients
https://www.w3schools.com/css/css3_gradients.asp
https://www.w3schools.com/css/css3_gradients.asp
CSS gradients have 2 notable annoyances:
- Simple horizontal, vertical, or radial gradients can rarely capture the "organic" look that most designers want (the gradients of real materials and scenes are highly uneven so perfect symmetry has a distinctly artificial appearance).
- I'm not sure if it's actually an aspect of the spec, but all implementations I've seen interpolate the colors in RGB or an RGB-like colorspace. This can have the effect of creating dramatic jumps or ridges. With a lot of trial and error (or color math) you can overcome this by using custom stop values, but it's much simpler and more in-line with a designer's toolset to be using colorspaces whose linear interpolations are more perceptually uniform.
Of course there's also the "standard drawback" of modern webdev too: it's often easier to just throw assets at the problem. :/
(Thoughts from a design-adjacent dev.)
- Simple horizontal, vertical, or radial gradients can rarely capture the "organic" look that most designers want (the gradients of real materials and scenes are highly uneven so perfect symmetry has a distinctly artificial appearance).
- I'm not sure if it's actually an aspect of the spec, but all implementations I've seen interpolate the colors in RGB or an RGB-like colorspace. This can have the effect of creating dramatic jumps or ridges. With a lot of trial and error (or color math) you can overcome this by using custom stop values, but it's much simpler and more in-line with a designer's toolset to be using colorspaces whose linear interpolations are more perceptually uniform.
Of course there's also the "standard drawback" of modern webdev too: it's often easier to just throw assets at the problem. :/
(Thoughts from a design-adjacent dev.)
That is part of the spec. CSS colour 4 allows colours to be defined in using different colourspaces, but the gradient spec continues to dictate linear interpolation of the RGB values.
Eh, I'm not fussed about that. The example images used are smooth but still rather complex. It would be hard for your average bear to codify them programatically.
Usually they would be. I’m sure there is a rare exception for why you would want to create it as a raster image, but for the usual cases I run across CSS is far more flexible.
Embedded gradient images for use in emails for clients without CSS gradient support, possibly.
In this specific case I can see why layered CSS gradients would be non-trivial to assemble, but it’s a trade off.
Example: https://stackoverflow.com/questions/14926189/creating-a-grad...
Embedded gradient images for use in emails for clients without CSS gradient support, possibly.
In this specific case I can see why layered CSS gradients would be non-trivial to assemble, but it’s a trade off.
Example: https://stackoverflow.com/questions/14926189/creating-a-grad...
Yeah, agree -- I over-simplified it.
jpg to png is a minor factor. The main one is "if your image is astoundingly blurry, make it much much smaller".
Which is great if you have an astoundingly blurry image, and useless if you don't.
Which is great if you have an astoundingly blurry image, and useless if you don't.
Png's works best for logo's and other computer drawn "images". JPG is the "best" format for photos. if i need to pick between png or jpg, that's what i do.
Not strictly true - JPG is best only if you need smaller images at the expense of image quality. I save photos as PNG all the time if I want to keep them losslessly.
> Disclaimer: I know very little about image scaling
This person also knows very little about web browsers. Warning: Do not follow their advice when making your website.
> When the small image is enlarged, the browser uses an interpolation algorithm to fill in the missing image data.
"the browser". Hah. As if there's just one.
This person also knows very little about web browsers. Warning: Do not follow their advice when making your website.
> When the small image is enlarged, the browser uses an interpolation algorithm to fill in the missing image data.
"the browser". Hah. As if there's just one.
While a certain amount of snark may be justified I’m pretty sure we can assume the author is aware their is more than one browser. Are you aware of browsers that don’t interpolate as described?
Why is this on the front page?