def generate_thumbnails(img_path): # Compute filenames and paths img_path = os.path.normpath(img_path) base_path, img_fname = os.path.split(img_path) filename, ext = os.path.splitext(img_fname) png_large_name = filename + '.png' png_thumb_name = filename + '.tb.png' png_large_path = os.path.normpath(os.path.join(base_path, png_large_name)) png_thumb_path = os.path.normpath(os.path.join(base_path, png_thumb_name)) # Convert original TIFF file to PNG format and also create a thumbnailed version. # Use Pillow, ImageMagick or other tooling. logger.info('Processing image "{}"'.format(img_path)) with open(img_path, 'rb') as tiff: # Write original image in PNG format # Only process image if not already exists if not os.path.exists(png_large_path): png_large = to_png(tiff) with open(png_large_path, 'wb') as f: f.write(png_large.read()) tiff.seek(0) # Write thumbnail image in PNG format # Only process image if not already exists if not os.path.exists(png_thumb_path): width, height = THUMBNAIL_SIZE png_thumb = to_png(tiff, width=width, height=height) with open(png_thumb_path, 'wb') as f: f.write(png_thumb.read()) return png_thumb_name, png_large_name, img_fname
def to_png(self, img_name): util.to_png(img_name, 50, 50, self.states)
def to_png(self, png_name): util.to_png(png_name, 50, 50, self.states)