Javascript – Is it possible to optimize/shrink images before uploading

compressionimagejavascriptupload

I am working on a web application that will deal with many image uploads. Its quite likely that the users will be in areas with slow internet connections and I'm hoping to save them upload time by compressing the images before uploading.

I have seen that Aurigma Image Uploader achieves this using a java applet or active x but it's expensive and I'd rather something open source or at least a little cheaper. Ideally I'd like to roll my own if its at all possible.

I'm developing on Ruby on Rails if that makes any difference..

Thanks!

Edit just to clarify: I don't mind if the solution uses activeX or an applet (although js is ideal) – I'm just looking for something a little cheaper than Aurigma at this stage of development.

Also, it may not be feasible for users to shrink the image themselves as in many instances they will uploading directly from an internet cafe or other public internet spot.

Best Answer

Generally, it isn't possible to write an image compressor in JavaScript. Sorry.

You'll need to use a plugin of some sort, and as you mention, other sites use Java.

It appears to be possible to write something to encode a JPEG in ActionScript (i.e. Flash), which will reach a much larger audience than the Java plugin you mention. Here's a link to a blog post talking about PNG & JPEG encoders in ActionScript.

Here's another blog post with a demo of an inlined JPEG encoder in ActionScript.