1//========= Step 1 - Client Side Compression ===========
2
3//Images Objects
4var source_img = document.getElementById("source_img"),
5 target_img = document.getElementById("target_img");
6
7//(NOTE: see the examples/js/demo.js file to understand how this object could be a local image
8//from your filesystem using the File API)
9
10//An Integer from 0 to 100
11var quality = 80,
12// output file format (jpg || png || webp)
13output_format = 'jpg',
14//This function returns an Image Object
15target_img.src = jic.compress(source_img,quality,output_format).src;
16
17
18//======= Step 2 - Upload compressed image to server =========
19
20//Here we set the params like endpoint, var name (server side) and filename
21var server_endpoint = 'upload.php',
22 server_var_name = 'file',
23 filename = "new.jpg";
24
25//This is the callback that will be triggered once the upload is completed
26var callback = function(response){ console.log(response); }
27
28//Here goes the magic
29jic.upload(target_img, server_endpoint, server_var_name, filename, callback);
30
31//======= Optional parameters example: errorCallback, duringCallback and customHeaders =======
32// This function gets called on an error response of the server - status code of >= 400.
33var errorCallback = function () {
34 // Handle upload failure
35};
36
37// This function gets called while the file is uploading. Returns the percent completeness of the image being uploaded
38var duringCallback = function (progressPercent) {
39 //progressPercent can be used to show a progress bar
40};
41
42// Custom Request Headers, nifty for things like Basic Authorization
43
44var customHeaders = { 'Authorization': 'Basic someBase64EncodedHash=====' };
45
46jic.upload(target_img, server_endpoint, server_var_name, filename, successCallback, errorCallback, duringCallback, customHeaders);
47