#!/usr/bin/env perl # # A wrapper around pngcrush to read and write the texture attributes of a # Yoink texture in PNG format. # my $infile = shift or die "Missing argument"; my $outfile = shift; if ($infile eq "-h" or $infile eq "--help") { print <; close(FILE); # See if we can't determine what the text currently is. my $text = ""; if ($bytes =~ m/(.{4})tEXt$key(\0)/g) { my $offset = pos($bytes); my $size = unpack("N", $1) - (length($key) + 1); $text = substr($bytes, $offset, $size); } # Write that text to a temporary file. $tmpfile = new File::Temp(UNLINK => 1); print $tmpfile $text; # Allow the user a chance to edit the text. system("\${EDITOR:-vi} $tmpfile"); (0 == $? >> 8) or die "Editor exited with an error"; # Reread the text from the temporary file. seek $tmpfile, 0, 0; $text = <$tmpfile>; # Use pngcrush to rewrite the image file with the new text. system("pngcrush", "-fix", "-oldtimestamp", "-rem", "text", "-text", "b", $key, $text, $infile, $tmpfile); if (0 == $? >> 8) { not $outfile and $outfile = $infile; seek $tmpfile, 0, 0; copy($tmpfile, $outfile) or die $!; } else { die "pngcrush exited with an error"; }