#πŸ”’ How to use Image.open to open the actual image file, and not a temp file?

7 messages Β· Page 1 of 1 (latest)

brave vapor
#

Hi all, new to python and spent the last few days learning some basics (but kind of rushing through the fundimentals; i have some coding bg and mainly wanted to dive into working on this. not good practice, but its what i did)

My end goal is to write a program that will open a random PNG file from the liss of all files in a folder. i have written that successfully, but what i need is for it to open the actual file for editing. Below is a simplified version of my code that simply opens a specified image in a given older, and writes the filepath in the console.

Currently, as per how the actual module works, it scans the chosen file and opens it as a temporary image, which is deleted as soon as its opened, making it essentially a fresh image that would need to be saved/"re"saved as a new file, with the original left untouched no matter what. How would i go about opening the original file, such that the paint window that opens can be edited and then Ctrl + S would save those changes over the original specified file?

from PIL import Image       # Initializer for images.

FileName = "3"              # File to open.
FilePath = "C:/Users/ [Username] /Desktop/RandomImageTest/" + FileName + ".png"  # Filepath for image to open.

print(FilePath)             # Writes the filename in console.
Image.open(File).show()     # Opens file.```
long oracleBOT
#

@brave vapor

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

obsidian holly
#

you're opening it in memory so you can modify it. after your modifications, you save it back to disk

tardy stone
#

@brave vapor ^^

long oracleBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.