7070< body >
7171 < div class ="container ">
7272 < h1 > Social Media Card Cropper</ h1 >
73- < p > Drop an image or click to select. The crop area is fixed to 2:1 ratio.</ p >
73+ < p > Drop an image or click to select. Select your preferred aspect ratio below.</ p >
74+
75+ < div style ="margin-bottom: 15px; ">
76+ < label style ="margin-right: 10px; ">
77+ < input type ="radio " name ="aspectRatio " value ="2 " checked > 2:1 ratio
78+ </ label >
79+ < label >
80+ < input type ="radio " name ="aspectRatio " value ="1.4 "> 14:10 ratio
81+ </ label >
82+ </ div >
7483
7584 < div class ="drop-zone " id ="dropZone ">
7685 Drop image here, click to select, or paste from clipboard
@@ -84,6 +93,7 @@ <h1>Social Media Card Cropper</h1>
8493 < div class ="preview-container hidden " id ="previewContainer ">
8594 < h3 > Preview (0.7 quality JPEG)</ h3 >
8695 < img id ="preview ">
96+ < div id ="dimensionsInfo " style ="text-align: center; margin-top: 5px; font-size: 14px; color: #666; "> </ div >
8797 < div style ="text-align: center; margin-top: 10px; ">
8898 < a href ="# " id ="downloadBtn " class ="download-btn "> Download Social Media Card</ a >
8999 </ div >
@@ -139,6 +149,15 @@ <h3>Preview (0.7 quality JPEG)</h3>
139149 handleFile ( e . target . files [ 0 ] ) ;
140150 }
141151 } ) ;
152+
153+ // Listen for aspect ratio changes and update the cropper
154+ document . querySelectorAll ( 'input[name="aspectRatio"]' ) . forEach ( radio => {
155+ radio . addEventListener ( 'change' , ( ) => {
156+ if ( cropper ) {
157+ initCropper ( ) ;
158+ }
159+ } ) ;
160+ } ) ;
142161
143162 function handleFile ( file ) {
144163 if ( ! file . type . startsWith ( 'image/' ) ) {
@@ -160,8 +179,12 @@ <h3>Preview (0.7 quality JPEG)</h3>
160179 cropper . destroy ( ) ;
161180 }
162181
182+ // Get the selected aspect ratio
183+ const aspectRatioValue = document . querySelector ( 'input[name="aspectRatio"]:checked' ) . value ;
184+ const ratio = parseFloat ( aspectRatioValue ) ;
185+
163186 cropper = new Cropper ( image , {
164- aspectRatio : 2 ,
187+ aspectRatio : ratio ,
165188 viewMode : 1 ,
166189 dragMode : 'move' ,
167190 autoCropArea : 1 ,
@@ -187,6 +210,10 @@ <h3>Preview (0.7 quality JPEG)</h3>
187210 preview . src = previewUrl ;
188211 previewContainer . classList . remove ( 'hidden' ) ;
189212
213+ // Show dimensions
214+ const dimensionsInfo = document . getElementById ( 'dimensionsInfo' ) ;
215+ dimensionsInfo . textContent = `Dimensions: ${ canvas . width } × ${ canvas . height } pixels` ;
216+
190217 // Update download link
191218 downloadBtn . href = previewUrl ;
192219 downloadBtn . download = 'social-media-card.jpg' ;
0 commit comments