Last active
September 30, 2015 04:13
-
-
Save adam12/7e6db5840980da918dde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
. | |
. | |
. | |
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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