脚本将画布大小裁剪为透明png文件中的可见图像大小

时间:2021-07-04 07:11:11

I have a collection of transparent .png files. They are all a standard canvas size of 220x132 but the image might only be for example 150x40 with the rest of the image being transparent background..

我有一组透明的.png文件。它们都是220x132的标准画布尺寸,但图像可能仅为150x40,其余图像为透明背景。

Is there a way to crop the canvas size to the actual visible image area using linux script?

有没有办法使用linux脚本将画布大小裁剪到实际的可见图像区域?

1 个解决方案

#1


1  

ImageMagick is a powerful framework for doing all kinds of image editing from the command line. Cropping is a part of it.

ImageMagick是一个功能强大的框架,用于从命令行执行各种图像编辑。裁剪是其中的一部分。

See the documentation here: http://www.imagemagick.org/Usage/crop/ Of special interest for you might be the trim command: http://www.imagemagick.org/Usage/crop/#trim

请参阅此处的文档:http://www.imagemagick.org/Usage/crop/特别感兴趣的可能是trim命令:http://www.imagemagick.org/Usage/crop/#trim

However, it might very well be, that a simple repage does the job. This depends on how your PNG image is built: PNGs can contain layer boundary information. trim will be perfectly fine for you, but repage might be faster when dealing with a huge amount of images.

然而,很可能,一个简单的重新制作完成了这项工作。这取决于PNG图像的构建方式:PNG可以包含图层边界信息。修剪对你来说非常好,但是在处理大量图像时,重新制作可能会更快。

When ImageMagick is installed, try these commands: identify, display, convert, mogrify on your images.

安装ImageMagick时,请尝试以下命令:识别,显示,转换,mogrify对您的图像。

#1


1  

ImageMagick is a powerful framework for doing all kinds of image editing from the command line. Cropping is a part of it.

ImageMagick是一个功能强大的框架,用于从命令行执行各种图像编辑。裁剪是其中的一部分。

See the documentation here: http://www.imagemagick.org/Usage/crop/ Of special interest for you might be the trim command: http://www.imagemagick.org/Usage/crop/#trim

请参阅此处的文档:http://www.imagemagick.org/Usage/crop/特别感兴趣的可能是trim命令:http://www.imagemagick.org/Usage/crop/#trim

However, it might very well be, that a simple repage does the job. This depends on how your PNG image is built: PNGs can contain layer boundary information. trim will be perfectly fine for you, but repage might be faster when dealing with a huge amount of images.

然而,很可能,一个简单的重新制作完成了这项工作。这取决于PNG图像的构建方式:PNG可以包含图层边界信息。修剪对你来说非常好,但是在处理大量图像时,重新制作可能会更快。

When ImageMagick is installed, try these commands: identify, display, convert, mogrify on your images.

安装ImageMagick时,请尝试以下命令:识别,显示,转换,mogrify对您的图像。