-
Notifications
You must be signed in to change notification settings - Fork 135
Image Wrapper
Plupload has an interesting feature - it can decrease the size of uploaded images, by dropping their resolution and quality, and optionally stripping off meta headers. It saves the bandwidth this way, quite noticeably. Since mOxie historically comes from Plupload and in fact represents the core for Plupload 2 we've extracted the whole image manipulation logic from Plupload and encapsulated it into a standalone image wrapper (in the text below referred as Image).
Our image wrapper can load image from various sources, be it dataUrl, binary string, native blob or file, moxie wrapper for blob or file, another instance of image wrapper, img
node or even url (for full reference check API entry for Image class).
Loading process is asynchronous. On successful completion it will fire load
event, or error
in case of failure.
Former resize().
Probably the most interesting method of the class. It can be used to drop the size of the image, either by decreasing it's quality, resolution or by stripping meta headers. It is usually a very handy thing to do, especially when used in conjunction with upload operation.
Downsize is asynchronous. On completion it fires resize
event.
Method accepts four arguments: width
, height
, crop
, preserveHeaders
, all of which are optional - width
and height
default to original dimensions, crop
deafults to false and preserveHeaders
to true. Purpose of these is probably obvious, but one feature is still worth mentioning - image can be dropped in size without decreasing it's resolution. This can be achieved by invoking downsize
without arguments (or with the last arguments set to false - for even more dramatic effect) and by requesting the resulting image with noticeably less quality (see getAsDataURL, getAsBinaryString, getAsBlob).