【发布时间】:2021-01-31 14:32:06
【问题描述】:
使用 Image Croppie,我编写了一个代码来裁剪和调整图像大小。
我的代码:
$uploadCrop1 = $('#upload-demo1').croppie({
enableExif: true,
viewport: {
width: <?php echo 800*0.20; ?>,
height: <?php echo 600*0.20; ?>,
type: 'rectangle'
},
boundary: {
width: <?php echo (800*0.20)+20; ?>,
height: <?php echo (600*0.20)+20; ?>
}
});
$('#upload1').on('change', function () {
var reader = new FileReader();
reader.onload = function (e) {
$uploadCrop1.croppie('bind', {
url: e.target.result
}).then(function(){
//console.log('jQuery bind complete');
});
}
reader.readAsDataURL(this.files[0]);
});
$('#cropped1').on('click', function (ev) {
$uploadCrop1.croppie('result', {
type: 'canvas',
size: {width: 800,height: 600,type: 'rectangle'}
}).then(function (resp) {
$("#inputtt1").val(resp);
$('#myModal1').modal('toggle');
});
});
问题 1:当我在更大的图像(比如说 4032 X 3024)上应用相同的大小以调整为(800 X 600)的大小时,图像会失真
在将图像保存为最终 jpg 之前,我尝试同时使用:重新采样和调整大小,但静止图像失真:
imagecopyresampled($destination, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagecopyresized($destination, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($destination, $row['base_path'].$imgname,90);
问题 2:当我使用 ImageCropper 裁剪 png 并将其保存为 png 时,我在输出图像中获得了背景颜色。我需要输出图像来保留透明背景。
【问题讨论】:
标签: javascript php jquery image croppie