habulaj commited on
Commit
3a6bb87
·
verified ·
1 Parent(s): 14e2605

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -6
app.py CHANGED
@@ -565,23 +565,46 @@ TRADUZA TUDO DE IMPORTANTE NO {media_desc_final}, que tenha dialogo... Nunca dei
565
  def flip_image_both_axes(image_path: str) -> str:
566
  """
567
  Inverte uma imagem horizontalmente e verticalmente.
 
 
568
  Retorna o caminho para um novo arquivo temporário com a imagem invertida.
569
  """
570
  with Image.open(image_path) as img:
571
  # Inverter horizontalmente e verticalmente
572
  flipped = img.transpose(Image.FLIP_LEFT_RIGHT).transpose(Image.FLIP_TOP_BOTTOM)
573
 
 
 
 
 
 
 
 
574
  # Salvar em arquivo temporário
575
- temp_flipped = tempfile.NamedTemporaryFile(delete=False, suffix=Path(image_path).suffix)
576
- flipped.save(temp_flipped.name)
577
  temp_flipped.close()
578
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579
  return temp_flipped.name
580
 
581
 
582
  def flip_base64_image_both_axes(img_base64: str, content_type: str) -> str:
583
  """
584
  Inverte uma imagem base64 horizontalmente e verticalmente.
 
585
  Retorna o base64 da imagem invertida.
586
  """
587
  # Decodificar base64 para bytes
@@ -594,14 +617,22 @@ def flip_base64_image_both_axes(img_base64: str, content_type: str) -> str:
594
 
595
  # Salvar em buffer
596
  buffer = io.BytesIO()
 
597
  # Determinar formato baseado no content_type
598
- img_format = 'PNG'
599
  if 'jpeg' in content_type or 'jpg' in content_type:
600
- img_format = 'JPEG'
 
 
 
 
 
 
 
601
  elif 'webp' in content_type:
602
- img_format = 'WEBP'
 
 
603
 
604
- flipped.save(buffer, format=img_format)
605
  buffer.seek(0)
606
 
607
  # Converter de volta para base64
 
565
  def flip_image_both_axes(image_path: str) -> str:
566
  """
567
  Inverte uma imagem horizontalmente e verticalmente.
568
+ Usa compressão JPEG com qualidade 90 e subsampling 4:2:0 para alterar
569
+ o fingerprint da imagem e evitar detecção de figuras públicas.
570
  Retorna o caminho para um novo arquivo temporário com a imagem invertida.
571
  """
572
  with Image.open(image_path) as img:
573
  # Inverter horizontalmente e verticalmente
574
  flipped = img.transpose(Image.FLIP_LEFT_RIGHT).transpose(Image.FLIP_TOP_BOTTOM)
575
 
576
+ # Determinar extensão e formato
577
+ suffix = Path(image_path).suffix.lower()
578
+ if suffix in ['.jpg', '.jpeg']:
579
+ out_suffix = '.jpg'
580
+ else:
581
+ out_suffix = suffix
582
+
583
  # Salvar em arquivo temporário
584
+ temp_flipped = tempfile.NamedTemporaryFile(delete=False, suffix=out_suffix)
 
585
  temp_flipped.close()
586
 
587
+ # Salvar com parâmetros específicos para alterar fingerprint
588
+ if out_suffix in ['.jpg', '.jpeg']:
589
+ # Usar qualidade 90 e subsampling 4:2:0 (como o Figma faz)
590
+ # Isso altera os artefatos de compressão JPEG
591
+ flipped.save(
592
+ temp_flipped.name,
593
+ format='JPEG',
594
+ quality=90,
595
+ subsampling='4:2:0', # Chroma subsampling diferente
596
+ optimize=True
597
+ )
598
+ else:
599
+ flipped.save(temp_flipped.name)
600
+
601
  return temp_flipped.name
602
 
603
 
604
  def flip_base64_image_both_axes(img_base64: str, content_type: str) -> str:
605
  """
606
  Inverte uma imagem base64 horizontalmente e verticalmente.
607
+ Usa compressão JPEG com qualidade 90 para alterar o fingerprint.
608
  Retorna o base64 da imagem invertida.
609
  """
610
  # Decodificar base64 para bytes
 
617
 
618
  # Salvar em buffer
619
  buffer = io.BytesIO()
620
+
621
  # Determinar formato baseado no content_type
 
622
  if 'jpeg' in content_type or 'jpg' in content_type:
623
+ # Usar qualidade 90 e subsampling 4:2:0 para alterar fingerprint
624
+ flipped.save(
625
+ buffer,
626
+ format='JPEG',
627
+ quality=90,
628
+ subsampling='4:2:0',
629
+ optimize=True
630
+ )
631
  elif 'webp' in content_type:
632
+ flipped.save(buffer, format='WEBP', quality=90)
633
+ else:
634
+ flipped.save(buffer, format='PNG')
635
 
 
636
  buffer.seek(0)
637
 
638
  # Converter de volta para base64