Cavan
Cavan

Reputation: 23

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

Upvotes: 0

Views: 1119

Answers (2)

Pim
Pim

Reputation: 958

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).

Upvotes: 1

tomgalpin
tomgalpin

Reputation: 2109

Its String encoding of the file path which is causing the issue See: "Unicode Error "unicodeescape" codec can't decode bytes... Cannot open text files in Python 3

Upvotes: 0

Related Questions