【发布时间】:2015-06-13 08:05:27
【问题描述】:
我正在使用这个裁剪工具https://github.com/fengyuanchen/cropper/。我有这个问题,如果我动态添加图像,图像周围会有一些透明背景。因此图像不适合容器,并且还可以在图像周围进行裁剪。我按照文档上的示例尝试摆脱透明背景,但没有成功。
这是我的代码:
<div id="imgWrap" style="max-height:400px;min-height:400px">
<img id="img" src="" /> // Image gets added dynamically
</div>
javascript
var reader = new FileReader();
reader.onloadend = function () {
var img = $('#imgWrap img');
img.attr('src', reader.result);
img.cropper({
aspectRatio: 1 / 1,
autoCropArea: 0.65,
guides: false,
strict: true,
highlight: false,
responsive:true,
dragCrop: false,
movable: true,
resizable: true,
zoomable: true,
touchDragZoom:true,
rotatable: false,
minCropBoxWidth:105,
minCropBoxHeight:105,
built: function () {
// cropper-container is the element where the image is placed
$('.cropper-container').cropper('setCanvasData', {
left: 0,
top: 0,
width: 700,
height: 700
}
);
},
})
我试过这个:https://github.com/fengyuanchen/cropper#setcanvasdatadata 但没有任何反应
您可以在此处查看示例:
图片的自然尺寸为 1920x1200
这是添加图片后生成的:
那么,有没有人建议如何摆脱透明背景并使图像适合容器?
【问题讨论】:
标签: javascript jquery css image crop