diff --git a/src/tiny-image-editor/src/components/init.tsx b/src/tiny-image-editor/src/components/init.tsx index d4eb5bba374f0db7a2e9a18087f81e4a85d4fc83..47d7942e3402410bc31e33f0872ee7bdfaf19b45 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;