Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
/*************************
3
  Coppermine Photo Gallery
4
  ************************
5
  Copyright (c) 2003-2005 Coppermine Dev Team
6
  v1.1 originaly written by Gregory DEMAR
7
 
8
  This program is free software; you can redistribute it and/or modify
9
  it under the terms of the GNU General Public License as published by
10
  the Free Software Foundation; either version 2 of the License, or
11
  (at your option) any later version.
12
  ********************************************
13
  Coppermine version: 1.3.3
14
  $Source: /cvsroot/coppermine/stable/include/imageObjectIM.class.php,v $
15
  $Revision: 1.4 $
16
  $Author: gaugau $
17
  $Date: 2005/04/19 03:17:11 $
18
**********************************************/
19
 
20
class imageObject{
21
 
22
         // image resource
23
         var $imgRes;
24
         // px
25
         var $height=0;
26
         var $width=0;
27
         // for img height/width tags
28
         var $string;
29
         // output report or error message
30
         var $message;
31
         // file + dir
32
         var $directory;
33
         var $filename;
34
         // output quality, 0 - 100
35
         var $quality;
36
 
37
         //constructor
38
         function imageObject($directory,$filename,$previous=null)
39
        {
40
        $this->directory = $directory;
41
        $this->filename = $filename;
42
        $this->previous = $previous;
43
        $this->truecolor = true;
44
 
45
        if (file_exists($directory.$filename)){
46
                        $this->filesize = round(filesize($directory.$filename)/1000);
47
                        if($this->filesize>0){
48
                                $size = @GetImageSize($directory.$filename);
49
                                // For IM we don't need an Image Resource (work directly on file :)
50
                                if ($size && !$this->imgRes) {
51
                                        $this->imgRes = true;
52
                                }
53
 
54
                                $this->width = $size[0];
55
                                $this->height = $size[1];
56
                                $this->string = $size[3];
57
                                }
58
                        }// if
59
        }// constructor
60
 
61
         function cropImage(&$clipval)
62
         {
63
             global $CONFIG;
64
                                 $cliparray = split(",",$clipval);
65
             $clip_top = $cliparray[0];
66
             $clip_right = $cliparray[1];
67
             $clip_bottom = $cliparray[2];
68
             $clip_left = $cliparray[3];
69
 
70
             $new_w = $clip_right - $clip_left;
71
             $new_h = $clip_bottom - $clip_top;
72
 
73
 
74
             $imgFile = escapeshellarg("$this->directory$this->filename");
75
 
76
 
77
             $output = array();
78
 
79
                                 /*
80
                                * Hack for working with ImageMagick on WIndows even if IM is installed in C:\Program Files.
81
                                * Also the options for -crop should not have space in between them.
82
                                * By Aditya Mooley <aditya@sanisoft.com>
83
                                */
84
                                if (eregi("win",$_ENV['OS'])) {
85
                                    $imgFile = str_replace("'","\"" ,$imgFile );
86
                                         $cmd = "\"".str_replace("\\","/", $CONFIG['impath'])."convert\" -quality {$this->quality} {$CONFIG['im_options']} -crop {$new_w}x{$new_h}+{$clip_left}+{$clip_top} ".str_replace("\\","/" ,$imgFile )." ".str_replace("\\","/" ,$imgFile );
87
                                         exec ("\"$cmd\"", $output, $retval);
88
                                } else {
89
                                    $cmd = "{$CONFIG['impath']}convert -quality {$this->quality} {$CONFIG['im_options']} -crop '{$new_w}x{$new_h} +{$clip_left} +{$clip_top}' $imgFile $imgFile";
90
                                         exec ($cmd, $output, $retval);
91
                                }
92
                                 //$cmd = "{$CONFIG['impath']}convert -quality {$this->quality} {$CONFIG['im_options']} -crop '{$new_w}x{$new_h} +{$clip_left} +{$clip_top}' $imgFile $imgFile";
93
             //exec ($cmd, $output, $retval);
94
 
95
             //To Do check for errors in execution etc
96
 
97
                 // Call the constructor again to repopulate the dimensions etc
98
             $this->imageObject($this->directory,$this->filename);
99
 
100
             return $this;
101
 
102
         }
103
 
104
         function rotateImage(&$angle){
105
 
106
             global $CONFIG;
107
                                 $imgFile = escapeshellarg("$this->directory$this->filename");
108
 
109
             $output = array();
110
 
111
                                 /*
112
                                * Hack for working with ImageMagick on WIndows even if IM is installed in C:\Program Files.
113
                                * By Aditya Mooley <aditya@sanisoft.com>
114
                                */
115
 
116
                                if (eregi("win",$_ENV['OS'])) {
117
                                    $imgFile = str_replace("'","\"" ,$imgFile );
118
                                         $cmd = "\"".str_replace("\\","/", $CONFIG['impath'])."convert\" -quality {$this->quality} {$CONFIG['im_options']} -rotate $angle ".str_replace("\\","/" ,$imgFile )." ".str_replace("\\","/" ,$imgFile );
119
                                         exec ("\"$cmd\"", $output, $retval);
120
                                } else {
121
                                    $cmd = "{$CONFIG['impath']}convert -quality {$this->quality} {$CONFIG['im_options']} -rotate '$angle' $imgFile $imgFile";
122
                                         exec ($cmd, $output, $retval);
123
                                }
124
             //$cmd = "{$CONFIG['impath']}convert -quality {$this->quality} {$CONFIG['im_options']} -rotate '$angle' $imgFile $imgFile";
125
             //exec ($cmd, $output, $retval);
126
 
127
             //To Do check for errors in execution etc
128
 
129
             // Call the constructor again to repopulate the dimensions etc
130
             $this->imageObject($this->directory,$this->filename);
131
             return $this;
132
 
133
         }
134
 
135
 
136
         function resizeImage($new_w=0,$new_h=0){
137
 
138
             global $CONFIG;
139
                                 $imgFile = escapeshellarg("$this->directory$this->filename");
140
 
141
             $output = array();
142
 
143
                                 /*
144
                                * Hack for working with ImageMagick on WIndows even if IM is installed in C:\Program Files.
145
                                * By Aditya Mooley <aditya@sanisoft.com>
146
                                */
147
                                if (eregi("win",$_ENV['OS'])) {
148
                                    $imgFile = str_replace("'","\"" ,$imgFile );
149
                                         $cmd = "\"".str_replace("\\","/", $CONFIG['impath'])."convert\" -quality {$this->quality} {$CONFIG['im_options']} -geometry {$new_w}x{$new_h} ".str_replace("\\","/" ,$imgFile )." ".str_replace("\\","/" ,$imgFile );
150
                                         exec ("\"$cmd\"", $output, $retval);
151
                                } else {
152
                                    $cmd = "{$CONFIG['impath']}convert -quality {$this->quality} {$CONFIG['im_options']} -geometry '{$new_w}x{$new_h}' $imgFile $imgFile";
153
                                         exec ($cmd, $output, $retval);
154
                                }
155
 
156
            //$cmd = "{$CONFIG['impath']}convert -quality {$this->quality} {$CONFIG['im_options']} -geometry '{$new_w}x{$new_h}' $imgFile $imgFile";
157
            //exec ($cmd, $output, $retval);
158
 
159
             //To Do check for errors in execution etc
160
 
161
             // Call the constructor again to repopulate the dimensions etc
162
             $this->imageObject($this->directory,$this->filename);
163
             return $this;
164
 
165
         }
166
 
167
 
168
   }
169
 ?>