lawmurray / jekyll-responsive-magick

A Jekyll plugin for responsive images using ImageMagick. Works with Jekyll 4.
https://indii.org/software/jekyll-responsive-magick
Apache License 2.0
11 stars 1 forks source link

`size` filter does not support webp image format #4

Closed d9beuD closed 8 months ago

d9beuD commented 8 months ago

Say I use the filter like {{ "/assets/img/test.png" | size: 480 }} then it outputs /assets/img/test-480w.png. But if the file is test.webp it outputs /assets/img/ without the file name.

I think it's because of the following line, but the srcset function has it too, yet it works.

https://github.com/lawmurray/jekyll-responsive-magick/blob/4f809ea4a0629f7ea728bb26629498446397479b/lib/jekyll-responsive-magick.rb#L145

lawmurray commented 8 months ago

Thanks @d9beuD. Happy to accept a pull request to fix this if you have the time. Probably just a case of adding .webp to the list of acceptable file extensions, as ImageMagick already supports the format I believe.

d9beuD commented 8 months ago

What do you think about checking the mime type of the file instead of the extension? I don't know Ruby enough to say if it's doable, but:

if File.exist?(src) and File.mime?(src, "image/*)

instead of the line I quoted in my original comment. If you're okay with this idea, assign me to the issue and I'll try my best to make it work.

lawmurray commented 8 months ago

Nice idea if you can get it working @d9beuD. That should open up support for any image formats that ImageMagick supports. Assigned you the ticket, thanks for the contributions!