[geeklog-cvs] geeklog-1.3/system/classes upload.class.php,1.25,1.26
dhaun at geeklog.net
dhaun at geeklog.net
Thu Mar 27 15:20:02 EST 2003
Update of /usr/cvs/geeklog/geeklog-1.3/system/classes
In directory internal.geeklog.net:/tmp/cvs-serv7566/system/classes
Modified Files:
upload.class.php
Log Message:
You can now keep the original, unscaled image when uploading images for stories. The smaller, scaled version will then be used as a thumbnail and link to the original image (based on code provided by Alexander Schmacks).
Index: upload.class.php
===================================================================
RCS file: /usr/cvs/geeklog/geeklog-1.3/system/classes/upload.class.php,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** upload.class.php 9 Mar 2003 01:20:35 -0000 1.25
--- upload.class.php 27 Mar 2003 20:20:00 -0000 1.26
***************
*** 109,112 ****
--- 109,116 ----
* @access private
*/
+ var $_keepOriginalImage = false; // boolean
+ /**
+ * @access private
+ */
var $_maxFileUploadsPerForm = 5;
/**
***************
*** 465,492 ****
$cmd = $this->_pathToMogrify . ' -resize '. $newsize . ' ' . $this->_fileUploadDirectory . '/' . $this->_getDestinationName() . ' 2>&1';
$this->_addDebugMsg('Attempting to resize with this command (imagemagick): ' . $cmd);
exec($cmd, $mogrify_output, $retval);
} else {
// use netpm
! $cmd = $_CONF['path_to_netpbm'];
$filename = $this->_fileUploadDirectory . '/' . $this->_getDestinationName();
$cmd_end = ' ' . $filename . ' | ' . $this->_pathToNetPBM . 'pnmscale -xsize=' . $newwidth . ' -ysize=' . $newheight . ' | ' . $this->_pathToNetPBM;
// convert to pnm, resize, convert back
! if (eregi('\.png', $filename)) {
$tmpfile = $this->_fileUploadDirectory . '/tmp.png';
! $cmd .= $this->_pathToNetPBM . 'pngtopnm ' . $cmd_end . 'pnmtopng > ' . $tmpfile;
! } else {
! if (eregi('\.(jpg|jpeg)', $filename)) {
! $tmpfile = $this->_fileUploadDirectory . '/tmp.jpg';
! $cmd .= $this->_pathToNetPBM . 'jpegtopnm ' . $cmd_end . 'ppmtojpeg > ' . $tmpfile;
! } else {
! if (eregi('\.gif', $filename)) {
! $tmpfile = $this->_fileUploadDirectory . '/tmp.gif';
! $cmd .= $this->_pathToNetPBM . 'giftopnm ' . $cmd_end . 'ppmquant 256 | ' . $this->_pathToNetPBM . 'ppmtogif > ' . $tmpfile;
! }
! }
! }
$this->_addDebugMsg('Attempting to resize with this command (netpbm): ' . $cmd);
exec($cmd, $netpbm_output, $retval);
// Move tmp file to actual file
if (!copy($tmpfile,$filename)) {
--- 469,522 ----
$cmd = $this->_pathToMogrify . ' -resize '. $newsize . ' ' . $this->_fileUploadDirectory . '/' . $this->_getDestinationName() . ' 2>&1';
$this->_addDebugMsg('Attempting to resize with this command (imagemagick): ' . $cmd);
+
+ if ($this->_keepOriginalImage) {
+ $filename = $this->_fileUploadDirectory . '/'
+ . $this->_getDestinationName ();
+ $lFilename_large = substr_replace ($this->_getDestinationName (), '_original.', strrpos ($this->_getDestinationName (), '.'), 1);
+ $lFilename_large_complete = $this->_fileUploadDirectory
+ . '/' . $lFilename_large;
+ if (!copy ($filename, $lFilename_large_complete)) {
+ $this->_addError ("Couldn't copy $filename to $lFilename_large_complete. You'll need to remove both files.");
+ $this->printErrors ();
+ exit;
+ }
+ }
+
exec($cmd, $mogrify_output, $retval);
} else {
// use netpm
! $cmd = $this->_pathToNetPBM;
$filename = $this->_fileUploadDirectory . '/' . $this->_getDestinationName();
$cmd_end = ' ' . $filename . ' | ' . $this->_pathToNetPBM . 'pnmscale -xsize=' . $newwidth . ' -ysize=' . $newheight . ' | ' . $this->_pathToNetPBM;
// convert to pnm, resize, convert back
! if (eregi ('\.png', $filename)) {
$tmpfile = $this->_fileUploadDirectory . '/tmp.png';
! $cmd .= 'pngtopnm ' . $cmd_end . 'pnmtopng > ' . $tmpfile;
! } else if (eregi ('\.(jpg|jpeg)', $filename)) {
! $tmpfile = $this->_fileUploadDirectory . '/tmp.jpg';
! $cmd .= 'jpegtopnm ' . $cmd_end . 'ppmtojpeg > ' . $tmpfile;
! } else if (eregi ('\.gif', $filename)) {
! $tmpfile = $this->_fileUploadDirectory . '/tmp.gif';
! $cmd .= 'giftopnm ' . $cmd_end . 'ppmquant 256 | '
! . $this->_pathToNetPBM . 'ppmtogif > ' . $tmpfile;
! } else {
! $this->_addError ("Image format of file $filename is not supported.");
! $this->printErrors ();
! exit;
! }
$this->_addDebugMsg('Attempting to resize with this command (netpbm): ' . $cmd);
exec($cmd, $netpbm_output, $retval);
+ if ($this->_keepOriginalImage) {
+ $lFilename_large = substr_replace ($this->_getDestinationName(), '_original.', strrpos ($this->_getDestinationName (), '.'), 1);
+ $lFilename_large_complete = $this->_fileUploadDirectory
+ . '/' . $lFilename_large;
+ if (!copy ($filename, $lFilename_large_complete)) {
+ $this->_addError ("Couldn't copy $filename to $lFilename_large_complete. You'll need to remove both files.");
+ $this->printErrors ();
+ exit;
+ }
+ }
+
// Move tmp file to actual file
if (!copy($tmpfile,$filename)) {
***************
*** 625,628 ****
--- 655,672 ----
return true;
}
+
+ /**
+ * Allows you to keep the original (unscaled) image.
+ *
+ * @param boolean $keepit true = keep original, false = don't
+ * @return boolean true if we set values OK, otherwise false
+ *
+ */
+ function keepOriginalImage ($keepit)
+ {
+ $this->_keepOriginalImage = $keepit;
+
+ return true;
+ }
/**
More information about the geeklog-cvs
mailing list