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 »

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: 12159
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 »

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 »

Thank snibgo, it works :D
Post Reply