Resizing an image with mini_magick
You'd just use the resize
method from MiniMagick, there's an example on the Github page:
Presumably you have the image as a bunch of bytes in memory so something like this:https://github.com/minimagick/minimagick
image = MiniMagick::Image.read(your_image_bytes)
image.resize('612x612')
scaled_image_bytes = image.to_blob
# Or image.write(filename)
MiniMagick uses standard ImageMagick geometry strings for sizing and, from the fine manual, a WxH
geometry:so usingMaximum values of height and width given, aspect ratio preserved.
'612x612'
will scale the image to fit within a 612px square while preserving the aspect ratio.You could also use Jcrop to allow your web users to crop the their uploaded images to fit into a square.
How to resize image in imagemagick with rails?
This is an ImageMagick syntax thing. It's preserving aspect ratio instead of respecting your height argument.
Add a bang to force the dimensions image.resize "1080x1920"
image.resize "1080x1920!"
Related Topics
Alias_Method on Activerecord::Base Results in Nameerror
Generate Models from Existing Tables Using Rails 3
Using Rails Form Helpers with Serialized Custom Classes
Clean Install Osx 10.9.1 Returns "Undefined Method 'Path2Class'" When Trying to Install Gems
How to Send a Keep-Alive Packet Through Websocket in Ruby on Rails
Ruby/Active Record: Custom Sorting Order
Rails How to Create Data Schema Seed Data
Actionmailer Pass Local Variables to The Erb Template
Error Installing Gems: Cannot Load Such File - Zlib
Understanding The Behaviour of Inject Used with a Lambda in Ruby
Error: Failed to Build Gem Native Extension on Windows
Foreign Key (Class_Id) Not Populating in Belongs_To Association
Recommended Way to Generate a Presigned Url to S3 Bucket in Ruby
Dynamic Role Attributes in Chef