Stroep

Just a collection of random works – Mark Knol

Tag Archives: php

ImageSaver ClassMy ImageSaver() Class is ready for download.

Download
ยป ImageSaver v1.0

Features

  • Save a MovieClip, Sprite, Shape, Bitmap, Textfield or other kinds of displayObjects.
  • It doesn’t matter where or how your object is positioned on the stage, it gets the right bounds.
  • Never worry about bytearray’s / encoding anymore.
  • Save your displayobject as JPG or PNG (using Adobe’s encoders)
  • Ready-to-install PHP file.



How to use
1. Copy the ’save-my-image.php’ file to your server or testing environment (I use WAMP for testing)
2. Use ImageSaver like this example.

// Create saver instance + point to php file on server
var imageSaver:ImageSaver = new ImageSaver( "http://localhost:8080/save-my-image.php" );       

// additional: Add eventlisteners.
imageSaver.addEventListener ( Event.COMPLETE, onSaveComplete );
imageSaver.addEventListener ( IOErrorEvent.IO_ERROR, onSaveError );

// Save textfield as JPG with red background
imageSaver.save ( myTextField, "myfilename1.jpg", 0xFFFF0000 );

// Save bitmap as JPG with red background in low JPG quality (15)
imageSaver.save ( myBitmap, "myfilename2.jpg", 0xFFFF0000, 15 );

// Save a shape as transparent PNG
imageSaver.save ( myShape, "myfilename3.png" );

// Save a movieclip as half-transparent (red) PNG
imageSaver.save ( myMovieClip, "myfilename4.png", 0xCCFF0000 );

// handle events
       
private function onSaveError( e:IOErrorEvent ):void {
    trace ( "Image save failed. Error while saving: " + e.text );
}

private function onSaveComplete( e:Event ):void {
    trace ( "Image save completed"  );
}

The save-function works like this:

public function save( displayobject:DisplayObject, filename:String, backgroundColor:Number = 0×00FFFFFF, JPGquality:int = 85 ):void
       

I love to hear your suggestions. Feel free to use it too.

Creative Commons License
Creative Commons Licence

Tagged with , , , , .