我使用libvips
将HEIC
图像转换为更易于处理的格式,并在不写入磁盘的情况下将结果传输到另一个进程。我可以使用PNG
作为中间格式来实现这一点:
vips copy input.heic .png
但是,我链中的下一个进程只接受BMP
图像或原始RGB数据。如果在上面的命令中将.png
替换为.bmp
,则会得到以下错误:
input.heic: bad seek to 1811903
VipsForeignSave: ".bmp" is not a known target format
这种情况发生在许多其他格式中,包括本机.vips
。如果我将转换写入磁盘而不是stdout
,则所有格式都能很好地转换。
它将有助于转换为BMP
或具有RGB信息的整数列表。
发布于 2020-11-27 05:56:48
不确定您是在寻找解决方案,还是希望约翰为libvips
提供软件更新,或者确切地说是什么。
无论如何,我只想说,如果你想要一个工作,把vips
输出转换成BMP,你可以使用ppmtobmp
,这是NetPBM套件的一部分。
因此,对于一个文件来说:
vips copy image.heic .ppm | ppmtobmp - > result.bmp
并作为流过滤器,而不进入磁盘:
vips copy image.jpg .ppm | ppmtobmp | NextProcess
请注意,ppm
格式实际上是RGB格式,开头有3-4行ASCII标头,其中包含尺寸--尝试并查看。因此,如果您可以在Windows中找到删除3-4行ASCII的方法,您就可以得到RGB。或者,如果您的图像是640x480像素(3字节/像素),也许您可以在Windows上找到一个文件的最后一个字节(640x480x3)字节,或者以这种方式流并丢弃PPM报头。
关键词:HEIC,vips,NetPBM,BMP
发布于 2020-11-26 14:59:48
您可以看到vips -l
支持的一组格式。对于8.10,它是:
$ vips -l | grep _target
VipsForeignSaveCsvTarget (csvsave_target), save image to csv (.csv), priority=0, mono
VipsForeignSaveMatrixTarget (matrixsave_target), save image to matrix (.mat), priority=0, mono
VipsForeignSavePpmTarget (ppmsave_target), save to ppm (.ppm, .pgm, .pbm, .pfm), priority=0, rgb
VipsForeignSaveRadTarget (radsave_target), save image to Radiance target (.hdr), priority=0, rgb
VipsForeignSavePngTarget (pngsave_target), save image to target as PNG (.png), priority=0, rgba
VipsForeignSaveJpegTarget (jpegsave_target), save image to jpeg target (.jpg, .jpeg, .jpe), priority=0, rgb-cmyk
VipsForeignSaveWebpTarget (webpsave_target), save image to webp target (.webp), priority=0, rgba-only
VipsForeignSaveHeifTarget (heifsave_target), save image in HEIF format (.heic, .heif, .avif), priority=0, rgba-only
.v
和.raw
可能添加在8.11中。.bmp
是由imagemagick而不是libvips编写的,可能无法实现。
另一种选择是使用类似于Python接口比维普斯的东西,而不是使用CLI。例如:
import os
import pyvips
image = pyvips.Image.black(10, 10)
memory = image.write_to_memory()
os.write(1, memory)
将原始字节(在本例中为100个零)以二进制模式写入stdout。
要使用BMP,您可以编写:
memory = image.magicksave_buffer(format="BMP")
https://stackoverflow.com/questions/65028952
复制相似问题