Trouble resizing the default image with Paperclip
The solution I've been using is to specify the style for the default image:
has_attached_file :photo,
:styles => {
:tiny => "25x25#",
:thumbnail => "100x100#",
:small => "150x150>",
:medium => "300x300>" },
:default_url => "/images/default_:style.png"
Then create a default image for each style (eg: default_tiny.png that is 25x25px, etc...)
Hope that helps.
How do you setup Paperclip to default to clipping rather than resizing images
Try :square => '200x200#'
-- that should give you the square image you're looking for.
Paperclip set default images for all different styles
The :style
can be included in the default url string which allows you to make it dynamic:
has_attached_file :avatar,
:styles => {
:thumb => "60x60>",
:small => "80x80>",
:medium => "140x140>",
:large => "300x300>"},
:default_url => "/images/default_avatar_:style.png"
Paperclip not resizing images to specified dimensions
ImageMagick is maintaining the image aspect ratio
widthxheight> Change as per widthxheight but only if an image dimension exceeds a specified dimension
So for an image of 791 x 1015 pixels, it would be resized to an image of size 195 x 250. If you want it to fit in 400 x 250 ignoring aspect ratio, you must use widthxheight!
More info here:
http://www.imagemagick.org/script/command-line-processing.php#geometry
Paperclip: How to resize an image only if it is big enough?
(1) Is probably because Paperclip is decoding a JPEG and then writing/encoding a new JPEG. JPEG is a lossy format so each encoding degrades the image. You could use the convert_options
to adjust the JPEG quality but you'll probably have to accept some degradation in your JPEGs.
(2) is because Paperclip is doing as it's told. Paperclip uses ImageMagick to do the heavy lifting and the style dimensions are just ImageMagick geometry strings with one modification:
Paperclip also adds the “#” option (e.g. “50x50#”), which will resize the image to fit maximally inside the dimensions and then crop the rest off (weighted at the center).
Your :thumb
style uses "#" so you're telling Paperclip that you want a 80x80 image even if the image has to be scaled and cropped to get there. You can drop the "#" from the dimensions string and, if desired or appropriate, add one of the the other modifiers.
Paperclip not sizing correctly
You need to change your trailing character after your size dimensions, so in your case you need
medium: 210x260#
The documentation clearly states
Default behavior is to resize the image and maintain aspect ratio (i.e. the :medium version of a 300×150 image will be 200×100). Some commonly used options are:
trailing '#', thumbnail will be centrally cropped, ensuring the requested dimensions.
trailing '>', thumbnail will only be modified if it is currently larger requested dimensions. (i.e. the :small thumb for a 120×80 original image will be unchanged)
For your current images you can this in the console
Image.all.each {|s| s.image.reprocess! }
After which any other images you upload will not need reprocessing and will be resized as you require
Hope that helps
Related Topics
Rails 5 Actioncontroller::Invalidauthenticitytoken Error
Jruby: Import VS Include VS Java_Import VS Include_Class
How to Get the Unique Elements from an Array of Hashes in Ruby
How to Bypass Mass Assignment Protection
Strictly Convert String to Integer (Or Nil)
How to Use Ruby " Case ... When " with Inequalities
Write and Read a File with Utf-8 Encoding
Should I Check in '.Ruby-Gemset' And/Or '.Ruby-Version'
Differencebetween #Encode and #Force_Encoding in Ruby
Rails 4 User Roles and Permissions
Rails 3 Joins -- Select Only Certain Columns
Weird Rails Error "Permission Denied: Bin/Rails" for Old Rails Apps
Adding a Submit Button Image to a Rails Form