![]() Notice that translate 2000, 2500 are the coordinates for the middle of the canvas. This canvas is filled with the image, a circle is drawn in the middle, and everything around the circle is removed.įinally, the image is saved as “circle.png”. This creates an empty canvas of the given size, which should be the size of the image that you want to round. Like this: MiniMagick::Tool::Convert.new do |img| If you’re looking to make your image rounded, then you’ll need to combine a set of methods. ![]() You can play around with these numbers until you find the crop you’re looking for. You can crop parts of an image to remove things you don’t want & make it smaller.įor example, if you want to cut the lower half of an image: image.crop "100%x50%+0+0"įor a vertical crop of half the image: image.crop "50%x100%+0+0" If you opened the image for direct modification (using new, instead of open) then you don’t need to use write. Here’s how: image.write("/tmp/new_image.jpg") You need to apply the changes by writing the file back to disk. This is a resize to 25% of the original size, not a resize BY 25%. This gives you an exact dimension, but if you want to scale the image to a percentage while keeping the aspect ratio intact… You can resize an image like this: image.resize "500x500" Now that you have the image loaded you can get information about it, like its size, dimensions, format, etc.Īlso, I would like to rotate it so it’s horizontal instead of vertical. You can load the image like this: require 'mini_magick' I’m going to use this image from Unsplash, a free photo sharing site. The open method takes both a file name & a URL, so you can pull images directly from the web. MiniMagick::Image.new => Changes the original image.MiniMagick::Image.open => Makes a copy of the image.Let’s see some examples! Opening an Image Then with mini_magick you can use regular Ruby methods to make changes to your images. You need to install ImageMagick using your operating system package manager, or downloading the installer from the project’s website. It helps you apply all sorts of transformations to your images to customize them to your needs! It’s an interface between the ImageMagick program & your Ruby code. Like resizing them to save space & faster download for your users. If you work with any kind of images in your Ruby application, there is a good chance that you’ll want to change them in one way or another. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |