sips shows无法呈现目标图像

Dan*_* Lu 6 macos sips

我曾使用sips来调整PNG图像的大小,如下面的命令.

sips -z 768 1024 image.png --out image-resize.png

它运作良好.但是今天我收到了一条错误信息,如下所示

<CGColor 0x7ffb72e05c40> [<CGColorSpace 0x7ffb72e04e70> (kCGColorSpaceDeviceRGB)] ( 0 0 0 1 )
Error: Unable to render destination image
Run Code Online (Sandbox Code Playgroud)

如果有人能提供帮助,我将非常感激.

Igo*_*gor 6

将颜色配置文件值从RGB 16位更改为8位sRGB可以解决此问题。

这可以通过终端中的一个命令来完成:

find . -type f -name '*.png' -print0 | while IFS= read -r -d '' file; do sips --matchTo '/System/Library/ColorSync/Profiles/sRGB Profile.icc' "$file" --out "$file"; done
Run Code Online (Sandbox Code Playgroud)

然后可以通过Sip调整图像大小。对于批量调整大小,请使用以下命令:

mdfind -0 -onlyin . "kMDItemPixelHeight > 600 || kMDItemPixelWidth > 600" | xargs -0 sips -Z 600
Run Code Online (Sandbox Code Playgroud)

最后,此命令用于减小图像文件的大小:

find . -name '*.png' -exec pngquant --skip-if-larger --ext .png --force {} \; -exec xattr -c {} \;
Run Code Online (Sandbox Code Playgroud)