我在 Django 项目中使用 wand,从不同类型的文件(例如 pdf)生成缩略图,所有缩略图生成过程都在内存中完成,源文件是从请求中获取的,缩略图保存到临时文件, 然后 Django FileFiled 将图像保存在正确的路径中,但生成的缩略图保持初始大小,这是我的代码:
with image.Image(file=self.content.file, format="png") as im: # self.content is a django model FileField didn't saved yet, so the file inside is still in memory (from the request)
im.resize(200, 200)
name = self.content.file.name
self.temp = tempfile.NamedTemporaryFile()
im.save(file=self.temp)
self.thumbnail = InMemoryUploadedFile(self.temp, None, name + ".png", 'image/png', 0, 0, None) # then self.thumnail as FileField saves the image
你知道会发生什么吗?可能是一个错误?我已经在 wand github 页面上将其报告为问题。