@@ -87,32 +87,20 @@ export const createNewCanvasEntityFromImage = async (arg: {
87
87
const state = getState ( ) ;
88
88
const { x, y } = selectBboxRect ( state ) ;
89
89
90
- let imageObject : CanvasImageState ;
91
- let resizeWidth : number ;
92
- let resizeHeight : number ;
90
+ const base = selectBboxModelBase ( state ) ;
91
+ const ratio = imageDTO . width / imageDTO . height ;
92
+ const optimalDimension = getOptimalDimension ( base ) ;
93
+ const { width, height } = calculateNewSize ( ratio , optimalDimension ** 2 , base ) ;
93
94
94
- if ( withResize ) {
95
- // Use the same resizing logic as newCanvasFromImage
96
- const base = selectBboxModelBase ( state ) ;
97
- const ratio = imageDTO . width / imageDTO . height ;
98
- const optimalDimension = getOptimalDimension ( base ) ;
99
- const { width, height } = calculateNewSize ( ratio , optimalDimension ** 2 , base ) ;
100
- resizeWidth = width ;
101
- resizeHeight = height ;
102
- } else {
103
- // Use current bbox dimensions
104
- const { width, height } = selectBboxRect ( state ) ;
105
- resizeWidth = width ;
106
- resizeHeight = height ;
107
- }
95
+ let imageObject : CanvasImageState ;
108
96
109
- if ( withResize && ( resizeWidth !== imageDTO . width || resizeHeight !== imageDTO . height ) ) {
97
+ if ( withResize && ( width !== imageDTO . width || height !== imageDTO . height ) ) {
110
98
const resizedImageDTO = await uploadImage ( {
111
99
file : await imageDTOToFile ( imageDTO ) ,
112
100
image_category : 'general' ,
113
101
is_intermediate : true ,
114
102
silent : true ,
115
- resize_to : { width : resizeWidth , height : resizeHeight } ,
103
+ resize_to : { width, height } ,
116
104
} ) ;
117
105
imageObject = imageDTOToImageObject ( resizedImageDTO ) ;
118
106
} else {
0 commit comments