Deseamos regalarte la mejor solución que encontramos online. Nosotros esperamos que te resulte de ayuda y si quieres aportar algo que nos pueda ayudar a perfeccionar nuestra información siéntete libre de hacerlo..
Ejemplo: comprimir imagen javascript
//========= Step 1 - Client Side Compression ===========//Images Objectsvar source_img =document.getElementById("source_img"),
target_img =document.getElementById("target_img");//(NOTE: see the examples/js/demo.js file to understand how this object could be a local image //from your filesystem using the File API)//An Integer from 0 to 100var quality =80,// output file format (jpg || png || webp)
output_format ='jpg',//This function returns an Image Object
target_img.src= jic.compress(source_img,quality,output_format).src;//======= Step 2 - Upload compressed image to server =========//Here we set the params like endpoint, var name (server side) and filenamevar server_endpoint ='upload.php',
server_var_name ='file',
filename ="new.jpg";//This is the callback that will be triggered once the upload is completedvarcallback=function(response)console.log(response);//Here goes the magic
jic.upload(target_img, server_endpoint, server_var_name, filename, callback);//======= Optional parameters example: errorCallback, duringCallback and customHeaders ======= // This function gets called on an error response of the server - status code of >= 400.varerrorCallback=function()// Handle upload failure;// This function gets called while the file is uploading. Returns the percent completeness of the image being uploadedvarduringCallback=function(progressPercent)//progressPercent can be used to show a progress bar;// Custom Request Headers, nifty for things like Basic Authorizationvar customHeaders ='Authorization':'Basic someBase64EncodedHash=====';
jic.upload(target_img, server_endpoint, server_var_name, filename, successCallback, errorCallback, duringCallback, customHeaders);
Calificaciones y reseñas
Recuerda que te damos el privilegio explicar si te ayudó.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)