showing results for - "compress image javascript"
Kaidence
22 May 2018
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
queries leading to this page
compress js image compress examplescompress js image simplejs image size compresserimage compression javascriptcompress image jscompess image size javascriptimage compress javascript codecompress uploaded image jscompress images javascripthow to compress image size using javascriptjs image compress imageshow to compress img using javascripthow to compress my image in javascriptimage compress javascriptimage compressor in javascriptcompress image upload javascriptcompress images using javascriptcompress image javascriptimage compression with javascriptcompress image size using javascriptcompress js imagecompress image kb in javascriptcompress image javascript functionhow to compress image size in javascriptcompress image size javascriptjs img compresshow to compress image files in javascriptjs compress image to displaycompress image size in javascriptimage compression using javascriptcompress image sizes javascript librarycompress image library jscommece js image how to code image compress in javascriptcompress image using jscompress image size javascript and uploadcompress image using javascriptcompress image with manual store javascripthow to compress size of image javascriptcompress jpg jscompress uploaded image javascriptcompress image with jshow to comprese image using our js functionscompress js image tutorialhow to compress image using javascriptjavascript library compress imagejs compress imgagejs compress imagecompress image for web online javascriptjavascript compress imagehow compress image jshow to compress image in javascriptjavascript compress an imagesimage compression in javascriptjavascript compress and save imagecompress js imagecompress image in jshow to compress image size in jsjavascript compress imaeghow to compress images in javascriptcompress a image link javascriptcompress image javascript librarycompress images in jscompress images jscompress image javascript