How to download an image using Pillow(python)

Asked

Viewed 139 times

-1

I wonder how I can choose where my arquivo.png will be saved using Img.save()

1 answer

0


You can use the module os to choose the location where you want to save the file as follows:

from os.path import join as pjoin
from PIL import Image
filename = "arquivo.png"
i = Image.open("C:/Users/User/Desktop/", filename)
path_to_file = pjoin("C:\\", "<local onde queira salvar>", filename)
i.save(path_to_file)

Note: In the case of the first argument pjoin is "C: "because I’m considering that Voce uses Windows.

  • Vlw worked, but I have another problem. How do I make each file be of a different name? Type file(1). png, file(2).png. Or if you don’t delete the image after 5s using Pillow

  • in that case the variable filename should receive an input from the user asking what the file name is. I can’t answer his second question :(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.