Instantly share code, notes, and snippets.

@bobbus /README.md forked from scottatron/README.md
Last active Apr 13, 2017

Embed
What would you like to do?
Dragonfly and ImageOptim setup

This runs provides an .optim job for dragonfly and also adds the .optim job into .thumb

This requires you have the 'image_optim' gem and it's dependencies.

class OptimizedThumb < Dragonfly::ImageMagick::Processors::Thumb
def call(*args, &block)
super
args[0].process!(:optim)
end
end
Dragonfly.app.configure do
### Image Optim processor
processor :optim do |content|
if optimized = ImageOptim.new.optimize_image(content.path).presence
# We have to use a Tempfile which copy the optimized image because optimized correspond to a Tempfile path which may be deleted
tempfile = Tempfile.new('optimized-image')
begin
optimized.copy(tempfile.path)
content.update tempfile
ensure
tempfile.close # here we cannot use `close!` because of https://github.com/markevans/dragonfly/issues/319
end
end
end
processor :thumb, OptimizedThumb.new
end
@sachin87

This comment has been minimized.

Show comment
Hide comment
@sachin87

sachin87 Jul 15, 2014

could you show me your complete dragonfly.rb code?

sachin87 commented Jul 15, 2014

could you show me your complete dragonfly.rb code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment