Doubt regarding GIF creation from set of images

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
appu
Posts: 29
Joined: 2013-09-20T10:10:02-07:00
Authentication code: 6789

Doubt regarding GIF creation from set of images

Post by appu »

Hi,

I'm using ImageMagick for verifying functionalities of my application. I wrote scripts which will verify the behaviour using Compare command utilities and it is working fine for me.

I am saving image when a comparison failed. So need to analyze the current failed image against the precaptured image to know, what went wrong during failure. Initially I composed a difference between precaptured and current failed image, but when those two are entirely different screens in application, it is very difficult for me to interpret the diff image.

precaptured : Image

current application image : Image

While going through IM tutorials, I read that we have options to create GIF images. So planning to save a GIF of image during the image comparison failure case as below

convert -delay 30 -loop 10 two.jpg one.jpg two.jpg out.gif

out.gif : Image

Here as per tutorial gave loop as 10 instead of 0 for easy analysis and also set first and last frame as two.jpg, because we can't predict the end frame during loop shutdown.

Please correct me, if above steps are wrong.

Coming to my issue,
I want to add some additional text or small image to correctly identify the two frames(precaptured and currently failed )images as below

precaptured with 'P' text on left top corner : Image

current failed image with 'E' text on left top corner: Image

How can I add some text or small images for identifying these frames, before creating the GIF ? Please share commands for doing this job. Also share inputs regarding performance of this operation - whether a costly one or not ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Doubt regarding GIF creation from set of images

Post by snibgo »

You could use "-annotate" to place text. For example (Windows syntax):

Code: Select all

%IM%convert ^
  -delay 30 ^
  -loop 10 ^
  ( one.jpg -gravity NorthWest -fill Red -annotate 0 P ) ^
  ( two.jpg -gravity NorthWest -fill Red -annotate 0 E ) ^
  p.gif
Usng jpeg for the screen capture is bad, as it is lossy (it changes pixel values). Use a lossless format, such as png, if you can.
snibgo's IM pages: im.snibgo.com
appu
Posts: 29
Joined: 2013-09-20T10:10:02-07:00
Authentication code: 6789

Re: Doubt regarding GIF creation from set of images

Post by appu »

Thanks Snibgo, it worked !

Regarding JPEG file format, actually I'm snapping the images from a Motion JPEG video and does the comparison. So is there a big difference in pixel values, while saving images as PNG and JPEG from a Motion JPEG snapshot ? Please confirm.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Doubt regarding GIF creation from set of images

Post by snibgo »

So is there a big difference in pixel values, while saving images as PNG and JPEG from a Motion JPEG snapshot ?
It depends on the movie compression. You should try it to find out. The movie compression has (almost certainly) changed pixels, and saving a frame as jpeg probably won't make it much worse.
snibgo's IM pages: im.snibgo.com
appu
Posts: 29
Joined: 2013-09-20T10:10:02-07:00
Authentication code: 6789

Re: Doubt regarding GIF creation from set of images

Post by appu »

Hi All,

One more doubt in the GIF creating scenario.

I've annotated 'expected' and 'actual' images with text using following command

Code: Select all

 convert one.jpg -gravity NorthWest -fill Red -pointsize 20 -annotate 0 Actual one-annotated.jpg

Code: Select all

convert two.jpg -gravity NorthWest -fill Red -pointsize 20 -annotate 0 Expected two-annotated.jpg
Then created the GIF by placing first and last frame as same to get a consistent stop frame during loop stop.

Code: Select all

convert -delay 30 -loop 10 one-annotated.jpg two-annotated.jpg one-annotated.jpg out-with-annotation.gif
Now my issue is about the GIF size. Since there are three frames, I expect that the GIF size is linear to number of frames. But If I have the actual and expected images of size approximately 50KB then the resultant GIF size is almost 500KB. I am expecting around 150KB, since there are three frames specified.

Can some one ensure that this behavior expected OR not in IM 6.8.6-8 ? Also is there any way to minimize the size of the GIF without degrading quality of the resultant GIF?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Doubt regarding GIF creation from set of images

Post by snibgo »

Are you comparing three GIFs with one animated GIF, or three JPGs with one animated GIF?

GIF and JPG compressions will be different, of course.
snibgo's IM pages: im.snibgo.com
appu
Posts: 29
Joined: 2013-09-20T10:10:02-07:00
Authentication code: 6789

Re: Doubt regarding GIF creation from set of images

Post by appu »

Three JPGs against the one animated GIF.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Doubt regarding GIF creation from set of images

Post by snibgo »

Well, that's the issue. You will probably find that the gif with 3 frames is about the same as the total of the 3 separate gifs. It may be smaller with "-layers optimize" (or one of the others, see http://www.imagemagick.org/script/comma ... php#layers) provided enough pixels are constant from one frame to the next.
snibgo's IM pages: im.snibgo.com
Post Reply