Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

image.inc.php

Go to the documentation of this file.
00001 <?php
00011 class Img
00012 {
00020     public static function rotate($inputFile, $outputFile, $degrees)
00021     {
00022         //error checking.
00023         if (!is_numeric($degrees))
00024             throw new Exception("Img::rotate - invalid degrees: $degrees");
00025 
00026         //setup our call.
00027         $inputFile = escapeshellarg($inputFile);
00028         $outputFile = escapeshellarg($outputFile);
00029         $call = "/usr/bin/convert -rotate $degrees $inputFile $outputFile";
00030         
00031         //do it!
00032         Util::shellExec($call);
00033     }
00034 
00042     public static function flip($inputFile, $outputFile, $type)
00043     {
00044         if ($type == "horizontal")
00045             $arg = "flop";
00046         else if ($type == "vertical")
00047             $arg = "flip";
00048         else
00049             throw new Exception("imageFlip: invalid type: $type");
00050 
00051         //setup our call.
00052         $inputFile = escapeshellarg($inputFile);
00053         $outputFile = escapeshellarg($outputFile);
00054         $call = "/usr/bin/convert -$arg $inputFile $outputFile";
00055 
00056         //do it!
00057         Util::shellExec($call);
00058     }
00059 
00068     public static function resize($inputFile, $outputFile, $maxDimension, $execute = true)
00069     {
00070         if (preg_match("/\d*:\d*/", $maxDimension))
00071         {
00072             list ($maxX, $maxY) = explode(':', $maxDimension);
00073         }
00074         else
00075         {
00076             $maxX = $maxY = $maxDimension;
00077         }
00078 
00079         if (!is_numeric($maxX) || !is_numeric($maxY))
00080             throw new Exception("imageResize: invalid maximum dimension: $maxDimension");
00081 
00082         //setup our call.
00083         $inputFile = escapeshellarg($inputFile);
00084         $outputFile = escapeshellarg($outputFile);
00085         $call = "/usr/bin/convert -size ${maxX}x${maxY} $inputFile -resize '${maxX}x${maxY}>' +profile \"*\" $outputFile";
00086 
00087         //do it!
00088         if ($execute)
00089             Util::shellExec($call);
00090         else
00091             echo "$call;\n";
00092     }
00093 
00101     public static function crop($inputFile, $outputFile, $dimensions)
00102     {
00103         $inputFile = escapeshellarg($inputFile);
00104         $outputFile = escapeshellarg($outputFile);
00105         $call = "/usr/bin/convert -crop $dimensions $inputFile +profile \"*\" $outputFile";
00106         
00107         Util::shellExec($call);
00108     }
00109 
00119     public static function convert($inputFile, $outputFile, $flags = "")
00120     {
00121         $inputFile = escapeshellarg($inputFile);
00122         $outputFile = escapeshellarg($outputFile);
00123         $call = "/usr/bin/convert $flags $inputFile $outputFile";
00124         
00125         Util::shellExec($call);
00126     }
00127 
00140     public static function scale($inputFile, $outputFile, $width = null, $height = null, $force = false)
00141     {
00142         $inputFile = escapeshellarg($inputFile);
00143         $outputFile = escapeshellarg($outputFile);
00144         if ($force)
00145             $force = "!";
00146         else
00147             $force = "";
00148 
00149         if ($width && !$height)
00150             $call = "/usr/bin/convert -geometry ${width}$force $inputFile $outputFile";
00151         else if ($height && !$width)
00152             $call = "/usr/bin/convert -geometry x${height}$force $inputFile $outputFile";
00153         else if ($height && $width)
00154             $call = "/usr/bin/convert -geometry ${width}x${height}$force $inputFile $outputFile";
00155         else
00156             return false;
00157         Util::shellExec($call);
00158 
00159         return true;
00160     }
00161 }
00162 ?>

Generated on Fri Oct 27 12:26:40 2006 for BaseJumper by doxygen 1.3.9.1