Output Image is always PNG , croppie not keeping original Format
See original GitHub issueHello ,
Im trying to integrate Croppie inside a simple WebApp ( HTML/php + js / css) and here is how is my code looks like :
`document.addEventListener(‘DOMContentLoaded’, function() { var extension = “1212121”; $image_crop = $(‘#image_demo’).croppie({ enableExif: true, viewport: { width: 1180, height: 600, type: ‘rectangle’ //circle }, boundary: { width: 1280, height: 800 }, }); $(‘.house_img’).each(function() { var id = $(this).attr(“id”);
$('#' + id + '').on('change click', function() {
extension = $(this).val().split('.').pop();
var reader = new FileReader();
reader.onload = function(event) {
$image_crop.croppie('bind', {
url: event.target.result,
}).then(function() {
console.log(extension);
});
}
reader.readAsDataURL(this.files[0]);
$('#uploadimageModal').modal('show');
});
})
$('.crop_image').click(function() {
var GetCropper = $(".crop_image")[0]['attributes']['data-selected'].nodeValue;
$image_crop.croppie('result',{
type: 'canvas',
size: 'original',
format : 'jpg',
quality: 0.5,
}).then(function(response){
$.ajax({
url:"./queries/upload.php",
type: "POST",
dataType: 'json',
data:{"image": response},
success:function(data)
{
$('#uploadimageModal').modal('hide');
image_placing = $('#uploaded_image').find('img');
image_placing.each(function(){
if($(this).attr('data-reading') == GetCropper )
{
$(this).attr('src','../images/uploads/'+encodeURI("%")+'temp'+encodeURI("%")+'/'+data['image']+'');
$(this).next().val(data['image'].split('.').slice(0, -1).join('.').concat('.'+data['filetype']));
}
})
}
});
})
$('#uploadimageModal').modal('show');
})
});`
The problem is that the croppie is converting my Image Always into PNG even if i choose JPEG it dosen’t work at all , and not reducing the quality is there something wrong on my Code ? thank you
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Output Image is always PNG , croppie not keeping original ...
I use croppie library I want to get the original image extension, but I got or jpeg or png. vanilla.result({ type: 'base64', ...
Read more >ngx-image-cropper - npm Package Health Analysis - Snyk
Inputs ; cropperMinWidth, number, 0 (disabled), The cropper cannot be made smaller than this number of pixels in width (relative to original image's...
Read more >Taking still photos with getUserMedia() - Web APIs | MDN
Once the canvas contains the captured image, we convert it to PNG format by calling HTMLCanvasElement.toDataURL() on it; finally, we call photo.
Read more >Resizing and Cropping Images with Canvas - Codrops
The CSS is also very minimal. First, define the styles for the resize-container and the image. .resize-container { position: relative; display ...
Read more >Croppie - element plugin to crop and zoom ... - Bubble Forum
I also tried to use the conditional formatting on a croppie element to change the dimensions based on a button click and then...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry, wrong place declared… solved
If you want to keep the image format then you should just add extra logic to check what is the extension of the file that user picked, and then tweak the value of croppie’s result format based on that. Keep in mind that croppie can only output jpeg, png, and webp format though, at the time of my writing. (so it’s not possible to let GIF stay GIF).