[geeklog-cvs] geeklog-1.3/system/classes upload.class.php,1.28,1.29
geeklog-cvs-admin at lists.geeklog.net
geeklog-cvs-admin at lists.geeklog.net
Fri Sep 5 13:18:17 EDT 2003
Update of /usr/cvs/geeklog/geeklog-1.3/system/classes
In directory geeklog_prod:/tmp/cvs-serv21687/system/classes
Modified Files:
upload.class.php
Log Message:
Added support for the GD library when uploading images.
Index: upload.class.php
===================================================================
RCS file: /usr/cvs/geeklog/geeklog-1.3/system/classes/upload.class.php,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** upload.class.php 16 Jun 2003 10:05:05 -0000 1.28
--- upload.class.php 5 Sep 2003 17:18:15 -0000 1.29
***************
*** 154,158 ****
*/
var $_imageIndex = 0; // Integer
!
/**
* Constructor
--- 154,164 ----
*/
var $_imageIndex = 0; // Integer
!
! /**
! * @access private
! */
! var $_wasResized = false; // Boolean
!
!
/**
* Constructor
***************
*** 355,359 ****
if ($imageInfo['height'] > $this->_maxImageHeight) {
! $sizeOK= false;
if ($doResizeCheck) {
$this->_addError('Image, ' . $this->_currentFile['name'] . ' does not meet height limitations (is: ' . $imageInfo['height'] . ', max: ' . $this->_maxImageHeight . ')');
--- 361,365 ----
if ($imageInfo['height'] > $this->_maxImageHeight) {
! $sizeOK = false;
if ($doResizeCheck) {
$this->_addError('Image, ' . $this->_currentFile['name'] . ' does not meet height limitations (is: ' . $imageInfo['height'] . ', max: ' . $this->_maxImageHeight . ')');
***************
*** 361,370 ****
}
}
!
if ($this->_debug) {
$this->_addDebugMsg('File, ' . $this->_currentFile['name'] . ' has a width of '
. $imageInfo['width'] . ' and a height of ' . $imageInfo['height']);
}
!
return $sizeOK;
}
--- 367,376 ----
}
}
!
if ($this->_debug) {
$this->_addDebugMsg('File, ' . $this->_currentFile['name'] . ' has a width of '
. $imageInfo['width'] . ' and a height of ' . $imageInfo['height']);
}
!
return $sizeOK;
}
***************
*** 452,456 ****
if ($imageInfo['height'] > $this->_maxImageHeight) {
! $sizeOK= false;
}
}
--- 458,462 ----
if ($imageInfo['height'] > $this->_maxImageHeight) {
! $sizeOK = false;
}
}
***************
*** 465,468 ****
--- 471,477 ----
$newwidth = (int) ($imageInfo['width'] * $sizefactor);
$newheight = (int) ($imageInfo['height'] * $sizefactor);
+ $this->_addDebugMsg ('Going to resize image to ' . $newwidth . 'x'
+ . $newheight . ' using ' . $this->_imageLib);
+
if ($this->_imageLib == 'imagemagick') {
$newsize = $newwidth . 'x' . $newheight;
***************
*** 484,489 ****
exec($cmd, $mogrify_output, $retval);
! } else {
! // use netpm
$cmd = $this->_pathToNetPBM;
$filename = $this->_fileUploadDirectory . '/' . $this->_getDestinationName();
--- 493,499 ----
exec($cmd, $mogrify_output, $retval);
!
! } elseif ($this->_imageLib == 'netpbm') {
!
$cmd = $this->_pathToNetPBM;
$filename = $this->_fileUploadDirectory . '/' . $this->_getDestinationName();
***************
*** 532,547 ****
}
}
}
if ($retval > 0) {
if ($this->_imageLib == 'imagemagick') {
! $this->_addError('Image, ' . $this->_currentFile['name'] . ' had trouble being resized: ' . $mogrify_output[0]);
! } else {
! $this->_addError('Image, ' . $this->_currentFile['name'] . ' had trouble being resized: ' . $netpbm_output[0]);
}
$this->printErrors();
exit;
} else {
! $this->_addDebugMsg('Image, ' . $this->_currentFile['name'] . ' was resized from ' . $imageInfo['width'] . 'x' . $imageInfo['height'] . ' to ' . $newsize);
}
}
--- 542,659 ----
}
}
+
+ } elseif ($this->_imageLib == 'gdlib') {
+
+ $filename = $this->_fileUploadDirectory . '/'
+ . $this->_getDestinationName();
+
+ // Detect filetype
+ if ($this->_currentFile['type'] == 'image/gif') {
+ if (!function_exists ('imagecreatefromgif')) {
+ $this->_addError ('Sorry, this version of the GD library does not support GIF images.');
+ $this->printErrors ();
+ exit;
+ }
+ // If file is GIF do a quick PNG conversion first
+ $this->_addDebugMsg ('converting GIF to PNG');
+ $image_size = getimagesize ($filename);
+ $image_source = imagecreatefromgif ($filename);
+ $image_dest = imagecreatetruecolor ($image_size[0],
+ $image_size[1]);
+ imagecopy ($image_dest, $image_source, 0, 0, 0, 0,
+ $image_size[0], $image_size[1]);
+ $png_filename = $this->_fileUploadDirectory . '/'
+ . eregi_replace ("\.gif", ".png",
+ $this->_getDestinationName ());
+ if (!imagepng ($image_dest, $png_filename)) {
+ $this->_addError ('Error creating PNG from GIF: '
+ . $png_filename);
+ $this->printErrors ();
+ exit;
+ } else {
+ // GIF converted to PNG, delete original file
+ $this->_addDebugMsg ('Deleting GIF: ' . $filename);
+ if (!unlink ($filename)) {
+ $this->_addError ('Unable to delete original GIF: '
+ . $filename);
+ $this->printErrors ();
+ exit;
+ }
+ }
+ // change file type to PNG
+ $this->_currentFile['type'] = 'image/png';
+
+ // change file name to .png
+ $filename = $this->_fileUploadDirectory . '/'
+ . eregi_replace ("\.gif", ".png",
+ $this->_getDestinationName ());
+ }
+
+ if (($this->_currentFile['type'] == 'image/png') OR
+ ($this->_currentFile['type'] == 'image/x-png')) {
+ if (!$image_source = imagecreatefrompng ($filename)) {
+ $this->_addError ('Could not create image from PNG: '
+ . $filename);
+ $this->printErrors ();
+ exit;
+ }
+ } elseif (($this->_currentFile['type'] == 'image/jpeg') OR
+ ($this->_currentFile['type'] == 'image/pjpeg')) {
+ if (!$image_source = imagecreatefromjpeg ($filename)) {
+ $this->_addError ('Could not create image from JPEG: '
+ . $filename);
+ $this->printErrors ();
+ exit;
+ }
+ } else {
+ $this->_addError ('MIME type ' . $this->_currentFile['type']
+ . ' not supported.');
+ $this->printErrors ();
+ exit;
+ }
+
+ // do resize
+ if ($imageInfo['height'] > $imageInfo['width']) {
+ $sizefactor = (double) ($this->_maxImageHeight / $imageInfo['height']);
+ } else {
+ $sizefactor = (double) ($this->_maxImageWidth / $imageInfo['width']);
+ }
+ $this->_addDebugMsg ('Resizing image, factor=' . $sizefactor);
+ $newwidth = (int) ($imageInfo['width'] * $sizefactor);
+ $newheight = (int) ($imageInfo['height'] * $sizefactor);
+ $newsize = $newwidth . 'x' . $newheight;
+ $image_dest = ImageCreateTrueColor($newwidth, $newheight);
+ imagecopyresized ($image_dest, $image_source, 0, 0, 0, 0,
+ $newwidth, $newheight, $imageInfo['width'],
+ $imageInfo['height']);
+ if (($this->_currentFile['type'] == 'image/png') OR
+ ($this->_currentFile['type'] == 'image/x-png')) {
+ if (!imagepng ($image_dest, $filename)) {
+ $this->_addError ('Could not create PNG: ' . $filename);
+ $this->printErrors ();
+ exit;
+ }
+ } elseif (($this->_currentFile['type'] == 'image/jpeg') OR
+ ($this->_currentFile['type'] == 'image/pjpeg')) {
+ if (!imagejpeg ($image_dest, $filename)) {
+ $this->_addError ('Could not create JPEG: '. $filename);
+ $this->printErrors ();
+ exit;
+ }
+ }
}
if ($retval > 0) {
if ($this->_imageLib == 'imagemagick') {
! $this->_addError ('Image, ' . $this->_currentFile['name']
! . ' had trouble being resized: ' . $mogrify_output[0]);
! } elseif ($this->_imageLib == 'netpbm') {
! $this->_addError ('Image, ' . $this->_currentFile['name']
! . ' had trouble being resized: ' . $netpbm_output[0]);
}
$this->printErrors();
exit;
} else {
! $this->_addDebugMsg ('Image, ' . $this->_currentFile['name'] . ' was resized from ' . $imageInfo['width'] . 'x' . $imageInfo['height'] . ' to ' . $newsize);
}
}
***************
*** 549,553 ****
$perms = $this->_getPermissions();
if (!empty($perms)) {
! $returnChmod = chmod($this->_fileUploadDirectory . '/' . $this->_getDestinationName(), octdec($perms));
}
--- 661,665 ----
$perms = $this->_getPermissions();
if (!empty($perms)) {
! $returnChmod = chmod ($this->_fileUploadDirectory . '/' . eregi_replace ("\.gif", ".png", $this->_getDestinationName ()), octdec ($perms));
}
***************
*** 582,588 ****
/**
! * Sets the path to where the mogrify ImageMagic function is
*
! * @param string $path_to_mogrify Absolute path to mogrify
* @return boolean True if set, false otherwise
*
--- 694,700 ----
/**
! * Sets the path to where the netpbm utilities are
*
! * @param string $path_to_netpbm Absolute path to netpbm dir
* @return boolean True if set, false otherwise
*
***************
*** 596,599 ****
--- 708,723 ----
/**
+ * Configure upload to use GD library
+ *
+ * @return boolean True if set, false otherwise
+ *
+ */
+ function setGDLib()
+ {
+ $this->_imageLib = 'gdlib';
+ return true;
+ }
+
+ /**
* Sets mode to autmatically resize images that are either too wide or
* too tall
***************
*** 1010,1016 ****
function uploadFiles()
{
! // Before we do anything, let's see if we are limiting file uploads by IP
! // address and, if so, verify the poster is originating from one of those
! // places
if ($this->_limitByIP) {
if (!in_array($GLOBALS['REMOTE_ADDR'], $this->_allowedIPS)) {
--- 1134,1140 ----
function uploadFiles()
{
! // Before we do anything, let's see if we are limiting file uploads by
! // IP address and, if so, verify the poster is originating from one of
! // those places
if ($this->_limitByIP) {
if (!in_array($GLOBALS['REMOTE_ADDR'], $this->_allowedIPS)) {
More information about the geeklog-cvs
mailing list