For example I want to manipulate some image and then save it to a particular directory. How do I save to a specific directory other than the one I am in? I understand that this will save to the directory I am in:
from PIL import Image
""" Some Code """
img.save("sample.png", "")
How do I save to a different directory?
Saving an image can be achieved by using . save() method with PIL library's Image module in Python.
The PIL module is used for storing, processing, and displaying images in Python. To save images, we can use the PIL. save() function. This function is used to export an image to an external file.
First create the directory before saving the image to the directory
from PIL import Image
import os
image_path = "path/to/image"
os.mkdir(image_path)
image = image.save(f"{image_path}/image.png")
Try this
img.save('/absolute/path/to/myphoto.jpg', 'JPEG')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With