Resize existing images to new style in paperclip & RMagick
You want the reprocess!
method of Paperclip::Attachment. See the docs.
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
# Console...
>> User.find_each { |u| u.avatar.reprocess! }
Also, according to the comments before the reprocess!
method, there's a paperclip:refresh Rake task, which might be easier.
Resize original image in Paperclip
I'm not sure paperclip does resizing by itself. You might have to look at Rmagick to get this done. I would try to get RMagick going (or minimagick) and then use a before_save callback to execute a :resize
method that you write that tells RMagic to resize the image. Your method might look like:
class Image < ActiveRecord::Base
belongs_to :profile
before_save :resize
def resize
self.image = self.image.resize "1024x1024"
end
end
or
class Image < ActiveRecord::Base
belongs_to :profile
before_save do
self.image = self.image.resize "1024x1024"
end
end
Resize an image with Paperclip
You can use "160x160#" which will scale and crop to exactly that size, which is unique to paperclip. Otherwise you can use any of the ImageMagick geometry strings, detailed here:
ImageMagick Geometry
But I'll quote the one you're interested in:
"160x160!"
Width and height emphatically given,
original aspect ratio ignored.
rmagick rotate and resize to fit specified dimensions in paperclip
No answer found. I ended up switching to Carrierwave and encountering another set of problems which I've finally arrived at a solution for. Too bad Carrierwave doesn't log the processing of images, but that's a small price to pay.
Carrierwave RMagick not removing transparency in convert to jpg
Carrierwave +repage option not working
Rails Paperclip Plugin - Style Options for Resizing
Try using 380x
This should resize width to 380px and keep original aspect ratio.
For all available options for resizing images go here: http://www.imagemagick.org/script/command-line-processing.php?ImageMagick=lj6pre8q2iautc3ch6nuph1fc2#geometry
Resize images with paperclip with amazon s3
You can specify the style in the model
styles => { :first=> "10x10", :second=> "20x20", :third=> "30x30", ....},
and after you made your new styles just use the rake task paperclip provides
rake paperclip:refresh CLASS=User
where User is the model in this case
This will go on every user and regenerate the images
see more here
https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation
Related Topics
Proc Throws Error When Used with Do End
How to Use Link_To with Ajax in Rails 3.2.1
Define a Class Method in a Module
Save Google Cloud Speech API Operation(Job) Object to Retrieve Results Later
Sum of All Amount If Charge Dates Are the Same in Stripe
Make a Ruby Script with Text Io Double Clickable Executable File
Ruby, No Implicit Conversion of Symbol into Integer
Sending Form Data to Remote Rails Application Using Httparty
Regex to Extract Boundary and Content Type Out of Mail Headers
Use Some Middleware Only for Specific Rack Website
Rails Cors Issue with Ajax API Endpoint Request
How to Count the Frequencies of the Letters in User Input
Watir Won't Download PDF, Only Opens in Viewer
Regex to Remove the Webpage Part of a Url in Ruby