Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import base64
- from PIL import Image, ImageChops
- import piexif
- # Liste d'URLs encodées en base64
- encoded_urls = [
- "aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vdXJsMQ==",
- "aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vdXJsMg==",
- "aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vdXJsMw==",
- "aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20vdXJsNA=="
- ]
- # Fonction pour comparer deux images
- def compare_images(image1_path, image2_path):
- image1 = Image.open(image1_path).convert('RGB')
- image2 = Image.open(image2_path).convert('RGB')
- # Compare les histogrammes
- h1 = image1.histogram()
- h2 = image2.histogram()
- rms = sum((a - b) ** 2 for a, b in zip(h1, h2)) ** 0.5
- return rms
- # Fonction pour insérer un commentaire dans les métadonnées EXIF
- def insert_exif_comment(image_path, comment):
- exif_dict = piexif.load(image_path)
- # Convertir le commentaire en bytes
- comment_bytes = comment.encode('utf-8')
- # Insérer le commentaire dans les métadonnées EXIF
- exif_dict['0th'][piexif.ImageIFD.ImageDescription] = comment_bytes
- # Sauvegarder les modifications dans l'image
- exif_bytes = piexif.dump(exif_dict)
- Image.open(image_path).save(image_path, exif=exif_bytes)
- # Chemins vers les images à comparer
- image1_path = "image1.jpg"
- image2_path = "image2.jpg"
- # Comparer les images
- rms_value = compare_images(image1_path, image2_path)
- threshold = 1000 # Ajustez ce seuil en fonction de la précision souhaitée
- if rms_value < threshold:
- # Sélectionner une URL aléatoire encodée en base64
- random_comment = base64.b64decode(random.choice(encoded_urls)).decode('utf-8')
- # Insérer le commentaire dans les EXIF de la première image
- insert_exif_comment(image1_path, random_comment)
- print(f"Les images sont similaires. Commentaire inséré : {random_comment}")
- else:
- print("Les images ne sont pas assez similaires pour insérer un commentaire.")
Add Comment
Please, Sign In to add comment