question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Output Image is always PNG , croppie not keeping original Format

See original GitHub issue

Hello ,

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:open
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
frestalinkcommented, Mar 25, 2020

Sorry, wrong place declared… solved

$('.upload-site-result').on('click', function (ev) {
	$uploadCrop.croppie('result', {
		type: 'canvas',
		size: 'viewport',
		format: 'jpeg',
		quality: 0.9,
	}).then(function (img) {
...
0reactions
Daniel-Congcommented, Aug 27, 2020

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found