|
1 | 1 | <?php |
2 | 2 |
|
| 3 | + $debug = false; |
| 4 | + |
3 | 5 | //config file |
4 | 6 | require_once('config.php'); |
5 | 7 |
|
|
89 | 91 | fclose($file); |
90 | 92 | } |
91 | 93 |
|
92 | | - //check image properties for mime type |
93 | | - $props = getimagesize($local_input); |
94 | | - //if mime type is image, process it |
95 | | - if(strpos($props['mime'], 'image')!== false && strpos($props['mime'], 'image') >= 0){ |
| 94 | + /* |
| 95 | + $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension |
| 96 | + finfo_file($finfo, $filename) |
| 97 | + finfo_close($finfo) |
| 98 | + */ |
| 99 | + |
| 100 | + $mime = image_type_to_mime_type(exif_imagetype($local_input)); |
| 101 | + if(strpos($mime, 'image')!== false && strpos($mime, 'image') >= 0){ |
96 | 102 |
|
97 | 103 | //only need to calculate this if width is set |
98 | 104 | if($w!="undefined"){ |
|
112 | 118 |
|
113 | 119 | //compare screen width to values in ranges |
114 | 120 | foreach ($ranges as &$range){ |
115 | | - //make sure have all the required values we need - min, max, and per or px |
116 | | - //don't need pixel measurements here cause would need exact dimensions, not percentage and ranges... |
| 121 | + //make sure have all the required values we need - min, max, and per |
| 122 | + //don't actually need quality since it's not used in Imagick at all... |
117 | 123 | if( ( isset($range["min"]) && is_numeric($range["min"]) ) && ( isset($range["max"]) && ( is_numeric($range["max"]) || $range["max"]=="*") ) && ( isset($range["per"]) && is_numeric($range["per"]) ) ){ |
118 | 124 |
|
119 | 125 | //check in case max is set to "all" |
|
146 | 152 | //check to see if resized image exists |
147 | 153 | if (!file_exists($local_output)) { |
148 | 154 |
|
149 | | - /* |
150 | | - //if quality is set in ranges |
151 | | - if(isset($range["quality"])){ |
152 | | - //check if quality is below max |
153 | | - if($range["quality"]<$max_quality){ |
154 | | - $quality = $range["quality"]; |
155 | | - } else { |
156 | | - $quality = $max_quality; |
157 | | - } |
158 | | - } |
159 | | - */ |
160 | | - |
161 | 155 | //output resized image |
162 | 156 | //FILTER_CATROM |
163 | 157 | //FILTER_LANCZOS |
164 | | - //$image->resizeImage(, ,Imagick::FILTER_CATROM,1); |
165 | | - |
166 | | - //calc width, in case passing 0 is causing the errors |
167 | | - $final_height = round( $image->getImageHeight() * ($final_width/$img_width) ); |
168 | | - |
169 | | - try { |
170 | | - $image->scaleImage($final_width,$final_height,true); |
171 | | - $image->writeImage($local_output); |
172 | | - $image->clear(); |
173 | | - $image->destroy(); |
174 | | - } catch(Exception $e){ |
175 | | - echo 'Caught exception: ', $e->getMessage(), "\n"; |
176 | | - } |
177 | | - |
178 | | - //output resized file |
179 | | - //system("convert $local_input -strip -quality $quality -resize $final_width $local_output"); |
180 | | - |
181 | | - //error code to check if get error status message from convert call |
182 | | - //uncomment if need to see results |
183 | | - /* |
184 | | - $retval = ""; |
185 | | - system("convert $local_input -strip -quality $quality -resize $final_width $local_output", $retval); |
186 | | - |
187 | | - if($retval>0){ |
188 | | - $log = "[" . date('y m d H:i:s') . "]\n"; |
189 | | - $log .= $filename . "\n"; |
190 | | - $log .= "convert $local_input -strip -quality $quality -resize $final_width $local_output \n"; |
191 | | - //$log .= "output: ". print_r($output, true) . "\n"; |
192 | | - //$log .= "result: ". print_r($result, true) . "\n"; |
193 | | - //$log .= "system: ". $system . "\n"; |
194 | | - $log .= "retval: ". $retval . "\n"; |
195 | | - $log .= "----\n"; |
196 | | - $fp = fopen('error.log', 'at'); |
197 | | - fwrite($fp, $log); |
198 | | - fclose($fp); |
| 158 | + //$image->resizeImage(, ,Imagick::FILTER_CATROM,1); |
| 159 | + |
| 160 | + //calc width, in case passing 0 is causing the errors |
| 161 | + $final_height = round( $image->getImageHeight() * ($final_width/$img_width) ); |
| 162 | + |
| 163 | + try { |
| 164 | + $image->scaleImage($final_width,$final_height,true); |
| 165 | + $image->writeImage($local_output); |
| 166 | + $image->clear(); |
| 167 | + $image->destroy(); |
| 168 | + } catch(Exception $e){ |
| 169 | + echo 'Caught exception: ', $e->getMessage(), "\n"; |
199 | 170 | } |
200 | | - */ |
| 171 | + |
201 | 172 | } |
202 | 173 |
|
203 | 174 | //send new header for resized image |
|
208 | 179 |
|
209 | 180 | } else { |
210 | 181 | //if missing any required paramters output a blank image |
211 | | - showMt(); |
| 182 | + showMt("missing required parameters"); |
212 | 183 | } |
213 | 184 | } //end foreach |
214 | 185 |
|
|
221 | 192 | } |
222 | 193 | } else { |
223 | 194 | //end if, if mime type is not image |
224 | | - showMt(); |
| 195 | + showMt("incorrect mime type"); |
225 | 196 | } |
226 | 197 |
|
227 | 198 | //if domain is in whitelist, break out of foreach |
|
248 | 219 |
|
249 | 220 | //final check, if remote domain is not in whitelist |
250 | 221 | if ($c>count($whitelist)) { |
251 | | - showMt(); |
| 222 | + showMt("domain not in whitelist"); |
252 | 223 | } |
253 | 224 |
|
254 | 225 | } else { |
255 | 226 | //end if, if src is not in query |
256 | 227 | //this will basically never happen currently cause htaccess does not pass through if not a proper image extension |
257 | | - showMt(); |
| 228 | + showMt("src not in query"); |
258 | 229 | } |
259 | 230 |
|
260 | 231 | } //end request uri check |
261 | 232 |
|
262 | | - function showMt(){ |
| 233 | + function showMt($e){ |
263 | 234 | //output blank gif for cases where no there is no image |
264 | | - header('Content-type: image/gif'); |
265 | | - readfile($GLOBALS["mt"]); |
266 | | - exit; |
| 235 | + if($debug){ |
| 236 | + header('Content-type: image/gif'); |
| 237 | + readfile($GLOBALS["mt"]); |
| 238 | + exit; |
| 239 | + } else { |
| 240 | + echo $e."<br />"; |
| 241 | + } |
267 | 242 | } |
268 | 243 |
|
269 | 244 | ?> |
0 commit comments