models.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:pandachaika 作者: pandabuilder 项目源码 文件源码
def save_img(self, img_link: str) -> None:
        tf2 = NamedTemporaryFile()
        request_file = requests.get(img_link, stream='True', timeout=25)

        for chunk in request_file.iter_content(4096):
            tf2.write(chunk)
        self.image.save(os.path.splitext(img_link)[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_link)[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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号