Reputation: 515
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?
Upvotes: 21
Views: 135797
Reputation: 140
Code for saving image to a specific folder
import urllib.request
from PIL import Image
from pathlib import Path
import os
url="https://bimber.bringthepixel.com/main/wp-content/uploads/sites/17/2018/07/neon_type2_v02.jpg"
urllib.request.urlretrieve(url, os.path.join('E:/new projects of python/picture download','1.jpg'))
Upvotes: 0
Reputation: 327
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")
Upvotes: 13