Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def persist_image(folder_path:str,url:str):
- try:
- image_content = requests.get(url).content
- except Exception as e:
- print(f"ERROR - Could not download {url} - {e}")
- try:
- image_file = io.BytesIO(image_content)
- image = Image.open(image_file).convert('RGB')
- file_path = os.path.join(folder_path,hashlib.sha1(image_content).hexdigest()[:10] + '.jpg')
- with open(file_path, 'wb') as f:
- image.save(f, "JPEG", quality=85)
- print(f"SUCCESS - saved {url} - as {file_path}")
- except Exception as e:
- print(f"ERROR - Could not save {url} - {e}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement