【问题标题】:Jpeg images resolution is not properly set by WandWand 未正确设置 Jpeg 图像分辨率
【发布时间】:2018-07-10 18:24:27
【问题描述】:

我正在尝试调整 jpeg 图像的大小并放大框架。为此,我将调整大小应用到原始图像,然后将其组合到较新的图像上:

with Image(blob=binary_data) as img:
    ...
    img.resize(width=new_width, height=long(2000))
    # Compose image to enlarge frame
    with Image(width=1571, height=2000, background=Color('white')) as dst_image:
        ...
        dst_image.composite(img, x, 0)
        img = dst_image
        img.resolution = (300,300)
        img.format = 'jpg'
        jpeg_bin = img.make_blob()

最后,我希望分辨率为 300dpi。 Imagemagick 命令 “识别”显示分辨率为 300dpi,但它不是真的;确实,如果我打开它 使用 Gimp 时,它显示的分辨率为 72dpi。

我正在使用 Wand v.0.4.4。

我的代码错了吗? ...有什么想法吗?

【问题讨论】:

  • 试试 EXIFTOOL 看看实际的密度/分辨率是多少。您可能还必须通过 wand 指定一组单位,例如像素每英寸。如果未指定,某些工具不知道如何解释密度/分辨率。见 wand.image.UNIT_TYPES
  • 谢谢@fmw42 它有效,它在下面的答案中提供了有关修复的详细信息。

标签: python wand


【解决方案1】:

@fmw42:谢谢,这是单位定义的问题。在修复之前,这是 exiftools 的输出:

  Resolution Unit                 : None
  X Resolution                    : 300
  Y Resolution                    : 300

我修正了它插入这一行:

  dst_image.units = 'pixelsperinch'

现在 exiftools 和 gimp 返回相同的分辨率:

  Resolution Unit                 : inches
  X Resolution                    : 300
  Y Resolution                    : 300

谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    相关资源
    最近更新 更多