【问题标题】:Set sampling algo设置采样算法
【发布时间】:2013-05-11 03:31:18
【问题描述】:

我正在尝试使用 PythonMagick 从 jpg 图像创建缩略图:

img.quality(90)
# TODO set the sampling algo e.g. bilinear
img.sample(Geometry(scaledWid, scaledHei))
img.crop(Geometry(THUMBNAIL_WID-1, THUMBNAIL_HEI-1,cropLeft, cropTop))
img.write(destFilePath)

如何设置要使用的采样算法?我相信现在它正在使用最近的邻居,看起来有点丑。

【问题讨论】:

    标签: imagemagick pythonmagick


    【解决方案1】:

    在调用.resize() 或我想是.sample() 之前,通过图像集上的属性设置调整大小过滤器。

    该属性是.filterType(),是从PythonMagick.FilterTypes 上的枚举值之一设置的 - 这与Magick++ FilterTypes 的列表相同。

    (注意。没有任何关于 PythonMagick 的文档,但由于它本质上只是 Magick++ 的包装器,因此只需使用 API documentation。)

    所以试试(未经测试,我不使用 Python):

    img.quality(90)
    
    img.filterType(PythonMagick.FilterTypes.SincFilter)
    img.sample(Geometry(scaledWid, scaledHei))
    
    img.crop(Geometry(THUMBNAIL_WID-1, THUMBNAIL_HEI-1,cropLeft, cropTop))
    
    img.write(destFilePath)
    

    注意默认过滤器通常是LanczosFilter,或者至少应该是这样,这非常好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      • 2011-01-11
      • 2013-08-10
      • 2022-11-19
      • 1970-01-01
      • 2010-09-23
      • 1970-01-01
      相关资源
      最近更新 更多