7 examples of 'python save image to directory' in Python

Every line of 'python save image to directory' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
115def write_image(filename, image):
116 os.makedirs(os.path.dirname(filename), exist_ok=True)
117 im = Image.fromarray(image)
118 im.save(filename)
54def save_img(img_pil, subfolder, name):
55 img_pil.save(subfolder+name+'.png')
12def save_image(filename, data):
13 img= data[:,:,[2,1,0]]
14 # img = data.clone().clamp(0, 255).numpy()
15 # img = img.transpose(1, 2, 0).astype("uint8")
16 img=img.astype("uint8")
17 img = Image.fromarray(img)
18 img.save(filename)
100def save_crop(base_dir, image_name, index, crop):
101 """
102 Save window crop as image file to be read by PIL. Filename should match the image_name + window index
103
104 """
105 #create dir if needed
106 if not os.path.exists(base_dir):
107 os.makedirs(base_dir)
108
109 im = Image.fromarray(crop)
110 image_basename = os.path.splitext(image_name)[0]
111 filename = "{}/{}_{}.jpg".format(base_dir, image_basename, index)
112 im.save(filename)
113
114 return filename
99def save_image (lt_image, page_number, images_folder):
100 """Try to save the image data from this LTImage object, and return the file name, if successful"""
101 result = None
102 if lt_image.stream:
103 file_stream = lt_image.stream.get_rawdata()
104 if file_stream:
105 file_ext = determine_image_type(file_stream[0:4])
106 if file_ext:
107 file_name = ''.join([str(page_number), '_', lt_image.name, file_ext])
108 if write_file(images_folder, file_name, file_stream, flags='wb'):
109 result = file_name
110 return result
87def save_img(im, file_path):
88 ext = splitext(file_path)[1]
89 if ext in ['.tif', '.tiff']:
90 save_rasterio(im, file_path)
91 else:
92 save_pillow(im, file_path)
56def save_image(image_numpy, image_path):
57 image_pil = Image.fromarray(image_numpy)
58 image_pil.save(image_path)

Related snippets