Skip to content

Image Wrapper

Davit Barbakadze edited this page May 6, 2013 · 4 revisions

Plupload has an interesting feature - it can decrease the size of uploaded images, by dropping their resolution and quality, and optionally stripping off the 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).

Table of Contents

## Methods ### load()

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.

### downsize()

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).

### getAsDataURL(), getAsBinaryString(), getAsBlob()
Clone this wiki locally