Resize Existing Images to New Style in Paperclip & Rmagick

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



Leave a reply



Submit