Ser*_*nyy 31 command-line image-processing convert-command
我想做的很简单。我有一个file.png,我想镜像它,即结果应该是原始图像的“反射”。
我知道像 GIMP 和 InkScape 这样的大工具可以做到这一点,但我希望有一个命令行实用程序,比如convert(遗憾的是它似乎没有这样的选项,或者至少man页面中没有提到它)。
Ser*_*nyy 48
从快速阅读this,显然为水平镜像和垂直镜像convert调用此选项。我需要做的就是-flop-flip
convert -flop input.png output.png
Run Code Online (Sandbox Code Playgroud)
小智 9
如果您想就地覆盖并且同一文件夹中有大量图像文件,mogrify则 ImageMagick 套件似乎是实现此目的的最简单方法:
# mirror in the vertical axis:
mogrify -flip *.jpg
# mirror in the horizontal axis:
mogrify -flop *.jpg
Run Code Online (Sandbox Code Playgroud)
对于这个特定的任务convert可能是最好的方法,但对于这种事情我经常使用该netpbm库,它可以通过apt install netpbm. 然后
pngtopnm input.png | pnmflip -lr \
| (other transformations if desired) \
| pnmtopng > output.png
Run Code Online (Sandbox Code Playgroud)
对于这项任务来说,这是大材小用,但我经常发现自己编写一次性脚本来以convert. 这相对容易,因为 PNM 几乎是可以想象到的最简单的位图图形格式。