Skip to content

Instantly share code, notes, and snippets.

@Nervovred
Last active June 15, 2017 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nervovred/7ea8473689b4651952dc8bf10e1c573e to your computer and use it in GitHub Desktop.
Save Nervovred/7ea8473689b4651952dc8bf10e1c573e to your computer and use it in GitHub Desktop.
ImageMagick resize with round edges
in_pic = "in.jpg"
out_pic = "out.jpg"
radius = 25
size = "500x500"
bgcolor = "white" #JPG doesn't support alpha channel, write "None" if you want transparent edges for PNG files
cmd = "convert #{in_pic} " +
"-resize #{size}! " + #comment out this line if you don't want to resize
"\\( +clone -alpha extract " +
"\\( -size #{radius}x#{radius} xc:black -draw 'fill white circle #{radius},#{radius} #{radius},0' " +
"-write mpr:arc +delete \\) " +
"\\( mpr:arc \\) -gravity northwest -composite " +
"\\( mpr:arc -flip \\) -gravity southwest -composite " +
"\\( mpr:arc -flop \\) -gravity northeast -composite " +
"\\( mpr:arc -rotate 180 \\) -gravity southeast -composite \\) " +
"-alpha off -compose CopyOpacity -composite -compose over " +
"\\( +clone -background black \\) +swap -background #{bgcolor} -layers merge #{out_pic}"
`#{cmd}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment