0
votes

I'm using Paperclip for my app and the images are not conforming to the sizes I have set them to. I'm using paperclip and rmagick and have ImageMagik installed. When I ran where convert I got

C:\Program Files\ImageMagick-6.8.9-Q16\convert.exe
C:\Windows\System32\convert.exe

Development.rb

Paperclip.options[:command_path] = "C:/Program Files/ImageMagick-6.8.9-Q16/convert.exe"

Gemfile

gem 'paperclip'
gem 'rmagick', '~> 2.13.2', :platforms => :ruby

User.rb

has_attached_file :avatar, styles: { medium: '210x260>', larger: "300x300>", thumb: "100x100>" }, default_url: "/assets/default.png"
validates_attachment_content_type :avatar, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]

view

<%= image_tag @user.avatar(**style**) %>

I'm testing it on two different images at different sizes, A (originally: 960x688 ) and B (originally: 160x160)

A(:thumb) becomes 100x72

B(:thumb) becomes 100x100

A(:medium) becomes 210x151

B(:medium) becomes 160x160

A(:larger) becomes 300x300

B(:larger) becomes 300x300

I've tried re-uploading the image after I change the size but get the same results. So, does paperclip have a problem with different size images or is there a problem with my code?

1
Try putting a # on the end as opposed to a >Richlewis
That fixed them, but i had to upload the image again each time I changed the style. Will I have to keep uploading the images when I change the style some place else if I have to?teddybear

1 Answers

1
votes

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