diff --git a/public/assets/camila_prof.png b/public/assets/camila_prof.png index 1a7b58d..8e14e08 100644 Binary files a/public/assets/camila_prof.png and b/public/assets/camila_prof.png differ diff --git a/public/assets/camila_prof.png.orig b/public/assets/camila_prof.png.orig new file mode 100644 index 0000000..1a7b58d Binary files /dev/null and b/public/assets/camila_prof.png.orig differ diff --git a/public/assets/kemily.png b/public/assets/kemily.png index 5854182..563548d 100644 Binary files a/public/assets/kemily.png and b/public/assets/kemily.png differ diff --git a/public/assets/kemily.png.orig b/public/assets/kemily.png.orig new file mode 100644 index 0000000..5854182 Binary files /dev/null and b/public/assets/kemily.png.orig differ diff --git a/scratch/optimize_avatars.py b/scratch/optimize_avatars.py new file mode 100644 index 0000000..67e51e2 --- /dev/null +++ b/scratch/optimize_avatars.py @@ -0,0 +1,51 @@ +import os +import sys +from PIL import Image + +def optimize_image(img_path, size=160, backup=False): + if not os.path.exists(img_path): + print(f"Error: {img_path} not found.") + return + + src_path = img_path + if backup: + backup_path = img_path + ".orig" + if not os.path.exists(backup_path): + os.rename(img_path, backup_path) + print(f"Backed up original to {backup_path}") + src_path = backup_path + else: + src_path = backup_path + + try: + img = Image.open(src_path) + width, height = img.size + print(f"Optimizing {img_path}: Original size {width}x{height}") + + # Crop to square + crop_size = min(width, height) + left = (width - crop_size) // 2 + + if height > width: + top = int((height - crop_size) * 0.15) + else: + top = (height - crop_size) // 2 + + right = left + crop_size + bottom = top + crop_size + + cropped = img.crop((left, top, right, bottom)) + resized = cropped.resize((size, size), Image.Resampling.LANCZOS) + + # Save as PNG + resized.save(img_path, 'PNG', optimize=True) + print(f"Saved optimized {size}x{size} image to {img_path}") + except Exception as e: + print(f"Error processing image: {e}") + +if __name__ == '__main__': + if len(sys.argv) > 1: + optimize_image(sys.argv[1], backup=False) + else: + optimize_image('/root/Apps/Camila/public/assets/camila_prof.png', backup=True) + optimize_image('/root/Apps/Camila/public/assets/kemily.png', backup=True) diff --git a/server.js b/server.js index dde0b97..063034d 100644 --- a/server.js +++ b/server.js @@ -1295,7 +1295,15 @@ app.post('/api/upload-avatar', requireAuth, (req, res) => { console.error('Erro ao salvar avatar:', err); return res.status(500).json({ error: 'Erro ao salvar arquivo' }); } - return res.json({ success: true, url: `assets/${fileName}` }); + + // Otimizar a imagem em segundo plano com Python + const { exec } = require('child_process'); + exec(`python3 scratch/optimize_avatars.py "${filePath}"`, (pyErr) => { + if (pyErr) { + console.error('Erro ao otimizar o avatar enviado com Python:', pyErr); + } + return res.json({ success: true, url: `assets/${fileName}` }); + }); }); });