How to save image as progressive image using paperclip/Imagemagick?
Code I am using:
has_attached_file :photo, {
:styles => {
:medium => ["200x200#", :jpg] ,
:small => ["192x256#", :jpg],
:thumb => ["50x50#", :jpg],
:small_thumb =>["30x30#", :jpg]
},
:convert_options => {
:medium => "-quality 60",
:small => "-quality 60",
:thumb => "-quality 60",
:small_thumb => "-quality 60"
},
:default_url => "/assets/default_:style.png" }.merge(PAPERCLIP_STORAGE_OPTIONS)
Simply add -interlace Line in the convert_options of your choice.
Doc states explicitly:
Use Line or Plane to create an interlaced PNG or GIF or progressive JPEG image.
Related
Is there any way to shorten this code for this?? It looks so miserable
has_attached_file :logo, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
has_attached_file :image1, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
has_attached_file :image2, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
has_attached_file :image3, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
You could do something like this:
[:logo, :image1, :image2, :image3].each do |image_symbol|
has_attached_file image_symbol, :styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => "/images/:style/missing.png"
end
Hope this helps :).
I was doing some image optimization on my site. Things are working awesome on development machine but in production mode I am getting an error ie:
ActionView::Template::Error (can't dup Symbol):
This is happening only in case of aws, If I remove this then things working perfectly fine:
A code I was using and was working perfectly:
has_attached_file :attachment, {
:styles => {
:medium=>"654x346>",
:small => "260x400>",
:thumb => "75x75#",
:facebook_meta_tag => "200x200#"
}, :include_updated_timestamp => false
}.merge(PAPERCLIP_STORAGE_OPTIONS)
But now I modified this and Its working perfectly fine in development environment but not working on production environment.
has_attached_file :attachment,
:styles => {
:medium => {
:geometry => "654x346>",
:quality => 60,
:format => 'JPG'
},
:small => {
:geometry => "260x400>",
:quality => 60,
:format => 'JPG'
},
:thumb => {
:geometry =>"75x75#",
:quality => 60,
:format => 'JPG'
},
:facebook_meta_tag => {
:geometry =>"200x200#",
:quality => 50,
:format => 'JPG'
}
}.merge(PAPERCLIP_STORAGE_OPTIONS)
Other relevant settings:
PAPERCLIP_STORAGE_OPTIONS = {
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/amazons3.yml",
}
amazons3.yml
production:
access_key_id: XXXXxxxXXXXxxx
secret_access_key: XXXXxxxXXXXxxxXXXXxxxXXXXxxxXXXXxxxXXXXxxx
bucket: images.XXXXxxx.com
Here is the working code:
has_attached_file :attachment, {
:styles => {
:medium => ["654x346>", :jpg],
:small => ["260x400>", :jpg],
:thumb => ["75x75#", :jpg],
:facebook_meta_tag =>["200x200#", :jpg]
},
:convert_options => {
:medium => "-quality 60",
:small => "-quality 60",
:thumb => "-quality 60",
:facebook_meta_tag => "-quality 60"
}
}.merge(PAPERCLIP_STORAGE_OPTIONS)
ActionView::Template::Error tends to be an error raised inside of a view (Rails re-wraps errors inside views inside ActionView::Template::Error exceptions).
To help you more I'd need to see the backtrace and the view involved.
This is not really an answer, but if this helps you find the cause you may as well accept it.
I am running Ruby on Rails 3 and I would like to reduce the quality of an uploading image using the Paperclip plugin/gem. How can I do that?
At this time in my model file I have:
has_attached_file :avatar,
:styles => {
:thumb => ["50x50#", :jpg],
:medium => ["250x250#", :jpg],
:original => ["600x600#", :jpg] }
that will convert images in to the .jpg format and will set dimensions.
Try using convert_options.
has_attached_file :avatar,
:styles => { :thumb => '50x50#' },
:convert_options => { :thumb => '-quality 80' }
From the paperclip wiki, there's an option for quality:
class User < ActiveRecord::Base
has_attached_file :photo,
:styles => {
:small => {
:geometry => '38x38#',
:quality => 40,
:format => 'JPG'
},
:medium => {
:geometry => '92x92#',
:quality => 50
}
end
As James says, once you figure out the correct arguments to pass to ImageMagick's convert by experimenting on the command line, you can pass these in to Paperclip through the convert_options option as in James' example.
If you have multiple arguments, pass them in as an array. Here's an example which I laboured over for a while:
:convert_options => {:medium => ["-shave", "2x2", "-background", "white",
"-gravity", "center", "-extent",
"530x322", "+repage"],
:small => ["-shave", "1x1"] }
Except -quality, the -strip option of ImageMagick can remove all profile and other fluff from the image which may reduce more size
has_attached_file :photo,
:styles => {
:thumb => "100x100#" },
:convert_options => {
:thumb => "-quality 75 -strip" }
I have a rectangular image for example 30x800 pixels
How I can scale it with paperclip to preserve the aspect ratio to a 100x100 pixel image with borders filling the empty area ?
an example : http://www.imagemagick.org/Usage/thumbnails/pad_extent.gif
has_attached_file :image, :styles => { :thumb => "100x100>" },
:convert_options => {:thumb => "-gravity center -extent 100x100"}
Or with not white background
has_attached_file :image, :styles => { :thumb => "100x100>" },
:convert_options => {:thumb => "-background red -gravity center -extent 100x100"}
I'd like to know how to convert png and gif files with alpha channel to jpg with white background with paperclip
I tried this but, it doesn't work
has_attached_file(
:photo,
:whiny => false,
:styles => {
:medium => ["300x300>", :jpg],
:thumb => ["100x100>", :jpg]
},
:convert_options => { :all => '-alpha white -background white'}
)
It saves the file with the gray background.
here the solution
has_attached_file :photo,
:styles => {
:medium => ["300x300>",:jpg],
:thumb => ["100x100>", :jpg]
},
:convert_options => {
:all => '-background white -flatten +matte'
}
-alpha remove -background white is preferable. white is not a valid argument for -alpha.