pil open from convert python python-imaging-library

python - open - Guardando Imagen con PIL



python pil image open (2)

PIL no es un atributo de newImg1, pero newImg1 es una instancia de PIL.Image, por lo que tiene un método para guardar, por lo tanto, lo siguiente debería funcionar.

newImg1.save("img1.png","PNG")

Tenga en cuenta que solo llamar a un archivo .png no lo convierte en uno, por lo que debe especificar el formato del archivo como segundo parámetro.

tratar:

type(newImg1) dir(newImg1)

y

help(newImg1.save)

Estoy intentando guardar una imagen que creé desde cero con PIL

newImg1 = PIL.Image.new(''RGB'', (512,512)) pixels1 = newImg1.load() ... for i in range (0,511): for j in range (0,511): ... pixels1[i, 511-j]=(0,0,0) ... newImg1.PIL.save("img1.png")

y me sale el siguiente error:

Seguimiento (última llamada más reciente): Archivo "", línea 1, en Archivo "C: / Python27 / lib / site-packages / spyderlib / widgets / externalshell / sitecustomize.py", línea 523, en el archivo ejecutable execfile (nombre de archivo, espacio de nombres ) Archivo "C: / Python27 / Lib / site-packages / xy / pyimgmake.py", línea 125, en newImg1.PIL.save ("img1.png") Archivo "C: / Python27 / lib / site-packages / PIL / Image.py ", línea 512, en getattr raise AttributeError (name) AttributeError: PIL

Necesito ayuda para interpretar este error y cómo guardar la imagen correctamente como "img1.png" (Estoy bien con la imagen guardada en el lugar de guardado predeterminado).

ACTUALIZAR:

from PIL import Image as pimg ... newImg1 = pimg.new(''RGB'', (512,512)) ... newImg1.save("img1.png")

y me sale el siguiente error:

... newImg1.save ("img1.png") Archivo "C: / Python27 / lib / site-packages / PIL / Image.py", línea 1439, en save save_handler (self, fp, filename) Archivo "C: / Python27 / lib / site-packages / PIL / PngImagePlugin.py ", línea 572, en _save ImageFile._save (im, _idat (fp, chunk), [(" zip ", (0,0) + im.size, 0, modo en bruto)]) Archivo "C: / Python27 / lib / site-packages / PIL / ImageFile.py", línea 481, en _save e = Image._getencoder (im.mode, e, a, im.encoderconfig) File "C: / Python27 / lib / site-packages / PIL / Image.py", línea 399, en _getencoder return apply (codificador, (modo,) + args + extra) TypeError: se requiere un número entero


Prueba esto:

newImg1 = pimg.as_PIL(''RGB'', (512,512)) ... newImg1.save(''Img1.png'')