Skip to content

Instantly share code, notes, and snippets.

@carlosmcevilly
Created May 15, 2012 19:36
Show Gist options
  • Save carlosmcevilly/2704455 to your computer and use it in GitHub Desktop.
Save carlosmcevilly/2704455 to your computer and use it in GitHub Desktop.
quickly create a blank (white) image of the same size as a reference image passed in on the command line
#!/usr/bin/perl
# requires imagemagick to be installed on the system for 'identify' and 'convert'
use strict;
use warnings;
my $infile = shift;
my $color = shift;
die "usage: $0 <infile> [<color>, e.g. white or \"#abcdef\" (with quotes)]\n\n" unless (defined($infile));
$color = "white" unless defined($color);
my $identify_output = `identify $infile`;
if ($identify_output =~ m{^(.*?)\.(png|jpe?g|gif)(?:\[\d+\])?\s+(?:png|jpe?g|gif)\s+(\d+)x(\d+)\D}i) {
my ($fileroot,$fileext,$x,$y) = ($1,$2,$3,$4);
my $outfile = "$fileroot-blank.$fileext";
die "error: will not overwrite existing file [$outfile]\n\n" if ( -e "$outfile");
`convert -size ${x}x$y xc:$color -geometry ${x}x$y $outfile`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment