Crop circles - How to crop many rectangular jpg's to a bunch of circles?
January 16, 2021 3:58 PM   Subscribe

I have a folder of .jpg's that I want to be able to change into circles (circles of content with a 100% transparent surround) - and want to maintain image quality. The .jpg's are a mix of squares and various aspect rectangles and I want the circle to have a diameter equal to the shortest dimension of the rectangle (to get as much content as possible).

I've found this but don't see how I can use it.

I've tried method one from this page

method is:
magick convert filename.jpg /( -size 960x650 xc:none -fill white -draw "circle 480,325 480,0" /) -compose copy_opacity -filename_one.jpg (I was hoiping to start with that one and use it as a base, and to understand what comes next)

Am currently getting no-where and getting except for "No such file or directory" errors.

IM is version 7.06, my systems is win10.

I've done a jpg to png conversion to check IM is installed currently and that worked fine with no dir errors.
posted by unearthed to Computers & Internet (7 answers total)
On Windows, I would try:

convert goat.jpg ( -size 960x650 xc:none -fill white -draw "circle 480,325 480,0" ) -compose copy_opacity -composite goat_method_one.png

That is, take out the back slashes from the original command -- those are a Unix shell thing, that doesn't work the same way on Windows. (On Unix, the \ character means "don't do anything special with the next character" -- in this case, the ( and ) characters; on Windows, \ is part of a filename. ImageMagick will also probably treat forward slash -- / -- as part of a filename, because it was originally designed for Unix.)
posted by reventlov at 4:41 PM on January 16

This one worked for me:
convert input.jpg ( +clone -fill black -colorize 100% -fill white -draw "circle %[fx:int(w/2)],%[fx:int(h/2)] %[fx:w>h?int(w/2):0],%[fx:w>h?0:int(h/2)]" -alpha off ) -compose copyopacity -composite -trim +repage result.png

This one is pretty good because it figures out what the image dimensions are automatically. The jpeg standard doesn't support transparency. So, if you want transparent you'll need to use PNG/GIF/etc.

Like reventlov noted, you need to drop the '\'.
posted by gregr at 6:48 PM on January 16

Do you need to actually alter the files themselves, or are you displaying these in a web page? If so, the CSS border-radius property can be used to make an image display with a circular crop.
posted by XMLicious at 6:59 PM on January 16

Hi Gregr, well it runs but only givers me a 1 pixel image, I'm trying to work out why (my original is 4032 x 3024).

reventlov - that works, just working out how to centre and enlargen circle.

XMLicious - I want to drag them into a CAD program - @maybe at some point I would do them in a webpage but not this time.
posted by unearthed at 7:15 PM on January 16

I believe you can do this in Canva, with their frames. Super easy and free.
posted by MexicanYenta at 5:55 AM on January 17

I think it will be easier to do this in 2 passes: first crop all the images to be the same width/height and then add the circle.

ImageMagick can do the first part based on the smallest size (height or width) with something like this:
convert input.jpg -filter lanczos -resize 128x -gravity center -crop 128x128+0+0 +repage result.png
posted by Lanark at 10:05 AM on January 17 [1 favorite]

Thanks gregr, after toying with that script I got it running! Tried about a dozen things until I realised that magick 7 uses copyAlpha instead of copyopacity

and learned a stack of things magick along the way.

magick HebeSalicifolia.jpg
( +clone -fill black -colorize 100% -fill white -draw "circle %[fx:int(w/2)],%[fx:int(h/2)] %[fx:w>h?int(w/2):0],%[fx:w>h?0:int(h/2)]" -alpha off )
-compose copyAlpha -composite -trim +repage HebeSalicifolia.png

posted by unearthed at 2:14 PM on January 17 [2 favorites]

« Older What is the most stain resistant white tee shirt...   |   Does a fitbit still make sense? Newer »

You are not logged in, either login or create an account to post comments