L'application de l'anti-crénelage réduira les saccades lors de la réduction de la photo. Code Python qui réduit tous les fichiers photo dans un dossier tout en conservant le rapport hauteur / largeur (rapport hauteur / largeur), applique l'anti-aliasing et les enregistre.
J'ai réduit les photos d'environ 4000 pixels à 300 pixels et les ai comparées. Dans l'image d'oiseau avec AA, le petit sable sur le sol est difficile à voir car la couleur est intégrée au sol.

#Installation de PIL
pip install PIL --allow-external PIL --allow-unverified PIL
Confirmé pour fonctionner uniquement dans l'environnement python2.7 de mac
resize.py
# -*- coding: utf-8 -*-
import commands
import Image
import re
#Pixels de hauteur d'image lors de la réduction
PHOTO_HEIGHT = 300
#Chemin complet du dossier contenant l'image
BASE_DIR = "/Users/XXXXX/Desktop/Photos"
#Nom d'expression régulière de l'image
PHOTO_REGEX = r"P.*.[jpg|JPG]"
#Préfixe d'image après redimensionnement
PHOTO_RESIZE_PREFIX = "r_"
def main():
    #Obtenir le chemin complet de l'image
    _cmd = "cd {} && ls".format(BASE_DIR)
    l = commands.getoutput(_cmd)
    l = l.split("\n")
    l = [_l for _l in l if re.match(PHOTO_REGEX, _l)]
    #Générer un dossier pour la sortie
    commands.getoutput("mkdir {}/output".format(BASE_DIR))
    #Lire le fichier existant en mode lecture
    for _l in l:
        before_path = '{}/{}'.format(BASE_DIR, _l)
        filename = '{}{}'.format(PHOTO_RESIZE_PREFIX, _l)
        after_path = '{}/output/{}'.format(BASE_DIR, filename)
        resize(before_path, after_path, filename=_l)  #Rétrécir
def resize(before, after, height=PHOTO_HEIGHT, filename="", aa_enable=True):
    """
Redimensionner l'image
    :param str before:Chemin du fichier image d'origine
    :param str after:Chemin du fichier image après le redimensionnement
    :param int height:Hauteur de l'image après le redimensionnement
    :param bool aa_enable:Activer l'anticrénelage
    :return:
    """
    #Ouvrir l'image en lecture seule
    img = Image.open(before, 'r')
    #Calculer les pixels de l'image après le redimensionnement
    before_x, before_y = img.size[0], img.size[1]
    x = int(round(float(height / float(before_y) * float(before_x))))
    y = height
    resize_img = img
    if aa_enable:
        #Rétrécir avec l'anticrénelage
        resize_img.thumbnail((x, y), Image.ANTIALIAS)
    else:
        #Rétrécir sans antialiasing
        resize_img = resize_img.resize((x, y))
    #Enregistrer l'image après le redimensionnement
    resize_img.save(after, 'jpeg', quality=100)
    print "RESIZED!:{}[{}x{}] --> {}x{}".format(filename, before_x, before_y, x, y)
#Courir
main()
Résultat d'exécution
>>> python resize.py
RESIZED!:P1040673.jpg[4592x3448] --> 400x300
RESIZED!:P1050388.JPG[4592x3448] --> 400x300
RESIZED!:P1050389.JPG[4592x3448] --> 400x300
RESIZED!:P1050390.JPG[4592x3448] --> 400x300
RESIZED!:P1050391.JPG[4592x3448] --> 400x300
RESIZED!:P1050392.JPG[4592x3448] --> 400x300
RESIZED!:P1050393.JPG[4592x3448] --> 400x300
RESIZED!:P1050394.JPG[4592x3448] --> 400x300
        Recommended Posts