Created
December 26, 2012 17:11
-
-
Save macndesign/4381562 to your computer and use it in GitHub Desktop.
Script para redimensionar imagem proporcionalmente de acordo com uma largura desejada.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
try: | |
from PIL import Image | |
except ImportError: | |
import Image | |
try: | |
largura_desejada = int(sys.argv[2]) | |
imagem = Image.open(str(sys.argv[1])) | |
largura_imagem = imagem.size[0] | |
altura_imagem = imagem.size[1] | |
percentual_largura = float(largura_desejada) / float(largura_imagem) | |
altura_desejada = int((altura_imagem * percentual_largura)) | |
imagem = imagem.resize((largura_desejada, altura_desejada), Image.ANTIALIAS) | |
imagem.save('imagem-{}x{}.png'.format(imagem.size[0], imagem.size[1])) | |
except IndexError: | |
print('Insira o nome da imagem e 1 inteiro com a largura desejada.') | |
print('Exemplo: C:\>python proporcional_img.py imagem.png 300') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment