Skip to content

Instantly share code, notes, and snippets.

@caseypugh
Created September 23, 2011 18:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caseypugh/1238101 to your computer and use it in GitHub Desktop.
Save caseypugh/1238101 to your computer and use it in GitHub Desktop.
GIFPlayer - How to resize an animated GIF
// See http://www.bytearray.org/?p=95
// Insert into GIFPlayer.as
import flash.geom.Rectangle;
public function resize(w:Number, h:Number):void
{
for (var i = 0; i < aFrames.length; i++) {
aFrames[i].resize(w, h);
}
}
// Insert into GIFFrame.as
import flash.geom.Matrix;
public function resize(w:Number, h:Number):void
{
if (!bitmapData_orig) {
bitmapData_orig = bitmapData.clone();
}
var m:Matrix = new Matrix();
m.scale(w / bitmapData_orig.rect.width, h / bitmapData_orig.rect.height);
var bmd:BitmapData = new BitmapData(w, h, true, 0x000000);
bmd.draw(bitmapData_orig, m, null, null, null, true);
bitmapData = bmd;
}
// Example usage
var myGIFPlayer:GIFPlayer = new GIFPlayer();
addChild ( myGIFPlayer );
myGIFPlayer.load ( new URLRequest ("animation.gif") );
myGIFPlayer.addEventListener ( GIFPlayerEvent.COMPLETE, function() {
myGIFPlayer.resize(400, 300);
});
@userOmar
Copy link

userOmar commented Mar 2, 2013

Hi Caseypugh
Many thanks for this script to resize
I use this script but some frames of gif animation are breaking

Can you tell what wrong in this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment