Resizing an Image with Mini_Magick

Resizing an image with mini_magick

You'd just use the resize method from MiniMagick, there's an example on the Github page:

https://github.com/minimagick/minimagick

Presumably you have the image as a bunch of bytes in memory so something like this:

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:

Maximum values of height and width given, aspect ratio preserved.

so using '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



Leave a reply



Submit