【问题标题】:Wand Image from PDF doesn't apply resizingPDF中的魔杖图像不适用调整大小
【发布时间】:2015-04-10 02:57:04
【问题描述】:

我在 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 页面上将其报告为问题。

【问题讨论】:

    标签: python-3.x thumbnails wand


    【解决方案1】:

    问题在于您的 PDF 有多个页面。如果您只调整第一页的大小(这是您要显示的那个),它可以工作。尝试在 with 语句后添加以下行:

    im = image.Image(image=im.sequence[0])
    

    但我同意你的观点,你的版本也应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-09
      • 2015-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多