]>
Dogcows Code - chaz/yoink/blob - scripts/textureattr.pl
4 # A wrapper around pngcrush to read and write the texture attributes of a
5 # Yoink texture in PNG format.
8 my $infile = shift or die "Missing argument";
11 if ($infile eq "-h" or $infile eq "--help") {
13 Edit the texture attributes of a Yoink texture file.
14 Usage: texture_edit.pl infile.png [outfile.png]
15 If outfile.png is not specified, infile.png will be written
22 my $key = "X-Yoink-Texture";
27 # Handle file contents as a whole, not line-by-line.
30 # Read in the image file for the first time.
31 open FILE
, $infile or die $!;
35 # See if we can't determine what the text currently is.
37 if ($bytes =~ m/(.{4})tEXt$key(\0)/g)
39 my $offset = pos($bytes);
40 my $size = unpack("N", $1) - (length($key) + 1);
41 $text = substr($bytes, $offset, $size);
44 # Write that text to a temporary file.
45 $tmpfile = new File
::Temp
(UNLINK
=> 1);
48 # Allow the user a chance to edit the text.
49 system("\${EDITOR:-vi} $tmpfile");
50 (0 == $? >> 8) or die "Editor exited with an error";
52 # Reread the text from the temporary file.
56 # Use pngcrush to rewrite the image file with the new text.
57 system("pngcrush", "-fix", "-oldtimestamp", "-rem", "text", "-text", "b",
58 $key, $text, $infile, $tmpfile);
60 not $outfile and $outfile = $infile;
62 copy
($tmpfile, $outfile) or die $!;
64 die "pngcrush exited with an error";
This page took 0.038254 seconds and 5 git commands to generate.