Rails peperclip - help crop the image - ruby-on-rails

Welcome, help crop the image,
has_attached_file: image, styles: {show: '540x505 #'}
trims as needed, but is centered on the (up), I need to image is not centralized, and trimmed the top
Original image:
Need:

You want to set the -gravity option to North when defining paperclip's style. Something like...
has_attached_file: image,
styles: {show: '540x505'},
convert_options: {show: ' -gravity North '}
See documents & example usage here.

Answer:
has_attached_file :image, styles: { show: '' },
convert_options: {show: '-gravity north -thumbnail 540x505^ -extent 540x505' }

Related

Resize missing.png depending upon style in paperclip

I'm using Paperclip to upload a image
here my paperclip configuration
has_attached_file :avatar,
:path => ":rails_root/public/users/:id/avatar/:style/avatar.jpg",
:url => "/users/:id/avatar/:style/avatar.jpg",
:default_url => "/missing/users/:style/missing.png",
:styles => {"47x47" => "47x47", "228x228" => "228x228","185x176"=>"185x176","pitch_planner"=>"262x129!"},
:convert_options => {"47x47" => "-background black -gravity center -extent 47x47",
"228x228" => "-background black -gravity center -extent 228x228","185x176" => "-background black -gravity center -extent 185x176"}
Now what if I want is to generate a resize image of missing.png depending upon the "style" How to achieve this in paperclip
One way to do it resize the image manually and store it inside folder pitch_planner or what ever styles you want to resize for
can it be done in programmatically through paperclip
Not with paperclip, but you could overwrite the method that looks for the default image, and use image magick to create it if not already present.
img = Magick::Image::read(default_image).first
img.resize_to_fit(75, 75)
img.write 'path'

How to resize and center image

I would like to set not square image to square and use for this square center of image. How to done it with paperclip?
This will take an image, crop in the center of the image at 500x500, then throw everything else away, then resize that new image back down to 100x100. It's used for generating square thumbnails, but you can adjust this for your needs.
has_attached_file :image,
:styles => { :thumb => "" },
:convert_options => {
:thumb => "-gravity Center -crop 500x500+0+0 +repage -resize 100x100^",
:default_style => :thumb

How do I get the top region of an image when cropping with Rails and Paperclip?

So I have a Rails 3 app using Paperclip to crop images.
I have this code in my model for Photo:
has_attached_file :thumbnail, PAPERCLIP_OPTIONS.merge(
:styles => {:cropped => '300x250#'})
The resulting image that's generated creates a 300x250 image, however the crop seems to always start a good 50px or so below the top of the image (not a good thing for social networking when it cuts off the top of peoples heads).
I did some research and I'm thinking I need to supply a :convert_options key that coincides with the :cropped style. However, I don't know exactly what options to set (-gravity, -region, etc.)
Anybody have any thoughts. I know there are Imagemagick pros; I'm not one, lol.
Thanks!
Update:
I found this link..
http://forrst.com/posts/Customized_Cropping_with_Paperclip-7g6
Is this still valid or does somebody have a better easier way?
Here's my favorite way to do it:
:styles => { :large => "", :medium => "", :thumb => ""},
:convert_options => {
:large => "-gravity north -thumbnail 300x300^ -extent 300x300" ,
:medium => "-gravity north -thumbnail 200x200^ -extent 200x200",
:thumb => "-gravity north -thumbnail 100x100^ -extent 100x100"
}
Note that instead of # you use ^ + extent.
Gravity parameters are like on a map: north, northeast, east ...

how to write this where paperclipe understands

I can do this command to resize an image to fit a specific size on the command line with Imagemagick. How do I tell paperclip can do the same when I upload an image:
convert Bisiye2.jpg -thumbnail '150x150^' -gravity center -extent 150x150 Bisiye2_tofit.jpg
has_attached_file :image, :styles => { :thumb => "150x150>" },
:convert_options => {:thumb => "-gravity center -extent 150x150"}

How to crop & fill with Paperclip (or RMagick)?

I upload a photo, it is a rectangle. How Can I get it resized and filled to a square ?
I mean when the photo is horizontal positioned it should have above and under it, two white fields (for keeping the shape of a square) and when it is vertically, it should have two white fields on the sides of the photo.
When I used PHP, a have used this http://www.verot.net/php_class_upload_samples.htm
Have a look at the
100x150, keeping ratio, filling top and bottom
example
I'm using Paperclip with RoR. How is the best way to do that ?
Here's what I used on a rails 3 app w/ paperclip. I used the following ImageMagick options to make it centered: background, compose, gravity and extent. I'm using the mini_magick processor.
has_attached_file :image,
:styles => { :large => ["855x570>", :jpg], :medium => ["432x288>", :jpg], :small => ["276x184>", :jpg], :tiny => ["195x130>", :jpg] },
:processor => "mini_magick",
:convert_options => {
:medium => "-background white -compose Copy -gravity center -extent 432x288",
:small => "-background white -compose Copy -gravity center -extent 276x184",
:tiny => "-background white -compose Copy -gravity center -extent 195x130"
}

Resources