Le code qui suit me sert à limiter la taille des images que je pose sur blogiwi à une largeur de 475, par exemple python x.py monimage.jpg
j'ai mis des commentaires pour rappeler l'indentation disparue à l'affichage
import Image,sys
from decimal import Decimal
img = Image.open('%s/%s' % ('/home/gg', sys.argv[1]))
(width, height) = img.size
print img.size
(max_width, max_height) = (475, 1000)
ratio = Decimal(width)/Decimal(height)
target_ration = Decimal(max_width)/Decimal(max_height)
if width > max_width:
width = max_width; #tabulation disparue à l'affichage
height = Decimal(width)/ratio# là aussi
#if height is still bigger than target ie
#above condition wasnt met then check height
if height > max_height:
height = max_height # tabulation
width = Decimal(height)*ratio #tabulation
img_resize = img.resize((width, height), Image.ANTIALIAS)
img_resize.save('%s/%s' % ('/home/gg', sys.argv[1]), quality=85)
# en python
Posté par palm123 (site web personnel) . En réponse au message Automatisation de réduction d'image. Évalué à 3.
j'ai mis des commentaires pour rappeler l'indentation disparue à l'affichage
import Image,sys
from decimal import Decimal
img = Image.open('%s/%s' % ('/home/gg', sys.argv[1]))
(width, height) = img.size
print img.size
(max_width, max_height) = (475, 1000)
ratio = Decimal(width)/Decimal(height)
target_ration = Decimal(max_width)/Decimal(max_height)
if width > max_width:
width = max_width; #tabulation disparue à l'affichage
height = Decimal(width)/ratio# là aussi
#if height is still bigger than target ie
#above condition wasnt met then check height
if height > max_height:
height = max_height # tabulation
width = Decimal(height)*ratio #tabulation
img_resize = img.resize((width, height), Image.ANTIALIAS)
img_resize.save('%s/%s' % ('/home/gg', sys.argv[1]), quality=85)
ウィズコロナ