phedited.py 文件源码

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

项目:IV 作者: collinmutembei 项目源码 文件源码
def save(self, *args, **kwargs):
        """overrides the save method for the model
        """

        # fetches the original image from its url and loads it to memory
        image_request = requests.get(self.original_image)
        image_bytes = io.BytesIO(image_request.content)
        image = Image.open(image_bytes)
        filename = os.path.basename(self.original_image)
        # call the apply_effect method on the in-memory original image
        image_with_effect = apply_effects(image, self.effects)
        # creat an empty in-memory bytes section to hold the edited image
        edited_image = io.BytesIO()
        image_with_effect.save(edited_image, format=image.format)
        # initiate an upload from the in-memory edited image
        edited_file = InMemoryUploadedFile(
            edited_image,
            None,
            filename,
            'image/jpeg',
            edited_image.tell,
            None
        )

        self.phedited_image.save(
            filename,
            edited_file,
            save=False,
        )
        super(PheditedImage, self).save(*args, **kwargs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号