Thoughts
☀️🌚

22 June 2022

Create rounded images with Imagemagick


Create a mask

convert -size 300x300 xc:none -draw "roundrectangle 0,0,300,300,150,150" mask.png
Masked image will saved to the file system.

-size 300x300 is the size of created image.

300,300 refers to width and height of the image. This has to be adjusted according the image. That is the mask has to be the size of the original_image.

150,150 refers to the border radius of the mask. It determines the curves of the edges.

Apply the mask

convert original_image.png -matte mask.png 
  -compose DstIn -composite rounded_original_image.png
Above created mask will be used as frame to crop extra part of original image. This image will be the size of original image and that is why the above image is pushing this down..

Crop the Image

convert rounded_original_image.png -crop 300x300 rounded_original_image.png

Other Useful commands

  • Crop image using directions Use directions to crop part of an image.
convert original_image.jpg -gravity East -chop 1000x0 chopped_image.jpg
convert original_image.jpg -gravity West -chop 1000x0 chopped_image.jpg
convert original_image.jpg -gravity South -chop 0x1000 
-gravity West -chop 1000x0 
-gravity East -chop 1000x0 
-gravity North -chop 0x200 
chopped_image.jpg`
  • Crop image using origin in order of width x height + originX + originY
convert original_image.jpg -crop 1280x1280+500+125 chopped_image.jpg
  • Compress image

    magick original_image.JPG -resize 40% chopped_image.JPG

Good to have

  • Size of the original image should be enough to create rounded borders
  • Focus content of the image ideally should be in center of image as the edges will be cropped.