#!@PHP@ -q Path to picture file # $2->Path to resulting thumbnail # $3->largest size (in pixels) # # OUTPUT: thumbnail file at $2 # ######################################################## $DJPEG="@DJPEG@"; $CONVERT="@CONVERT@"; $GIFTEXT="@GIFTEXT@"; $JPEGSIZE="@JPEGSIZE@"; $PNMSCALE="@PNMSCALE@"; $PPMQUANT="@PPMQUANT@"; $PPMTOGIF="@PPMTOGIF@"; $GIFINTER="@GIFINTER@"; $GIFRSIZE="@GIFRSIZE@"; foreach($argv as $value) { if ($value == "-V" || $value == "--version") { print $__version__."\n"; exit(); } if ($value == "-h" || $value == "--help") { print "usage : thumbmaker " . "\n"; exit(); } } if ($DJPEG == "") { print "\nthumbmaker: Cannot find djpeg\n"; exit; } if ($CONVERT == "") { print "\nthumbmaker: Cannot find convert\n"; exit; } if ($GIFTEXT == "") { print "\nthumbmaker: Cannot find giftext\n"; exit; } if ($JPEGSIZE == "") { print "\nthumbmaker: Cannot find jpegsize\n"; exit; } if ($PNMSCALE == "") { print "\nthumbmaker: Cannot find pnmscale\n"; exit; } if ($PPMQUANT == "") { print "\nthumbmaker: Cannot find ppmquant\n"; exit; } if ($PPMTOGIF == "") { print "\nthumbmaker: Cannot find ppmtogif\n"; exit; } if ($GIFINTER == "") { print "\nthumbmaker: Cannot find gifinter\n"; exit; } if ($GIFRSIZE == "") { print "\nthumbmaker: Cannot find gifrsize\n"; exit; } if ( count($argv) != 4 ) { print "usage : thumbmaker " . "\n"; exit; } else { $picture=$argv[1]; $thumbnail=$argv[2]; $maxsize=$argv[3]; } ####################################################### # # Main script # ####################################################### #get extension $extension = ereg_replace(".*\.","",$picture); $ext = strtolower($extension); if ($ext != "gif" && $ext != "jpeg" && $ext != "jpg" && $ext != "pdf" && $ext != "ps" ) { print "$0: works only with GIF, PDF, PS or JPEG formats!!!\n"; exit; } if ( $ext == "pdf" ) { $newname = str_replace(".pdf",".gif",$picture); $isPDF = TRUE; system("$CONVERT pdf:$picture gif:$newname"); $picture = $newname; $ext = "gif"; } elseif ( $ext == "ps" ) { $newname = str_replace(".ps",".gif",$picture); $isPDF = TRUE; system("$CONVERT ps:$picture gif:$newname"); $picture = $newname; $ext = "gif"; } else $isPDF = FALSE; #get picture size if ($ext == "gif") { $imagesize=`$GIFTEXT $picture | grep "Image Size"`; $imagesize = ereg_replace("\n.*","",$imagesize); $width = ereg_replace(".*Width = ","",$imagesize); $width = ereg_replace(" Height.*","",$width); $height = ereg_replace(".*Height = ","",$imagesize); $height = ereg_replace("\..*","",$height); } else { $imagesize=`$JPEGSIZE $picture`; $width = ereg_replace(" .*","",$imagesize); chop($width); $height = ereg_replace(".* ","",$imagesize); chop($height); } #process scale factor if ( $width > $height ) $originalmaxsize = $width; else $originalmaxsize = $height; $scale = $maxsize/$originalmaxsize; #create gif picture if jpeg + transform interlaced gif $basename = ereg_replace("\.$extension","",$picture); if ( $ext == "jpg" || $ext == "jpeg" ) system("$DJPEG $picture | $PNMSCALE" . " $scale | $PPMQUANT 256 | " . "$PPMTOGIF > $thumbnail"); else { system("$GIFINTER $picture > ${basename}_TMfinal.gif"); #create final thumbnail system("$GIFRSIZE -s $scale ${basename}_TMfinal.gif " . "> $thumbnail"); system("rm -r ${basename}_TMfinal.gif"); } if ($isPDF == TRUE) system("rm $picture"); ?>