Yes it's possible to resize an image in javascript using the HTML5 canvas API. You, however, will need to save it somewhere after being resized.
Depending on what you want to do, you can either:
- Make the user save the smaller image using this client side script.
- Store it yourself using a server-side language, to convert a
Base64 Encoded Image to an actual image file, and save it on your server. Check out Example 1.
Example 1: PHP5 based solution:
<?php
define('UPLOAD_DIR', 'images/');
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';
?>
UPDATE #2:
As stated in the comments below, this method requires a modern browser that supports File APIs to work. Use the flash method instead to support both modern and non-html5 browsers.