0

Using paper clip, how can I change the aspect ratio of uploaded image.

Which is easier? Doing with jcrop or paperclip ?

I think paperclip would be nice but not sure where/how to keep the config options.

user2349115
  • 1,288
  • 2
  • 17
  • 34
  • Would be nice if you accept correct answers. Looking at your profile I noticed you usually don't do that. Use green tick-mark to do so. – pawel7318 Apr 15 '14 at 12:43
  • Sure, I will do that. In the last question, the correct answer was deleted for some reason. – user2349115 Apr 15 '14 at 13:10

2 Answers2

1

As for the paperclip you can easy do this by specifying convert options directly in your model. For example:

has_attached_file :photo,
                  :preserve_files => true,
                  :styles => { :medium => "800x800>",
                               :small => "300x300>",
                               :thumb => "150x150>" },
                  :convert_options => { :medium => "-quality 70 -interlace Plane -strip",
                                        :small => "-quality 70 -interlace Plane -strip",
                                        :thumb => "-quality 70 -interlace Plane -strip" },
                  :default_url => "/images/missing.png"

you can use that way any ImageMagick's conver option.

All supported options are described here.

BTW: if you want it to be processed in background than add this to your Gemfile:

gem 'delayed_job'
gem 'delayed_job_active_record'
gem 'delayed_paperclip'
gem 'daemons'

and this to the model:

process_in_background :photo, queue: 'paperclip_processing'

to run/stop a daemon:

RAILS_ENV=production bin/delayed_job -n 2 start
RAILS_ENV=production bin/delayed_job stop

and to see the progress and manage the queue this is great:

gem 'delayed_job_web'

Enjoy.

pawel7318
  • 3,383
  • 2
  • 28
  • 44
0

You'll need to use ImageMagick to get Paperclip to crop images. Paperclip only handles the upload process - it doesn't crop or store the images for you


I would recommend looking at how to use Paperclip with ImageMagick, and then you'll have to find a way to populate your models' styles option with ImageMagick commands:

has_attached_file :image, styles: { medium: "[[imagemagick code]]" }

ImageMagick change aspect ratio without scaling the image

Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147