""" !!! FICHIER OBSOLÈTE !!! Ce fichier est maintenu uniquement pour la compatibilité. Veuillez utiliser les modules dans utils/ocr_avance/ à la place. """ from PIL import Image, ImageOps from pathlib import Path import os BICUBIC = Image.Resampling.BICUBIC # Nouvelle façon d'accéder à BICUBIC def prepare_image_for_llama_vision(input_path: str, output_path: str, size=(672, 672)) -> str: from PIL import ImageOps, Image img = Image.open(input_path) if img.mode != "RGB": img = img.convert("RGB") # Redimensionne en conservant le ratio img.thumbnail(size, Image.Resampling.BICUBIC) # Ajoute du padding pour obtenir exactement 672x672 padded_img = Image.new("RGB", size, (255, 255, 255)) # fond blanc offset = ((size[0] - img.width) // 2, (size[1] - img.height) // 2) padded_img.paste(img, offset) padded_img.save(output_path, format="PNG", optimize=True) return output_path