jekyll-assets icon indicating copy to clipboard operation
jekyll-assets copied to clipboard

unleash the full potential of ImageMagick inside jekyll-assets

Open dsmrs opened this issue 5 years ago • 3 comments

  • [ ] This feature is not on the latest version

Request

I'm trying to build a super low consumption website, one way is to "dithering" the images from the website. The option is already available in ImageMagick, but not on the ones supported by jekyll-assets. Not a Jekyll expert, neither ruby, but I would love to have this feature implemented.

A (bad) example of implementation

{% asset my_image.png magick:resize=930 magick:colors=4 magick:colorspace=gray magick:define=png:color-type=3 %}

In assets/plugins/proxy/magick.rb

       def process
          img = ::MiniMagick::Image.new(@file)
          magick_format(img) if @args[:magick][:format]
          img.combine_options do |c|
            @args[:magick].keys.reject { |k| k == :format }.each do |k|
              m = "magick_#{k}"

              if respond_to?(m, true)
                method(m).arity == 2 ? send(m, img, c) : send(m, c)
              end

              # send any key to ImageMagick
              if img.respond_to?(k, true)
                c.send(k, @args[:magick][k])
              end

            end
          end

          @file
        ensure
          img&.destroy!
        end

dsmrs avatar Oct 15 '19 12:10 dsmrs

I don't know if I trust implicit forwarding with something that could potentially hit the system.

envygeeks avatar Mar 06 '20 23:03 envygeeks

I don't know if I trust implicit forwarding with something that could potentially hit the system.

Agreed! That's why I said a "bad" implementation ^^ We could build an array with only the safest functions of ImageMagick? to filter what we pipe to it.

dsmrs avatar Mar 11 '20 21:03 dsmrs

If you can provide a list I can see what I can work out. That would be a workable solution IMO.

envygeeks avatar Mar 12 '20 00:03 envygeeks