lundi 13 avril 2015

How to save an image with the Python Image Library

I am a beginner in Python, so this question might be stupid but unfortunatly I can't figure it out on my own.


With the following script I want to create a black image and save it under the following path: C://Users/User/Desktop/black.png



def create_file(x=1000,y=10):
img = Image.new('RGB', (x,y), "black") #creates a new black image
img.save('C://Users/User/Desktop/black.png')`


The point is now that I want to pretend the path, the filename and the filetyp with the function like that:



create_image(x=1000,y=10,path=C://Users/bsimon/Desktop/,filename=black,filetype=png)`


And there the struggle begins:




  1. I cant find the exact Syntax how I can deliver the path (filename, filetyp) to the img.save function




  2. I got errors by using a different filetyp than png. The line img.save('C://Users/User/Desktop/black.png') works fine but when I try to use img.save('C://Users/User/Desktop/black.bmp') instead for example, the program I run the script with (Blender) crashes or get stucked in an endless loop).




Aucun commentaire:

Enregistrer un commentaire