Foliotek / Croppie

A Javascript Image Cropper
http://foliotek.github.io/Croppie
MIT License
2.57k stars 884 forks source link

What if my cropped image needs to be larger than the viewport and container? #757

Closed xblabs closed 3 years ago

xblabs commented 3 years ago

What I need :

Currently the cropped image assumes the width / height of the viewport which is way smaller than I need it to be.

I tried to use CSS scale transforms on the container but that messes up everything.

Any further ideas?

bret-miller commented 3 years ago

Something like this:

$('#image-crop-container img').croppie('result',{type:'base64',size:{width:imgsize[0],height:imgsize[1]},format:'png'}).then(function(r) { gciSaveImage(r); ; });

If you specify the image size when you get the result, you should be able to get the size of the image you need. regardless of the size of the viewport.

xblabs commented 3 years ago

Thanks Bret! That does not work unfortunately. the size object scales viewport render result up which is of no use.

Example : the view port is set to 300x400px , the input image comes as 1920 x 1600 I want a crop output of 1200x1600

$uploadCrop.croppie('result', { type: 'canvas', size: {width:1200, height:1600} }).then( (resp) => { this.$uploadPreviewImage.attr( "src", resp ); })

Takes the 300x400 and upscales it to 1200x1600, losing all image information. It's all a pixelated mush,

xblabs commented 3 years ago

Sneaky problem. The crop container was inside a nested structure where an outer css rule said something like .outer img { max-size: 360px; } which messed up all the subsequent cropping calculations. So IMPORTANT for anyone reading this : please make sure that the crop container does NOT inherit any css restricting the size of an image.

lbshopping commented 6 months ago

{type:'base64',size:{width:imgsize[0],height:imgsize[1]},format:'png'}

Thanks! Works well 😍