Actionscript 3 watermark image class

A recent project needed a watermark added to any images that could be downloaded off the site. Originally we used a PHP solution, which worked fine. But I wanted to do it inside of Flash and use the save methods in FP10.

So, I wrote this simple little class to adding a water mark to a display object, and the returning that display object as bitmapdata for say, passing to Adobe’s jpg encoder.

Maybe someone will have some use for it?

Source Files
Here is the relevant source file; Watermark class (601)

By downloading, you agree to the terms of use, outlined here: http://www.blog.noponies.com/terms-and-conditions

Dependencies
Zero

5 Neighs about “Actionscript 3 watermark image class”



UnImpressed Neighed:

Well, I’m not very impressed by this code….

It’s generally pretty sloppy, and requires that the Flex framework be included.

Specifically:
- Your alignment values should be constants since you’re not doing any case checking… Also in case someone fat fingers it, granted it only being two characters.
- Your test for setting the alignment value is just all kinds of nasty. All your cases are identical, and could have eliminated all the break statements except the last, and had the conditions one after another. Even better/faster, would be to do an IF statement… And probably even easier to read would be to push all the constants into an array and check the indexOf value.
- Since you expect a DisplayObject to be used as the watermark image, it’s required to have all the overhead of a complex component just to get the bitmap drawable data and replicate it via the .draw method of the BMPData object, which is redundant copying of data. It would be best to supply the url, load the image, and utilize the watermark in a static method to be reused over and over.

I’ve never considered a watermark IN flash, so that does at least open my eyes to new ideas. Kudos on that!

Dale Neighed:

Umm,

It does not require the flex framework at all.

There are the imports:
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.DisplayObject;
That’s all standard AS3, flash packages.

A case statement tests on === or strict equality, so yeah, it’s testing for the case of the parameters passed in. None of the cases are identical.

What are you talking about, a displayObject is about as basic as it goes. I could check that the objects passed in implement the IBitmapDrawable interface.

You miss the point of the class, its for creating watermarked images of content you have already got in flash, and does not require it to be an image at all.

I doubt you even read the class…

j Neighed:

don’t listen to this guy… good work man.

Jackie Juan Neighed:

Haha Whats wrong with some ppl?
Why flame a guy whos putting time and effort to help?

Leave a neigh?