dbb942f70c719dcd24942165cdf3b9a9005219b1
[pear] / File / Convert / Solution / convert.php
1 <?php
2  
3 class File_Convert_Solution_convert  extends File_Convert_Solution
4 {
5     
6    
7     static $rules = array(
8         array(
9          
10             'from' =>    array( //source
11                  'image/jpeg',
12                 'image/gif',
13                 'image/png'
14             ),
15             'to' =>    array( //target
16                 'image/jpeg',
17                 'image/gif',
18                 'image/png',
19                 'image/x-ms-bmp',
20                 'image/tiff',
21             )
22         ),
23         
24    
25     );
26     function convert($fn,$x,$y,$pg) // image only..
27     {
28         
29         $frame = '';
30         $ext = $this->ext;
31         $target = $fn . '.' . $ext;
32         
33         $this->debug("COVERT: FE:" . (file_exists($target) ? 1: 0) );
34         $this->debug("COVERT: FS:" . (file_exists($target) ?  (filemtime($target) . '>' .  filemtime($fn)) : 'n/a'));
35         
36         if (file_exists($target)  && filesize($target) && filemtime($target) > filemtime($fn)) {
37             return $target;
38         }
39         $flat = '';
40         $targetName = $target;
41         if ($this->to == 'image/jpeg' && $this->from != 'image/gif') {
42             $flat = " -background '#ffffff' --flatten ";
43         }
44         $strip = '-strip';
45         if ($this->to == 'image/x-ms-bmp') {
46             $targetName = "bmp3:$target";
47             $strip = '';
48         }
49         if ($this->from == 'image/gif') {
50             $frame = '[0]';
51         }
52         
53         require_once 'System.php';
54         $CONVERT = System::which("convert");
55         $cmd = "$CONVERT " . $strip .  "  -colorspace sRGB -interlace none -density 800 $flat ". 
56                         "-quality 90   ". escapeshellarg($fn . $frame) . " " . escapeshellarg($targetName );
57          $this->debug($cmd);
58         $this->exec($cmd);
59         clearstatcache();
60         $fe = file_exists($target)  && filesize($target) ? $target : false;
61         if (!$fe) {
62             return false;
63         }
64         
65         @chmod($target,fileperms($fn));
66             
67         return $target;
68     }
69 }