Blog

Ingresar:     


Perl script for resizing VDJ skins v1.0

Wed 01 Jun 05 @ 10:55 pm

#!perl
#
#Script for resizing skin defining XML files for VirtualDJ
# by frd1963

$V = 0;
$XML = $ARGV[0];
$WIDTH = $ARGV[1];
$HEIGHT = $ARGV[2];

die "Must specify a valid xml file!" unless (-e "$XML");
open(INFILE,"$XML") || die "Can't open '$XML' : $!";
my @in = ;
close(INFILE);

# Get original height and width
$height = $in[0];
$width = $in[0];
chomp($width);
chomp($height);
print("Using header line '$width'\n") if $V;
$height =~ s/^.*\sheight=\"(\d+)\".*/\1/i;
$width =~ s/^.*\swidth=\"(\d+)\".*/\1/i;

#prompt for new dimensions if not defined or invalid
while ($HEIGHT !~ /^\d+$/ || $WIDTH !~ /^\d+$/) {
     print("Old width = $width     Enter new width : ");
     $WIDTH = ;
     chomp($WIDTH);
     print("Old height = $height     Enter new height: ");
     $HEIGHT = ;
     chomp($HEIGHT);
}

#calculate conversion ratios
my $ratioX = ($WIDTH / $width);
my $ratioY = ($HEIGHT / $height);
print("Width ratio =     $ratioX\nHeight ratio =     $ratioY\n") if $V;

# Convert the sizes, positions and widths
# iterating through each line
$size = @in;
for(my $i = 0; $i $newName") || die "Can't open '$newName' : $!";
foreach $line (@in) {
     print OUTFILE ("$line\n");
}
close(OUTFILE);

$ratioX *= 100;
$ratioY *= 100;
$bmp = $XML;
$bmp =~ s/.xml$/.bmp/i;
$newBmp = "$bmp" . "${HEIGHT}x${WIDTH}" . "bmp";
$bmp = "$bmp" . ".bmp";
print("Now don't forget to make '$newBMP' by stretching '$bmp':\n\tstretch width by '$ratioX%'\n\tstretch height by '$ratioY%'\n");

exit;

sub Convert {
     my $string = shift(@_);
     my $r = shift(@_);
     my @list = @_;

     my $newString = $string;

     foreach my $tag (@list) {
          my $value = $newString;
          $value =~ s/^.*$tag=\"(\d+)\".*/\1/i;
          next if ($value eq "" || $value eq $newString);
          print("Scaling for tag '$tag': '$value' becomes ");
          $value *= $r;
          $value = int($value + .5);
          print("'$value'\n");
          $newString =~ s/^(.*$tag=\")\d+(\".*)/\1$value\2/i;
     }
     return "$newString";
}