是否有创建空白图像的实用程序?


20

我正在寻找一个xpm图标用作占位符,直到变得更好为止。

是否有任何Linux命令行工具可以创建指定尺寸的空白图像?就像人们touch用来创建空白文本文件一样。

Answers:


41

可以使用ImageMagickconvert命令:

要创建带有白色背景的32x32图像:

convert -size 32x32 xc:white empty.jpg

要创建具有透明背景的32x32图像:

convert -size 32x32 xc:transparent empty2.png

1
要指定DPI设置,请使用-density 96开关。imagemagick.org/script/command-line-options.php?#density
colemik 2012年

4
请注意,jpg不能透明。因此,此命令将起作用,但除jpg以外的其他
扩展程序

@colemik该-density设置在创建空白图像时将不起作用
Bert

7

您可以使用convert -size 123x456 xc:white x.pngconvert是ImageMagick的一部分。


1

如果未安装ImageMagick,则可以使用简短的Perl脚本:

use GD::Simple;
my $i = GD::Simple->new(32,32);
open my $out, '>', 'empty.png' or die;
binmode $out;
print $out $i->png;

使用Python:

from PIL import Image
img = Image.new('RGB', (32,32), color='white')
img.save('empty.png')
quit()
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.