Special Ops 2.50
[specialops2.git] / css / img / img-encode.pl
blobb77b92d612194b33fb1fac46e169ad20be22b45c
1 #!/usr/bin/perl
2 # Takes image filename, outputs file contents in format for css background
3 # (Public Domain) / Ant P. / 2007-02-01
4 use strict;
5 use warnings;
6 use URI::data;
8 foreach (@ARGV) {
9 print &file_to_data($_)."\n\n" if ( -r );
12 sub file_to_data {
13 my $file = shift;
14 (my $type = `file -bi $file`) =~ s/\s//g;
15 my $dat = URI->new('data:');
17 print "========== $file\n";
18 if ( $type eq 'image/png' ) {
19 print `optipng -i0 $file`;
20 } else {
21 print "Not preprocessing filetype $type\n";
24 $dat->media_type($type);
25 $dat->data(scalar(`cat $file`));
27 return $dat;