39

I'm looking for an xpm icon to use as a placeholder until I make something better.

Are there any linux command line tools that create blank images of specified dimensions? Like people use touch to create blank text files.

0

3 Answers 3

70

The convert command from ImageMagick can be used:

To create a 32x32 image with a white background:

convert -size 32x32 xc:white empty.jpg

To create a 32x32 image with a transparent background:

convert -size 32x32 xc:transparent empty2.png
4
  • 1
    To specify the DPI setting, use the -density 96 switch. imagemagick.org/script/command-line-options.php?#density
    – colemik
    Mar 18, 2012 at 3:46
  • 5
    Please note that jpg's can't be transparent. So, this command will work, but with an ext other than jpg
    – NoelHunter
    Aug 30, 2016 at 14:56
  • @colemik the -density setting will have no effect when creating blank images
    – Bert
    Feb 19, 2019 at 21:07
  • 2
    Use PNG32:empty.png to get a 32 bit png instead of a 1 bit greyscale png.
    – konrad
    May 1, 2021 at 16:52
7

You can use convert -size 123x456 xc:white x.png. convert is part of ImageMagick.

4

If you do not have ImageMagick installed, you can use a short Perl script:

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

Using Python:

from PIL import Image
img = Image.new('RGB', (32,32), color='white')
img.save('empty.png')
quit()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .