envygeeks / jekyll-assets

:art: Asset pipelines for Jekyll.
ISC License
1.11k stars 169 forks source link

unleash the full potential of ImageMagick inside jekyll-assets #624

Open dsmrs opened 5 years ago

dsmrs commented 5 years ago

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
envygeeks commented 4 years ago

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

dsmrs commented 4 years ago

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.

envygeeks commented 4 years ago

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