I have just installed the Python imaging library and started to learn it but I cannot sem to open the image file.
import Image
im = Image.open(\"Desert.j
Use an absolute path. You can get the path of the script to create that path:
import os.path
script_dir = os.path.dirname(os.path.abspath(__file__))
im = Image.open(os.path.join(script_dir, 'Desert.jpg'))
Otherwise, relative files (anything without an absolute path) are opened relative to the current working directory, and that depends entirely on how you started the script and your operating system defaults.
The __file__
variable is the filename of the current module, the os.path
calls ensure it is a full absolute path (so including the drive when on Windows, starting with a /
on POSIX systems), from which we then take just the directory portion.