简体   繁体   中英

Opening a GIF picture with PIL in Python

I am trying to open a GIF file but it is coming up with a syntax error i do not understand. Does the image have to change to PNG / JPEG because i am trying to keep transparency which would be lost if i have to change the file type.

The Syntax Error i don't understand

I have tried to keep the image and open it with Turtle by using screen.addshape. That works for the image however i have had a problem with resizing the image so i am having to use the PIL library to open the images and then resize them

Image.open("your.gif") should work. However, the path is not the string you think it is. \\ is the escape character. To type a \\ , you will need to use \\\\ in stead of \\ .

Thus Image.open("C:\\Your\\Path\\to a funny\\image.gif") becomes Image.open("C:\\\\Your\\\\Path\\\\to a funny\\\\image.gif") or Image.open(r"C:\\Your\\Path\\to a funny\\image.gif") (a raw string).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM