Animated GIF Plugin for Cropper + some .NET Animated GIF code

WHAT'S ALL THIS, THEN?

Cropper is a great free screen capture program. It has a cool plugin system which lets you send the screenshots anywhere you can write code to send it. I wrote a plugin to save a portion of the screen to an Animated GIF.

I originally wrote it for use in a weblog post, but got so caught up in the ins and outs of image processing that I never posted the article that got this all started or the plugin I'd written. I just realized last week when I was using the plugin that I still needed to publish it, so here it is.

BUT, WHY?

There are some inexpensive screen recorders that save to animated GIF, but I really like working with Cropper and figured an Animated GIF plugin just made sense. I was just talking with a friend who recently started a technical blog (a very good one, I might add), and we both agreed that the way Cropper simplifies the "screenshot / open in editor / crop / convert format / upload" cycle is huge. Screenshots really enhance the readability of a blog1, and keeping the friction as low as possible helps make sure you'll do it. I like the simplicity of using one tool for all my screenshots.

CREDITS AND TECH STUFF

I made use of some code from a CodeProject article, NGif. This code was a direct Java to .NET port of Kevin Weiner's AnimatedGifEncoder, which in turn was based on a bunch of public domain code dating back as far as 1994. The GIF Quantization uses NeuQuant, an interesting Neural Network quantizer. NeuQuant is a little slower than the Octree quantization that's so hot these days, but NeuQuant generally produces better quality images for the same file size. Don't your animated GIF images deserve the neural network treatment?

My plugin code is published under public domain license. Based on my research on the origin of the code above, I believe all the NGif code is public domain as well. I did some significant refactoring to the NGif code; the CodeProject version was a direct port from Java and didn't leverage .NET Framework classes like System.Drawing. Bottom line - after a good amount of research, I believe that all this code is under public domain license.

I wrote about all this license silliness previously.

I'm pretty happy with the way the plugin turned out. My first pass at it was pretty simple - take a picture every tenth of a second and add it to the animated GIF. I added an optimization which cut the file size way down, but took a bit more work - I compare each picture with the previous image and only added to the GIF if the image has changed. Since the Animated GIF format requires you to include the time duration of each image as it is added, I end up having to keep the image until the next one is added or capturing is stopped so I can calculate the duration that goes with the image.

I referenced this CodeProject article for comparing two images by using an MD5 hash, although my code just grabs a string hash and stores it rather than comparing two images directly.

Here's the main brains of the code:

 

private void HandleImage(Image image)
{
string currentHash = GetHashFromImage(image);
DateTime timeStamp
= DateTime.Now;

//Check if image has changed from previous
if(currentHash != _previousHash)
{
if(_previousTimestamp != DateTime.MinValue)
{
//This is not the first image being added
AddImageToAnimation(timeStamp);
}
StoreImage(image, currentHash, timeStamp);
}
}

private void StoreImage(Image image, string imageHash, DateTime timeStamp)
{
_previousImage
= (Image)image.Clone();
_previousHash
= imageHash;
_previousTimestamp
= timeStamp;
}

private void AddImageToAnimation(DateTime timeStamp)
{
TimeSpan timeSpan
= timeStamp.Subtract(_previousTimestamp);
_AnimatedGifEncoder.SetDelay(timeSpan.Milliseconds);
this._AnimatedGifEncoder.AddFrame(_previousImage);
_previousImage
= null;
}

DOWNLOAD

You can download the code and source for this plugin from http://www.codeplex.com/cropperplugins. (note: updated)

INSTALLATION

To install, copy all files to your Croppper\Plugins directory.

OTHER RANDOM TIPS

  • You can edit your animated GIF's with Microsoft GIF Animator.
  • It can be a little tricky to start recording, as a commenter noted. I use Cropper in "Always on top" mode and use the "S" key while Cropper is focused to start recording. "S" again stops recording.
  • You can host animated GIF's on Flickr, but only the original size will show the animation. You can find that by clicking on the All Sizes button when you're viewing the picture, then pick the largest size (which should be the default).
  • I highly recommend the Flickr Output Plugin for Cropper.
  • You can combine TimeSnapper's history browser and Cropper Animated GIF captures for some fun results.

1I'll readily agree that the animated GIF overload on this one particular post makes it much tougher to read. Please use your powers for good. I think this is a special case - I can't really blog about animated GIF's without including a few, can I?

Published Tuesday, November 07, 2006 11:40 PM by Jon Galloway
Filed under: , , ,

Comments

# Brian Scott : Cropper in C#

Wednesday, November 08, 2006 3:22 AM by Brian Scott : Cropper in C#

# Animated Gif Plug-in for Cropper

John Galloway has created a nice animated gif plug-in for Cropper. It has some nice optimizations like...

Wednesday, November 08, 2006 3:32 AM by Brian Scott

# re: Animated GIF Plugin for Cropper + some .NET Animated GIF code

It took me a few tries to know how to record a screen.  The lesson is: Don't enable "Always on Top" when recording to animated gif (otherwise double click won't work).  Bring the Cropper form behind the screen or window you are recording and only make the upper-left corner leafs visible. Then you can double-click these leafs to start and stop recording.

Wednesday, November 08, 2006 3:36 AM by Samboy LIms

# Animated GIF Plugin for Cropper + some .NET Animated GIF code

Jon Galloway ismét egy érdekes, kíválóan megoldott dologra hívta fel figyelmem. E cikkben és hivatkozásaiban

Wednesday, November 08, 2006 4:41 AM by Kurbli

# re: Animated GIF Plugin for Cropper + some .NET Animated GIF code

I finally had a chance to try your plugin out.  It's very cool.  I'd like to echo the comments about recording being a little tricky though.  You may want to add a few tips to the readme.txt included with the download. Better yet, maybe you could record a quick demo using the plugin.  ;)

Friday, November 10, 2006 2:01 AM by Ben Griswold

# Screencasting for Windows

Here's a compendium of all the screencasting tools I could find, but it's far from comprehensive: ...

Friday, November 10, 2006 3:04 PM by Christopher Clark's AvaBlog

# Bummer

Doesn't work for me. Keeps crashing. Tried with Cropper 1.8.0 and 1.9.1. :(

Cool idea though.

Thursday, February 01, 2007 3:53 AM by Steve Monroe

# Some Issues

Fabulous utility. Hot key to start/stop capture would be great.

Cropper crashes with Alt-Print Screen when Animated GIF is the output (I have dual screens in case that is an issue but the problem occurs on both).

Animated GIF sets the wrong filename so when Browse option is selected it looks for...[5].Gif instead of ...[2].Gif (where ...[5].Bmp would be the next file if it was still outputting Bmp files).

Monday, February 05, 2007 1:25 PM by GregT

# re: Animated GIF Plugin for Cropper + some .NET Animated GIF code

Hi,

Did you manage to reduce the file size that the encoder produces? Its seems quite large to me, almost double when using the ngif encoding opposed to a proper animated gif application.

Wednesday, September 26, 2007 7:35 AM by tom

# re: Animated GIF Plugin for Cropper + some .NET Animated GIF code

putang ina nyo....

Monday, December 03, 2007 2:38 AM by raobert

# re: Animated GIF Plugin for Cropper + some .NET Animated GIF code

Password protection wont let us download this plugin :(

Sunday, October 12, 2008 5:48 PM by simon

Leave a Comment

(required) 
(required) 
(optional)
(required)