How to crop gif images into circle

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
bkstorm
Posts: 8
Joined: 2017-04-27T23:22:30-07:00
Authentication code: 1151

How to crop gif images into circle

Post by bkstorm » 2018-03-05T00:29:30-07:00

I have a gif image like this:
Image

I want to crop it into a circle.
Here is the command which I use to crop images, it works fine with static images (png, jpeg, ...), but it doesn't work with animations (gif images).

Code: Select all

convert bird.png -alpha on \( +clone -channel a -evaluate multiply 0 +channel -fill white -draw 'circle 128,128 0,128' \) -compose DstIn -composite bird-circle.png
How can I do that? Thanks.
Here is information about ImageMagick:
Version: ImageMagick 6.7.8-9 2017-09-20 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

snibgo
Posts: 10561
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to crop gif images into circle

Post by snibgo » 2018-03-05T01:06:16-07:00

Your code nearly works with Gif. The trick is to use "-layers composite", and a NULL: image. See http://www.imagemagick.org/script/comma ... php#layers

I've converted to Windows BAT syntax. You'll need to convert it back to bash.

Code: Select all

convert ^
  giphy3.gif ^
  -layers coalesce ^
  -alpha on ^
  NULL: ^
  ( -clone 0 ^
    -channel a -evaluate multiply 0 +channel -fill white ^
    -draw "circle 128,128 0,128" ^
    -repage +122+122 ) ^
  -compose DstIn -layers composite ^
  bird-circle.gif
The "-repage" centralises the circle. Adjust to taste.
snibgo's IM pages: im.snibgo.com

bkstorm
Posts: 8
Joined: 2017-04-27T23:22:30-07:00
Authentication code: 1151

Re: How to crop gif images into circle

Post by bkstorm » 2018-03-05T02:46:30-07:00

Thank snibgo, it works :D

Post Reply