How do I use Python PIL to save an image to a particular directory?
Question:
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?
Answers:
Try this
img.save('/absolute/path/to/myphoto.jpg', 'JPEG')
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")
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'))
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?
Try this
img.save('/absolute/path/to/myphoto.jpg', 'JPEG')
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")
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'))