-
Notifications
You must be signed in to change notification settings - Fork 2
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
Optimise images with imagemin #23
Comments
I have been considering image compression since this plugin's creation. I previously wanted to use Sharp, the fastest library; Sharp is used to compress screenshots on Hexo.io, which I helped to integrate (hexojs/site#1138). I hold off this feature because I've been using Statically.io CDN that optimize image on-the-fly, on my blog. Previously there was also installation issue, because Sharp requires installation of native library specific to Node version. The installation thing could've improved recently, so I might revisit it. |
Sounds cool, I might give statically a try! How did you integrate it with Hexo? I know that imagemin plugins don't require any manual intall (at least for the most part of them). Kudos for Sharp, the API looks very nice. And it looks like there no external dependencies outside of npm:
So far, I manually optimised my assets and then convert images to webp with the Works well enough but not very integrated to Hexo… "scripts": {
"webp": "find ./source/assets \\( -name '*.jpg' -o -name '*.jpeg' -o -name '*.png' -o -name '*.gif' \\) -exec bash -c 'imagemin -p=webp $1 > $1.webp' _ {} \\;"
}, |
If there is no reverse proxy, you can modify the script to prepend I don't need to upload image to Statically, just add an image link after To resize an image, for example to 320 pixels wide, Another point is, I'm reluctant to add image compression because I haven't find a sane default, there are too many parameters, particularly the responsive image. For instance, Safari hasn't support webp, so you need responsive image element for safe fallback; responsive image element has no sane default, I don't think the one I use in step3 script can apply to everyone. For now, I recommend hexo-filter-responsive-images. Possible enhancement to that plugin is webp support. |
It is pretty involved indeed. Responsive is another thing. I was just referring to compression without changing its definition: a 1000px * 1000px would be left untouched, but with proper compression it could go from 1.5Mb to 120Kb and also be converted to WebP. But as you highlighted, hexo-filter-responsive-images might be a good option. I'll take a look at it and see if there's a way to also generate WebP images. As for WebP, they can't replace jpeg as some browsers don't (and probably won't in the near future) support them. So images must be referrenced as jpeg (or gif or png, depending on the source format) and then it's the role of the web server to serve the more appropriate image based on the HTTP support header sent by the client browser. |
Hey there,
I think that could be an even moe complete plugin if you could include an image asset compression (in addition to SVG):
All of this can be done with imagemin.
Let me know what you think about it.
The text was updated successfully, but these errors were encountered: