From 065e57608a9f72ad6c035ca2b5afe612accb9624 Mon Sep 17 00:00:00 2001 From: qq_41923622 Date: Thu, 6 Feb 2025 17:43:00 +0800 Subject: [PATCH] Thu Feb 6 17:43:00 CST 2025 inscode --- src/tiny-image-editor/src/components/init.tsx | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/tiny-image-editor/src/components/init.tsx b/src/tiny-image-editor/src/components/init.tsx index d4eb5bb..47d7942 100644 --- a/src/tiny-image-editor/src/components/init.tsx +++ b/src/tiny-image-editor/src/components/init.tsx @@ -130,23 +130,33 @@ export const useInit = ({ url }: IProps) => { imageUrl: string = '', justBackground: boolean = false, callback?: () => void, + annotationsData?: any, ) => { const canvas = canvasInstanceRef.current; if (imageUrl.trim() && canvas && wrapperInstanceRef.current) { const { height } = wrapperInstanceRef.current.getBoundingClientRect(); + imageInstanceRef.current = fabric.Image.fromURL( imageUrl, (oImg: any) => { - const center = canvas.getCenter(); - const imgHeight = oImg.height; - /** 图片过大,使其大小正好跟容器一致 */ - oImg.scale(height / imgHeight); - /** 使得图片在canvas中间 */ - oImg.set({ - left: center.left - (oImg.width * (height / imgHeight)) / 2, - top: center.top - (oImg.height * (height / imgHeight)) / 2, - }); + const center = canvas.getCenter(); + const imgHeight = oImg.height; + /** 图片过大,使其大小正好跟容器一致 */ + oImg.scale(height / imgHeight); + if(annotationsData){ + + + }else{ + /** 使得图片在canvas中间 */ + oImg.set({ + left: center.left - (oImg.width * (height / imgHeight)) / 2, + top: center.top - (oImg.height * (height / imgHeight)) / 2, + }); + } + + + /** 不让直接操作图片 */ oImg.selectable = false; oImg.id = WORK_SPACE_ID; -- GitLab