Last active
September 9, 2016 20:07
-
-
Save Gabri3l/4f6650ce21f67793013fd4644869bac6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var imageQuality = 0.7; | |
var scale = 0.35; | |
$container = $('#resize' + id + 'Container'); | |
var crop_canvas, | |
left = $('#pic' + id + 'Overlay').offset().left - $container.offset().left, | |
top = $('#pic' + id + 'Overlay').offset().top - $container.offset().top, | |
width = $('#pic' + id + 'Overlay').width(), | |
height = $('#pic' + id + 'Overlay').height(); | |
crop_canvas = document.createElement('canvas'); | |
crop_canvas.width = width; | |
crop_canvas.height = height; | |
// Rescale left and top corner | |
left = (left/scale); | |
top = (top/scale); | |
crop_canvas | |
.getContext('2d') | |
.drawImage( | |
$('#pic' + id + "Preview").get(0), | |
left, top, width, height, 0, 0, width, height | |
); | |
// Converts image from URI to file for upload | |
function dataURItoBlob(dataURI) { | |
var binary = atob(dataURI.split(',')[1]); | |
var array = []; | |
for(var i = 0; i < binary.length; i++) { | |
array.push(binary.charCodeAt(i)); | |
} | |
return new Blob([new Uint8Array(array)], {type: 'image/jpeg'}); | |
} | |
var imgL = crop_canvas.toDataURL("image/jpeg", imageQuality), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment