converting tiff files to jpg from php
I am trying to convert a folder of tif files to jpeg so they can be displayed on my website. my current approach is not working. i wrote a perl script with
#!/usr/bin/perl
opendir(DIR, $ARGV[0]);
@files = readdir(DIR);
closedir(DIR);
foreach $file (@files){
if($file =~ /(.*?)\.tif/){
print 开发者_JS百科"converting $file\n";
`convert -auto-level -depth 12 -type grayscale $ARGV[0]$file $ARGV[1]$1.jpg`;
}
}
But this never enters the for loop because the opendir fails. The folder does exist.
i am calling this by exec("perl test.pl arg1 arg2"); in php
Is this how i should be doing this because it isn't working?
Also i gave pretty much everything that needs to be accessed or written to chmod 777
thanks
First of all, you should always have these two lines in every script and module:
use strict;
use warnings;
These lines will give you many errors and clues that will tell you what you're missing.
Second, you need to check the return value of the opendir
command, as it does return an error if it failed to open the directory (for example if it didn't exist). The $!
variable contains the most recent error message. If you print the exact filename in the error message that you tried to open, you can see if your file specification is incorrect:
opendir (my $dir, $ARGV[0]) or die "Cannot open $ARGV[0]: $!";
my @files = readdir($dir);
closedir($dir);
If your directory specification is relative, and you are in the wrong directory, you can change directories with chdir.
The specifications for the opendir command are in perldoc -f opendir. You can read about special variables in perldoc perlvar.
精彩评论