@@ -9,6 +9,10 @@ const addToCircleBtn = document.getElementById('addToCircleBtn');
99const addToHexadecagonBtn = document . getElementById ( 'addToHexadecagonBtn' ) ;
1010const addToFlowerBtn = document . getElementById ( 'addToFlowerBtn' ) ;
1111const addToSquareBtn = document . getElementById ( 'addToSquareBtn' ) ;
12+ const addToRectBtn = document . getElementById ( 'addToRectBtn' ) ;
13+ const rectHeightControl = document . getElementById ( 'rectHeightControl' ) ;
14+ const rectHeight = document . getElementById ( 'rectHeight' ) ;
15+ const rectHeightValue = document . getElementById ( 'rectHeightValue' ) ;
1216
1317const teluguText = document . getElementById ( 'teluguText' ) ;
1418const imageSize = document . getElementById ( 'imageSize' ) ;
@@ -106,19 +110,50 @@ addToCircleBtn.addEventListener('click', () => setShape('circle'));
106110addToHexadecagonBtn . addEventListener ( 'click' , ( ) => setShape ( 'hexadecagon' ) ) ;
107111addToFlowerBtn . addEventListener ( 'click' , ( ) => setShape ( 'flower' ) ) ;
108112addToSquareBtn . addEventListener ( 'click' , ( ) => setShape ( 'square' ) ) ;
113+ // Add Rectangle Handler
114+ addToRectBtn . addEventListener ( 'click' , ( ) => setShape ( 'rectangle' ) ) ;
115+
116+ // Add Slider Handler
117+ rectHeight . addEventListener ( 'input' , ( e ) => {
118+ rectHeightValue . textContent = e . target . value + 'px' ;
119+ updatePreview ( ) ;
120+ } ) ;
109121
110122function setShape ( shape ) {
111- if ( ! currentImageSrc ) return ;
112-
113123 currentShape = shape ;
114- resetImageAdjustment ( ) ;
115124
116- // Show controls
117- imageAdjustControl . style . display = 'block' ;
118- borderColorControl . style . display = 'block' ;
119- positionControl . style . display = 'block' ;
125+ // 1. Show standard controls
126+ // Note: If you have a variable for imageAdjustControl, make sure it matches.
127+ // If your code uses 'imageAdjustControl', keep it.
128+ // If your previous code used specific IDs, ensure they match.
129+ // Based on your previous uploads, this is the standard set:
130+ if ( document . getElementById ( 'imageAdjustControl' ) ) document . getElementById ( 'imageAdjustControl' ) . style . display = 'block' ;
131+ if ( document . getElementById ( 'borderColorControl' ) ) document . getElementById ( 'borderColorControl' ) . style . display = 'flex' ;
132+ if ( document . getElementById ( 'positionControl' ) ) document . getElementById ( 'positionControl' ) . style . display = 'block' ;
133+
134+ // 2. Show height slider ONLY for rectangle
135+ if ( shape === 'rectangle' ) {
136+ rectHeightControl . style . display = 'block' ;
137+ } else {
138+ rectHeightControl . style . display = 'none' ;
139+ }
140+
141+ // 3. Reset position variables
142+ // (We use global variables typically found in your script)
143+ if ( typeof imageX !== 'undefined' ) imageX = 0 ;
144+ if ( typeof imageY !== 'undefined' ) imageY = 0 ;
145+ if ( typeof imageScale !== 'undefined' ) imageScale = 1 ;
146+
147+ // 4. Reset zoom slider if it exists
148+ const zoomSlider = document . getElementById ( 'imageZoom' ) ;
149+ if ( zoomSlider ) zoomSlider . value = 1 ;
120150
151+ // 5. Update the drawing
121152 updatePreview ( ) ;
153+
154+ // 6. Scroll to result
155+ const resultContainer = document . getElementById ( 'resultContainer' ) ;
156+ if ( resultContainer ) resultContainer . scrollIntoView ( { behavior : 'smooth' } ) ;
122157}
123158
124159// ============================================
@@ -285,7 +320,18 @@ function createShapeWrapper(size, shape, src, borderColor) {
285320
286321 // Outer div (border)
287322 outerDiv . style . width = size + 'px' ;
288- outerDiv . style . height = size + 'px' ;
323+
324+ // NEW: Calculate height for rectangle
325+ if ( shape === 'rectangle' ) {
326+ const currentW = parseInt ( document . getElementById ( 'imageSize' ) . value ) ;
327+ const currentH = parseInt ( document . getElementById ( 'rectHeight' ) . value ) ;
328+ // Calculate ratio so it works for both Preview and Download
329+ const ratio = currentH / currentW ;
330+ outerDiv . style . height = ( size * ratio ) + 'px' ;
331+ } else {
332+ outerDiv . style . height = size + 'px' ;
333+ }
334+
289335 outerDiv . style . background = borderColor ;
290336 outerDiv . style . display = 'flex' ;
291337 outerDiv . style . justifyContent = 'center' ;
@@ -314,7 +360,7 @@ function createShapeWrapper(size, shape, src, borderColor) {
314360 outerDiv . style . shapeOutside = 'circle(50%)' ;
315361 innerDiv . style . borderRadius = '50%' ;
316362 img . style . borderRadius = '50%' ;
317- } else if ( shape === 'square' ) {
363+ } else if ( shape === 'square' || shape === 'rectangle ') {
318364 // Square shape logic (no radius, no clip-path)
319365 outerDiv . style . borderRadius = '0' ;
320366 outerDiv . style . shapeOutside = 'none' ;
0 commit comments