How do I resize an image on the client size before upload?
I'm trying to resize images before they upload to save bandwidth. I'm basing this process off of the "photo_album" sample, using the jQuery-file-upload.js The example has the upload options outside of the .fileupload initialization, but I understand that it's already wrapped in the file-upload widget. However, these options don't seem to be applying. The images are resized on the server side, but I'd actually like to do both. Here's the coffeescript for the page: (indentation lost through pasting)
Uncomment the following lines to enable client side image resizing and valiation.
Make sure cloudinary/processing is included the js file
disableImageResize: false,
imageMaxWidth: 1920,
imageMaxHeight: 1080,
acceptFileTypes: /(.|\/)(gif|jpe?g|png|bmp|ico)$/i,
maxFileSize: 20000000
view_upload_details = (upload) ->
Build an html table out of the upload object
rows = []
$.each upload, (k, v) ->
rows.push $("<tr>").append($("<td>").text(k)).append($("<td>").text(JSON.stringify(v)))
return
$("#info").html $("<div class=\"upload\_details\">").append("<h2>Upload metadata:</h2>").append($("<table>").append(rows))
return
$(document).ready ->
$(".cloudinary-fileupload").fileupload(
dropZone: "#direct_upload"
start: (e) ->
$(".status").text "Starting upload..."
return
progress: (e, data) ->
$(".status").text "Uploading... " + Math.round((data.loaded * 100.0) / data.total) + "%"
return
fail: (e, data) ->
$(".status").text "Upload failed"
return
).off("cloudinarydone").on "cloudinarydone", (e, data) ->
$("#photo_bytes").val data.result.bytes
$(".status").text ""
preview = $(".preview").html("")
$.cloudinary.image(data.result.public_id,
format: data.result.format
width: 192
height: 108
crop: "fit"
).appendTo preview
$("<a/>").addClass("delete_by_token").attr(href: "#").data(delete_token: data.result.delete_token).html("×").appendTo(preview).click (e) ->
e.preventDefault()
$.cloudinary.delete_by_token($(this).data("delete_token")).done(->
$(".preview").html ""
$("#info").html ""
$("#photo_bytes").val ""
$("input[name=\"storefront[index_image]\"]").remove()
return
).fail ->
$(".status").text "Cannot delete image"
return
return
view_upload_details data.result
return
return
-
Please make sure you've included the additional libraries which are required for the pre-processing. For more information:
https://github.com/cloudinary/cloudinary_js#client-side-image-resizing-before-upload0
Post is closed for comments.
Comments
1 comment