@@ -33,7 +33,7 @@ export const usePhotoGallery = () => {
3333 } ;
3434
3535 /**
36- * Process and compress image
36+ * Process and compress image with better quality settings
3737 */
3838 const processImage = async ( imageBlob : Blob , maxSize : number , maxHeight : number , maxWidth : number ) : Promise < Blob > => {
3939 return new Promise ( ( resolve , reject ) => {
@@ -55,18 +55,23 @@ export const usePhotoGallery = () => {
5555
5656 const ctx = canvas . getContext ( '2d' ) ;
5757 if ( ctx ) {
58+ // Enable high-quality image rendering
59+ ctx . imageSmoothingEnabled = true ;
60+ ctx . imageSmoothingQuality = 'high' ;
5861 ctx . drawImage ( img , 0 , 0 , width , height ) ;
5962 }
60- let quality = 1 ; // Start with 100% quality
61- const step = 0.1 ; // Reduce quality by 10% each step
63+
64+ let quality = 1 ; // Start with 95% quality instead of 100%
65+ const step = 0.05 ; // Reduce quality by 5% each step (more gradual)
66+ const minQuality = 0.8 ; // Don't go below 80% quality (was 60%)
6267
6368 const reduceQualityParameter = ( ) => {
6469 canvas . toBlob ( ( blob ) => {
6570 if ( ! blob ) {
6671 reject ( new Error ( 'Failed to convert canvas to blob' ) ) ;
6772 return ;
6873 }
69- if ( blob . size <= convertedMaxSize || quality <= 0.6 ) {
74+ if ( blob . size <= convertedMaxSize || quality <= minQuality ) {
7075 resolve ( blob ) ;
7176 } else {
7277 quality -= step ;
@@ -162,8 +167,8 @@ export const usePhotoGallery = () => {
162167 try {
163168 const stream = await navigator . mediaDevices . getUserMedia ( {
164169 video : {
165- width : { ideal : 1280 } ,
166- height : { ideal : 720 } ,
170+ width : { ideal : 1920 , min : 1280 } , // Higher resolution for better quality
171+ height : { ideal : 1080 , min : 720 } ,
167172 facingMode : 'user' // Front camera for profile photos
168173 }
169174 } ) ;
@@ -180,8 +185,15 @@ export const usePhotoGallery = () => {
180185 captureButton . onclick = ( ) => {
181186 canvas . width = video . videoWidth ;
182187 canvas . height = video . videoHeight ;
183- context ?. drawImage ( video , 0 , 0 ) ;
184188
189+ // Use high-quality canvas rendering
190+ if ( context ) {
191+ context . imageSmoothingEnabled = true ;
192+ context . imageSmoothingQuality = 'high' ;
193+ context . drawImage ( video , 0 , 0 ) ;
194+ }
195+
196+ // Increased JPEG quality from 0.9 to 0.95 for better camera captures
185197 canvas . toBlob ( ( blob ) => {
186198 if ( blob ) {
187199 stopCamera ( ) ;
@@ -190,7 +202,7 @@ export const usePhotoGallery = () => {
190202 stopCamera ( ) ;
191203 reject ( new Error ( 'Failed to capture photo' ) ) ;
192204 }
193- } , 'image/jpeg' , 0.9 ) ;
205+ } , 'image/jpeg' , 0.95 ) ;
194206 } ;
195207
196208 cancelButton . onclick = ( ) => {
@@ -237,7 +249,7 @@ export const usePhotoGallery = () => {
237249 } ;
238250
239251 /**
240- * Take photo for gallery (larger size )
252+ * Take photo for gallery (higher quality, less compression )
241253 */
242254 const takePhotoGallery = async ( ) : Promise < Blob > => {
243255 try {
@@ -249,14 +261,15 @@ export const usePhotoGallery = () => {
249261 photoBlob = await takePhotoWithFileInput ( ) ;
250262 }
251263
252- return await processImage ( photoBlob , 1 , 2000 , 2000 ) ;
264+ // Increased size limit to 3MB and dimensions to 2400x2400 for better gallery quality
265+ return await processImage ( photoBlob , 3 , 2400 , 2400 ) ;
253266 } catch ( e ) {
254267 throw new Error ( `Failed to take photo: ${ e instanceof Error ? e . message : 'Unknown error' } ` ) ;
255268 }
256269 } ;
257270
258271 /**
259- * Take photo for profile (smaller, compressed )
272+ * Take photo for profile (smaller, but still good quality )
260273 */
261274 const takePhotoProfile = async ( ) : Promise < Blob > => {
262275 try {
@@ -268,7 +281,8 @@ export const usePhotoGallery = () => {
268281 photoBlob = await takePhotoWithFileInput ( ) ;
269282 }
270283
271- return await processImage ( photoBlob , 0.2 , 800 , 600 ) ;
284+ // Increased size limit from 0.2MB to 1MB for better profile photo quality
285+ return await processImage ( photoBlob , 1 , 800 , 600 ) ;
272286 } catch ( e ) {
273287 throw new Error ( `Failed to take profile photo: ${ e instanceof Error ? e . message : 'Unknown error' } ` ) ;
274288 }
0 commit comments