def copy_img(self, img_path: str) -> None:
tf2 = NamedTemporaryFile()
shutil.copy(img_path, tf2.name)
self.image.save(os.path.splitext(img_path)[1], File(tf2), save=False)
tf2.close()
im = PImage.open(self.image.path)
if im.mode != 'RGB':
im = im.convert('RGB')
# large thumbnail
im.thumbnail((200, 290), PImage.ANTIALIAS)
thumb_relative_path = upload_announce_thumb_handler(self, os.path.splitext(img_path)[1])
thumb_fn = pjoin(settings.MEDIA_ROOT, thumb_relative_path)
os.makedirs(os.path.dirname(thumb_fn), exist_ok=True)
im.save(thumb_fn, "JPEG")
self.thumbnail.name = thumb_relative_path
self.save()
评论列表
文章目录