Skip to content

Instantly share code, notes, and snippets.

@adam12
Last active September 30, 2015 04:13
Show Gist options
  • Save adam12/7e6db5840980da918dde to your computer and use it in GitHub Desktop.
Save adam12/7e6db5840980da918dde to your computer and use it in GitHub Desktop.
require 'dragonfly'
# Adding image_optim to Dragonfly
image_optim = ImageOptim.new(nice: 20, threads: 4, verbose: true, advpng: { level: 4 }, jpegoptim: { strip: :all }, jpegrecompress: { quality: 2 }, optipng: { level: 4 }, pngcrush:{ chunks: :alla } )
# Configure
Dragonfly.app.configure do
plugin :imagemagick
# Image optimization processor.
processor :image_optim do |content, *args|
optimized = image_optim.optimize_image_data(content.data)
content.update(optimized) if optimized
puts "********************************"
puts "optimized"
puts "****************************"
end
.
.
.
.
class Image < ActiveRecord::Base
include Concerns::Utils
belongs_to :user
dragonfly_accessor :asset do
after_assign {|img| self.asset = img.image_optim }
storage_options do |attachment|
{ headers: {"x-amz-acl" => "public-read-write"} }
end
end
abs_url_for :asset
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment