Python Imaging Library
Este artigo não cita fontes confiáveis. (janeiro de 2014) |
Python Imaging Library (abreviado para PIL) é uma biblioteca da linguagem de programação Python que adiciona suporte à abertura e gravação de muitos formatos de imagem diferentes.
Formatos de Imagens
Alguns dos formatos suportados são o PNG, TIFF, BMP, EPS e GIF. Também é possível criar novos decodifidores de arquivo para expandir a biblioteca em formatos de imagens acessíveis.
Pacotes que usam o PIL
Há muitos pacotes que usam o PIL para fazer manipulação de imagens. Alguns exemplos são:
- Numeric Python, uma biblioteca da linguagem que adiciona suporte para matrizes e arrays grandes e multi-dimensionais.
- SciPy, uma biblioteca de rotinas científicas e numéricas.
Instalação
Instalação no Linux Procure o pacote python-imaging. Em geral:
apt-get install python-imaging
Instalação no Windows Há um instalador EXE Aqui[1]. Antes de baixar verifique a versão do seu Python.
Exemplo de código
from PIL import Image, ImageDraw, ImageFont
def escreve():
imagem = "original.jpeg", # Nome da imagem original
texto = "teste com PIL", # Texto a inserir na imagem de cor cinza
imagem_final = "arquivo_final.jpeg" # Resultado da imagem
img = Image.open(imagem).convert("RGB")
write = Image.new("RGB", (img.size[0], img.size[1]))
draw = ImageDraw.ImageDraw(img)
size = 0
while True:
size +=1
FONT_win = "C:\WINDOWS\Fonts\Vera.ttf"
nextfont = ImageFont.truetype(FONT_win, size)
nexttextwidth, nexttextheight = nextfont.getsize(text)
if nexttextwidth+nexttextheight/3 > write.size[0]:
break
font = nextfont
textwidth, textheight = nexttextwidth, nexttextheight
draw.setfont(font)
draw.text(((write.size[0]-textwidth)/55, (write.size[0]-textheight)/55), texto, fill=(120,120,120))
img.save(imagem_final)
if __name__ == '__main__':
escreve()
Ligações externas
- Website Oficial - Em inglês
- Interface de Referência - Em inglês
- [1]
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.