3
I have this screen, image resizing:
when I click download, this screen appears to save the file, but as you can see, the file appears without the extension, how can I make the file appear with the extension automatically when saving?
I have the following code that downloads:
js:
$('.js-crop').on('click', download);
download = function(){
//Find the part of the image that is inside the crop box
var canvas,
left = $('.resize-image').offset().left - $container.offset().left,
top = $('.resize-image').offset().top - $container.offset().top,
width = $('.resize-image').width(),
height = $('.resize-image').height();
canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
canvas.getContext('2d').drawImage(image_target, left, top, width, height, 0, 0, width, height);
//var src = $('.resize-image').attr('src');
//alert(src);
//canvas.toDataURL("image/png;base64");
var ImageData = canvas.toDataURL("image/png;base64");
ImageData = ImageData.replace("image/png", "image/octet-stream");
document.location.href = ImageData;
}
html:
<div class="content">
<div class="component">
<img class="resize-image" src="img/image.jpg" alt="image for resizing">
<button class="btn-crop js-crop">Download<img class="icon-crop" src="img/crop.svg"></button>
</div>
</div><!-- /content -->
Is there any way to do that? can be with php tbm if necessary. on that link is my full code so far: https://www.dropbox.com/s/5ptiq8h5y4r4akc/ImageResizeCropCanvas.zip?dl=0
@guiilherme has to do some thing in html besides javascript? because here so did not work, nor is called the download function...
– alexandre9865
nothing appears, so said (think) that is not called the download function.
– alexandre9865
It’s only in my machine... which site I can use to host this?
– alexandre9865
https://www.dropbox.com/s/5ptiq8h5y4r4akc/ImageResizeCropCanvas.zip?dl=0 this is the link tbm...
– alexandre9865
I have not used the pq codepen are some levels of folders and files, n of the very right using it here...
– alexandre9865
@Alexandremartinsmontebelo corrected the code.
– Guilherme Nascimento