def generate_thumbnail(self): self.thumbnail_uuid = hash_file(self.file_path) + ".jpg" with Image(background=Color('#EEEEEE'), width=256, height=256) as bg: with open(self.file_path, encoding='utf-8', errors='ignore') as f: text = f.read() if len(text) > 512: text = text[0:512] font = Font(path="Arial", size=20, color=Color('#333333')) bg.caption(text=text, left=10, top=10, font=font) bg.save( filename=os.path.join(self.dir_path, self.thumbnail_uuid))
def generate_thumbnail(self): self.thumbnail_uuid = hash_file(self.file_path) + ".jpg" with Image(filename=self.file_path) as img: with Image(width=img.width, height=img.height, background=Color("#EEEEEE")) as bg: bg.composite(img, 0, 0) size = img.width if img.width < img.height else img.height bg.crop(width=size, height=size, gravity='center') bg.resize(256, 256) bg.format = 'jpeg' bg.save(filename=os.path.join(self.dir_path, self.thumbnail_uuid))
def generate_thumbnail(self): self.thumbnail_uuid = hash_file(self.file_path) + ".gif" with Image(filename=self.file_path) as img: size = img.width if img.width < img.height else img.height img.crop(width=size, height=size, gravity='center') img.resize(256, 256) img.format = 'gif' img.save(filename=os.path.join(self.dir_path, self.thumbnail_uuid)) # If the file size is over 5mb, save jpeg thumbnail instead if os.path.getsize(os.path.join(self.dir_path, self.thumbnail_uuid)) > MAX_FILE_SIZE: super()
def generate_thumbnail(self): self.thumbnail_uuid = hash_file(self.file_path) + ".jpg" thumbnail_loc = os.path.join(self.dir_path, self.thumbnail_uuid) clip = VideoFileClip(self.file_path) time_mark = clip.duration * 0.05 clip.save_frame(thumbnail_loc, t=time_mark) with Image(filename=thumbnail_loc) as img: with img.clone() as image: size = image.width if image.width < image.height else image.height image.crop(width=size, height=size, gravity='center') image.resize(256, 256) image.background_color = Color("#EEEEEE") image.format = 'jpeg' image.save(filename=thumbnail_loc)
def generate_thumbnail(self): self.thumbnail_uuid = hash_file(self.file_path) + ".jpg" with Image(filename=self.file_path, resolution=300) as all_pages: with Image(all_pages.sequence[0]) as first_page: with Image(width=first_page.width, height=first_page.height, background=Color("#EEEEEE")) as bg: bg.composite(first_page, 0, 0) size = first_page.width if first_page.width < first_page.height else first_page.height bg.crop(width=size, height=size, gravity='north') # top of first page bg.resize(256, 256) bg.format = 'jpeg' bg.save(filename=os.path.join(self.dir_path, self.thumbnail_uuid))
def generate_thumbnail(self): self.thumbnail_uuid = hash_file(self.file_path) + ".jpg" with Image(filename="thumbnails/reedphoto.jpg") as bg: bg.save(filename=os.path.join(self.dir_path, self.thumbnail_uuid))