imagemagick - animate, with a static black background? - imagemagick

Just a quickie.
I have a series of images min*.png that I want to animate into a gif.
They are each fully transparent, except for some white dots on the area I want filled in for that frame.
Is there some way to create an animation from these such that the background is black (so that the whtie dots show up?)
I am interested in both:
black background, and paste each successive image on top of the previous ones (so frame i is the black background plus all of the dots up to image i)
each frame consists of just (image i on a black background)
I think for 1. I need to use -dispose none and for 2 I use -dispose background or -dispose previous, but various attempts at actually setting the background to black have failed (I have spent a lot of time reading this imagemagick page but am still learning).
e.g.
convert -background black -dispose background min*.png out.gif
various attempts with -background and -dispose have invariably produced a gif of my min*.png with a transparent background, not a black one. I think I'm close, but not sure.

This may be useful for the black background problem: starting from ImageMagick 6.7.5 you can remove transparency and replace it with a static color; you can read more about this command here
Hope this helps, unfortunately I have an older version of Imagemagick, so i can't try it myself
Example from ImageMagick documentation:
convert moon.png -background tan -alpha remove alpha_remove.png
The color "tan" replaces the transparent areas of the picture
Comment from mathematical.coffee
Using the above answer, I was able to generate the animations I wanted.
1: successive buildup of dots, all on a black background. Turned out to be as simple as creating a black background picture to put at the start of the animation, and using -coalesce:
# where bg.png is a black png of the appropriate size:
convert bg.png min*.png -coalesce out.gif
# in the below the first line creates the black background
# image, same size as my first min00.png image, for me:
convert min00.png -alpha Opaque +level-colors black \
min*.png -coalesce out.gif
2. use the method mentioned above:
convert min000*.png -background black -alpha remove out.gif
In both I was using imagemagick 6.7.something.

Related

Resizing animated GIF in image creates artifacts

I'm trying to add a blank area around some animated GIFs using imagemagick, but in many cases the resulting larger animations have artifacts. For example, if I start with this image
And run the following command (which has the dispose and coalesce flags which I've thrown in after seeing them online in the hopes they'll help)
convert input.gif -gravity center -dispose previous -extent 500x500 -coalesce output.gif
The result is the following
Is there a different command I can run that wouldn't gave the green splotches invade the original image?
You have your syntax wrong for ImageMagick and also need to use -dispose none. You are adding a new color to your animation which likely already used 256 colors.
Input:
convert -dispose none input.gif -coalesce -gravity center -background green -extent 500x500 -layers optimize output.gif
Change the background color as desired, which you left out of your command.

How to remove specific white space from image using ImageMagick

Currently, I have thousands of pictures where I want to get rid of white space around the object, but not inside the object. However, the white space is not constant. See pictures below.
Picture 1 :
Picture 2 :
Picture 3 :
Options like this don't work as they delete all white space in the images
convert image.png -fuzz 10% -transparent white output.png
Any suggestions?
What do you mean by getting rid of the white space? If you mean make it transparent, then in ImageMagick 6, you can do a whole folder of images using the mogrify command as follows:
The process involves padding the image with 1 pixel border of white to ensure white is all around. Then doing a fuzzy flood fill. Then remove the extra one pixel all around. I have assumed that the background color is nearly white. Change the fuzz value as desired.
Create a new directory to hold the output (or backup your input directory)
Change directory to the one holding your input images
mogrify -path path_to/outdirectory -format png -bordercolor white -border 1 -fuzz 20% -fill none -draw "matte 0,0 floodfill" -shave 1x1 *.png
Here are the resulting images.
Of course you will have to download them to see that they are transparent.
Note that the images that I downloaded were JPG. So if your images are jpg and not png as in your command, then change *.png to *.jpg. Or just use * to change all formats.
See
https://imagemagick.org/Usage/basics/#mogrify
https://imagemagick.org/Usage/draw/#matte
If using ImageMagick 7, change matte to alpha and change mogrify to magick mogrify.

Stop ImageMagick from pre-multiplying during composite

ImageMagick is premultiplying transparent pixels. This causes a gray outline to appear during subsequent transformations.
For example:
$ convert -size 1085x558 xc:"rgba(0,0,0,0)" PNG32:temp.png
$ composite -gravity center samples/logo_white.png temp.png PNG32:temp.png
Here are the source and resulting images.
Here is a video showing that the temp.png image has had its transparent pixels turned from white to black.
Is there a way to force ImageMagick to leave fully transparent pixels alone rather than changing them to black?

ImageMagick treating JPG and GIF differently in -alpha shape

I just encountered unexpected behavior in ImageMagick, which I'm hoping someone can explain to me.
Version numbers
$ convert --version
Version: ImageMagick 6.7.7-10 2013-02-25 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
Running on Linux Mint 15 Olivia (based on Ubuntu 13.04 "Raring Ringtail").
Executive summary
Running the same operation with two images that should be quite similar, except that one is a GIF while the other is a JPEG, the resulting output is entirely different. The GIF comes out black, the JPEG comes out white.
To reproduce:
Go to http://karenswhimsy.com/public-domain-images/animal-silhouettes/animal-silhouettes-1.shtm and download the elephant silhouette as elephant.jpg
Download http://www.arthursclipart.org/silhouettes/animals/DUCK1.gif as DUCK1.gif
convert elephant.jpg -negate -alpha shape output-elephant.png
convert DUCK1.gif -negate -alpha shape output-duck.png
Compare the output-elephant.png and output-duck.png images
Can anyone explain why these two output images are different? Why the GIF duck ends up being black after conversion, while the JPEG elephant becomes white after conversion?
Long-winded explanation
The situation is this: I want to take some black-and-white images, turn the background transparent, and turn the foreground different colors. For example, starting with the elephant silhouette at http://karenswhimsy.com/public-domain-images/animal-silhouettes/images/animal-silhouettes-1.jpg (I saved the image as elephant.jpg), I want to produce a .png with a transparent background and an elephant that's green, red, yellow, or whatever color I want.
The command I'm using to do this is:
convert elephant.jpg -negate -alpha shape +level-colors ,green green-elephant.png
This does exactly what I want. First it inverts the image so that the background is black and the elephant is white, because -alpha shape expects an alpha mask where black = fully transparent and white = fully opaque. Then -alpha shape does its magic and produces a white elephant against a transparent background. Then +level-colors ,green kicks in, transforming black-and-white gradients into the two colors specified as parameters to +level-colors; here, the first color is omitted so it would remain black, and the second color is what white turns into. This produces a green elephant with smooth borders -- exactly the result I want -- and I'm quite happy with it.
Next, I tried running the same command against one of the images from http://www.arthursclipart.org/silhouettes/animals.htm (I used DUCK1.gif). The input source is the same -- a black silhouette against a white background -- so I expected the same result, a green duck against a transparent background. But it didn't work. A little research showed me that -alpha shape was behaving differently. Where with the JPEG elephant it was producing a white elephant against a transparent background, with the GIF duck the same command was producing a black duck against a transparent background. In other words, -alpha shape was inverting the result with a GIF image source, but not with a JPEG image source. So to color the animal properly, I needed to rewrite the +level-colors parameters to put "green" before the comma instead of after.
Tweaking my script is no problem at all, but I'd love to understand why this is happening, and so far I'm clueless. Can anyone explain to me why ImageMagick is treating GIFs and JPEGs so differently in the -alpha shape operation?
OK, I think here is the story. With GIF, a background color might be explicitly defined, and I think that is the case with DUCK1.GIF. Not so with JPEG; here the background is, I think, assumed to be "white".
Whatever the case is, converting the DUCK1.GIF to DUCK1.JPG results in a similar image to the elephant. Moreover, you can make sure that the same background color is used with the apropriate Imagemagick option. The two commands below produce similar output:
convert DUCK1.jpg -background Black -negate -alpha shape output-duck.png
convert elephant.jpg -background Black -negate -alpha shape output-elephant.png

create toolbar imagelist with imagemagick

I'd like to use the ImageMagick convert tool to automatically generate a toolbar bitmap from several png images.
I'm using the following command line:
convert.exe -resize 32x32 #imagelist32.txt +append BMP3:toolbarlarge.bmp
with imagelist32.txt containing a list of png files (each one being one toolbar button).
This works, but the resulting bitmap uses black for the transparent color and white as the background color. I would need both colors to be RGB(192,192,192). Like if there was already an image with that background color, and the png images would be drawn on that background.
How can I do that? I've tried adding the -background #C0C0C0 and -transparent-color #C0C0C0 parameters but it didn't work - maybe I put them in the wrong order?
I know you've probably resolved it by your own, but I've been playing a bit with converter.exe some time ago, so I hope this is what you were looking for.
Set the -alpha parameter to the background flag, what means that every fully transparent pixel will be set to the background color, while leaving it fully transparent.
And set also the -background to a certain color RGB(192,192,192), so the previously transparent pixels will get this color.
convert.exe -resize 32x32 -alpha background -background RGB(192,192,192) #imagelist32.txt +append BMP3:toolbarlarge.bmp

Resources