Last active
June 15, 2017 04:18
-
-
Save Nervovred/7ea8473689b4651952dc8bf10e1c573e to your computer and use it in GitHub Desktop.
ImageMagick resize with round edges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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