Skip to content

Commit

Permalink
fix: 图片裁剪兼容本地图片不存在src的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
x007xyz committed Nov 13, 2024
1 parent 08b0bfa commit 69a9400
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/components/cropperImg.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@ const cropper = () => {
const activeObject = canvasEditor.canvas.getActiveObjects()[0];
if (activeObject && activeObject.type === 'image') {
console.log('🚀 ~ cropper ~ activeObject:', activeObject);
cropperDialogRef.value.open({ img: activeObject.src }, async (data) => {
console.log('🚀 ~ cropper ~ data:', data);
const imgEl = await insertImgFile(data);
const width = activeObject.get('width');
const height = activeObject.get('height');
const scaleX = activeObject.get('scaleX');
const scaleY = activeObject.get('scaleY');
activeObject.setSrc(imgEl.src, () => {
activeObject.set('scaleX', (width * scaleX) / imgEl.width);
activeObject.set('scaleY', (height * scaleY) / imgEl.height);
canvasEditor.canvas.renderAll();
});
imgEl.remove();
});
cropperDialogRef.value.open(
{ img: activeObject.src || activeObject._element.src },
async (data) => {
console.log('🚀 ~ cropper ~ data:', data);
const imgEl = await insertImgFile(data);
const width = activeObject.get('width');
const height = activeObject.get('height');
const scaleX = activeObject.get('scaleX');
const scaleY = activeObject.get('scaleY');
activeObject.setSrc(imgEl.src, () => {
activeObject.set('scaleX', (width * scaleX) / imgEl.width);
activeObject.set('scaleY', (height * scaleY) / imgEl.height);
canvasEditor.canvas.renderAll();
});
imgEl.remove();
}
);
}
};
Expand Down

0 comments on commit 69a9400

Please sign in to comment.