Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpbimagefile.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezimagefile.php 6304 2001-07-29 23:31:17Z kaid $
5 //
6 // Definition of eZPBImageFile class
7 //
8 // Created on: <21-Sep-2000 11:22:21 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
67 //include_once( "kernel/classes/ezfile.php" );
68
69
70 class eZPBImageFile extends eZPBFile
71 {
75 function __construct()
76 {
77
78 }
79
85 function isImage()
86 {
87 if ( preg_match( "/image/", $this->FileType ) )
88 {
89 $ret = true;
90 }
91 else
92 {
93 $ret = false;
94 }
95
96 return $ret;
97 }
98
108 static public function &information( $file, $use_default = false )
109 {
110 $ret = array();
111 if ( preg_match( '/\.([a-zA-Z]+)$/', $file, $regs ) )
112 {
113 // We got a suffix, make it lowercase and store it
114 $suffix = strtolower( $regs[1] );
115 }
116 else
117 {
118 // If we don't have a suffix, we assume it's not supported
119 $suffix = "";
120 }
121 // List of supported suffixes
122 $suffix_list = array( "jpg" => array( ".jpg", "image/jpeg" ),
123 "jpeg" => array( ".jpg", "image/jpeg" ),
124 "gif" => array( ".gif", "image/gif" ),
125 "png" => array( ".png", "image/png" ) );
126
127 if( isset( $suffix_list[$suffix] ) )
128 {
129 $postfix = $suffix_list[$suffix];
130 $ret["suffix"] = $suffix;
131 $ret["dot-suffix"] = $postfix[0];
132 $ret["image-type"] = $postfix[1];
133 $ret["supported"] = is_array( $postfix );
134 }
135 else {
136 // If we don't have a suffix, we assume it's not supported
137 $ret["suffix"] = $suffix;
138 $ret["dot-suffix"] = "";
139 $ret["image-type"] = "";
140 $ret["supported"] = false;
141 }
142 if ( isset( $ret["supported"] ) and !$ret["supported"] and $use_default )
143 return eZPBImageFile::defaultInformation();
144 return $ret;
145 }
146
152 static public function &defaultInformation()
153 {
154 $ret = array( "suffix" => "jpg",
155 "dot-suffix" => ".jpg",
156 "image-type" => "image/jpeg",
157 "supported" => false );
158 return $ret;
159 }
168 function scaleCopy( $dest, $width, $height, $convertToGray = false, $aspectScale=true )
169 {
170 $ret = false;
171 $lock_file = $dest . ".lock";
172
173 if ( file_exists( $lock_file ) )
174 {
175 // If image file is locked we need to wait until it's finished
176 $i = 0;
177 while( file_exists( $lock_file ) and $i < 5*5 ) // Wait max 5 seconds
178 {
179 usleep( 200000 ); // Sleep 1/5 of a second
180 clearstatcache();
181 $i++;
182 }
183 return "locked";
184 }
185 touch( $lock_file );
186 $ini =& eZINI::instance( 'site.ini' );
187 $image_prog = "convert";
188 if ( $ini->hasVariable( "classes", "ImageConversionProgram" ) )
189 $image_prog = $ini->variable( "classes", "ImageConversionProgram" );
190 $grayCode = "";
191 if ( $convertToGray == true )
192 $grayCode = " -colorspace GRAY ";
193 $execstr = "$image_prog -colorspace Transparent $grayCode -geometry \"$width" . "x" . "$height" . ">\" " . $this->TmpFileName . " " . $dest;
194 // print( "<br><b>$execstr</b><br>" );
195
196 $err = system( $execstr, $ret_code );
197
198 if ( $ret_code == 0 )
199 {
200 @eZPBFile::chmod( $dest, 0644 );
201 $ret = true;
202 }
203 else
204 {
205 $ret = false;
206 }
207
208 // Watermark Code added by Brian Ducharme - www.brianducharme.com
209 // - modified for image watermarks by Dylan McDiarmid
210 $watermarkCodeTL = "";
211 $watermarkCodeBR = "";
212 $watermark_enabled = "false";
213 $watermark_width = "200";
214 $watermark_height = "200";
215 $watermark_position = "south";
216 // $watermark_image = "ttwater.gif";
217
218 if ( $ini->hasVariable( "watermark", "watermarkEnabled" ) )
219 $watermark_enabled = $ini->variable( "watermark", "watermarkEnabled" );
220
221
222 if ( $ini->hasVariable( "watermark", "watermarkImage" ) )
223 $watermark_image = $ini->variable( "watermark", "watermarkImage" );
224 if ( $ini->hasVariable( "watermark", "watermarkImageBr" ) )
225 $watermark_image_br = $ini->variable( "watermark", "watermarkImageBr" );
226 if ( $ini->hasVariable( "watermark", "watermarkImageBrSmall" ) )
227 $watermark_image_br_small = $ini->variable( "watermark", "watermarkImageBrSmall" );
228
229 if ( $watermark_enabled == "true" )
230 {
231 if ( $ini->hasVariable( "watermark", "minWidth" ) )
232 $watermark_width = $ini->variable( "watermark", "minWidth" );
233 if ( $ini->hasVariable( "watermark", "minHeight" ) )
234 $watermark_height = $ini->variable( "watermark", "minHeight" );
235 if ( $ini->hasVariable( "watermark", "position" ) )
236 $watermark_position = $ini->variable( "watermark", "position" );
237 {
238 // static for now while we get the scaling thing figured out
239 $actualsize = getimagesize($dest);
240 $actualheight = $actualsize[1];
241 $actualwidth = $actualsize[0];
242
243 if (($width >= 400 | $height >= 400) && ($actualheight >= 400 | $actualwidth >= 400)) {
244 $watermark_image_br = $watermark_image_br;
245 // $watermark_image_br = 'design/tt/images/watermarks/ttwater-br.png';
246 // $watermark_image_br = 'design/tt/images/watermarks/ttwater-br-outline.png';
247 } else {
248 $watermark_image_br = $watermark_image_br_small;
249 // $watermark_image_br = 'design/tt/images/watermarks/ttwater-br-small-outline.png';
250 }
251
252 // some lame error handling
253 if (!is_file($watermark_image_br)) {
254 // ezlog: new eZPBLog
255 eZPBLog::writeNotice( "User Site: Could not locate watermark image file." );
256 echo ('Could not locate watermark image file.');
257 print ('Could not locate watermark image file.');
258 }
259
260 if ( $width >= $watermark_width | $height >= $watermark_height ):
261 // $watermarkCodeTL = "/usr/bin/composite -gravity northwest $watermark_image_tl $dest $dest";
262
263 $watermarkCodeBR = "/usr/bin/composite -gravity southeast $watermark_image_br $dest $dest";
264
265 // $watermarkCode = '';
266 endif;
267
268
269 //$watermarkCode = " composite -compose atop -gravity $watermark_position $watermark_text " . $this->TmpFileName;
270 //$watermarkCode = " -font helvetica -draw 'gravity $watermark_position fill white text 0,20 \"$watermark_text\" fill black text 1,21 \"$watermark_text\"' ";
271 }
272
273 // print('watermark is ' . $watermarkCode . "\n");
274 // $execstr = "$image_prog -colorspace Transparent $grayCode -geometry \"$width" . "x" . "$height" . ">\" $watermarkCode " . $this->TmpFileName . " " . $dest;
275 // die('exec' . $execstr);
276
277 // End of Watermark Code
278
279 if ($watermarkCodeBR != "")
280 {
281 $err_water = system( $watermarkCodeBR, $ret_code_water );
282 if ( $ret_code_water == 0 )
283 {
284 @eZPBFile::chmod( $dest, 0644 );
285 $re2 = true;
286 }
287 else
288 {
289 $ret2 = false;
290 }
291 }
292
293 // Check for animated gif/png
294 if ( file_exists( "$dest" . ".0" ) )
295 {
296 // TODO: not sure
297 // copy( $this->TmpFileName, $dest );
298 eZPBFile::copy( $dest );
299 @eZPBFile::chmod( $dest, 0644 );
300 $i = 0;
301 while( file_exists( "$dest.$i" ) )
302 {
303 eZPBFile::unlink( "$dest.$i" );
304 $i++;
305 }
306 $ret = true;
307 }
308 }
309
310 eZPBFile::unlink( $lock_file );
311
312 if ((isset($ret2) && $ret2 == false) || $ret == false ) return false;
313
314 return true;
315 }
316
320 function convertCopy( $dest )
321 {
322 $ret = false;
323 $ini =& eZINI::instance( 'site.ini' );
324 $image_prog = "convert";
325 if ( $ini->hasVariable( "classes", "ImageConversionProgram" ) )
326 $image_prog = $ini->variable( "classes", "ImageConversionProgram" );
327 $execstr = "$image_prog -colorspace Transparent -quality 95 " . $this->TmpFileName . " " . $dest;
328 // print( "<br><b>$execstr</b><br>" );
329
330 $err = system( $execstr, $ret_code );
331 $ret = true;
332 if ( $ret_code != 0 )
333 {
334 $ret = false;
335 }
336 else
337 @eZPBFile::chmod( $dest, 0644 );
338
339 return $ret;
340 }
341
342 }
343
344 ?>
$i
$i
Definition: admin/adlist.php:91
eZPBFile
Definition: ezpbfile.php:49
eZPBFile\file_exists
static file_exists( $filename)
Definition: ezpbfile.php:267
eZPBFile\chmod
static chmod( $filename, $mode)
Definition: ezpbfile.php:371
eZPBFile\unlink
static unlink( $filename)
Definition: ezpbfile.php:352
eZPBFile\copy
copy( $dest)
Definition: ezpbfile.php:166
eZPBFile\is_file
static is_file( $filename)
Definition: ezpbfile.php:287
eZPBImageFile
Definition: ezpbimagefile.php:71
eZPBImageFile\information
static & information( $file, $use_default=false)
Definition: ezpbimagefile.php:108
eZPBImageFile\defaultInformation
static & defaultInformation()
Definition: ezpbimagefile.php:152
eZPBImageFile\isImage
isImage()
Definition: ezpbimagefile.php:85
eZPBImageFile\__construct
__construct()
Definition: ezpbimagefile.php:75
eZPBImageFile\convertCopy
convertCopy( $dest)
Definition: ezpbimagefile.php:320
eZPBImageFile\scaleCopy
scaleCopy( $dest, $width, $height, $convertToGray=false, $aspectScale=true)
Definition: ezpbimagefile.php:168
eZPBLog\writeNotice
static writeNotice( $notice)
Definition: ezpblog.php:166
$ini
$ini
Definition: classes/admin/linklist.php:64
$suffix
$suffix
Definition: ezfilemanager/user/filedownload.php:168
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$height
$height
Definition: user/imageview.php:171
$width
$width
Definition: user/imageview.php:170
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.