Skip to content

Instantly share code, notes, and snippets.

@bortels
Created October 29, 2011 22:43
Show Gist options
  • Save bortels/1325189 to your computer and use it in GitHub Desktop.
Save bortels/1325189 to your computer and use it in GitHub Desktop.
Use ImageMagick to convert PNG background to transparent alpha
#!/usr/bin/perl
$img = shift @ARGV;
$corner = `convert $img -format '%[pixel:s.p{0,0}]' info:`;
chomp $corner;
print "corner color is $corner\n";
@r = split(/\./, $img);
$ext = pop @r;
$name = join('.', @r); $name = $name . "_new." . $ext;
print "Saving to $name\n";
system("convert $img -alpha set -channel RGBA -fuzz 1% -fill none -floodfill +0+0 $corner $name");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment