Could someone please review this and propose a better solution; I feel this utterly sucks. I am having to create thumbnail images from original images; the thumbnail images will be placed in a separate folder from the original images, and the original images will remain untouched.
The only way I could fathom this being done was to copy the image into the /thumb folder and to mogrify the copy. I think there is a better way to do this.
Here is the code I proposed to do such a thing, but I think there is a better solution (I just can't fathom it):
class ThumbGenerator extends MethodGeneratofForActionPerformer {
function ThumbGenerator() {
// DO LOTS OF STUFF
}
/**
* Perform ImageMagick's UNIX mogrify command
*
* @access private
* @param int $width
* @param int $height
* @return boolean
*/
function &doMogrify($width, $height) { // STATIC BOOLEAN METHOD
/*-------------------------------------------------------------------------------------------------------------------
New 7/27/2004: If you are running an old version of PHP and/or GD Library < 2.0 the PHP
function 'imagecreatetruecolor' is not available to you, however, ImageMagick's UNIX command
'mogrify' might be available. Check to see if it exists and use that
--------------------------------------------------------------------------------------------------------------------*/
global $phpVersionInt;
if ($this->isSuccessful && ThumbView::isImage($this->fileName, $this->album)) {
$mogString = exec('whatis mogrify 2>&1');
if (!preg_match('/nothing appropriate/i', $mogString)) $mogExists = true;
}
if ($this->isSuccessful && $mogExists) {
$msg = exec('cp ' . $this->locationPath . '/' . $this->fileName .
' ' . $this->thumbLocationPath . '/' . $this->fileName .
' 2>&1');
if (!$msg) {
$mogResponse = exec("mogrify -geometry ${width}x$height " .
$this->thumbLocationPath . '/' . $this->fileName .
' 2>&1');
if ($mogResponse) {
$this->isSuccessful = false;
$this->setErrorArray(array('action' => 'Could not mogrify image: ' . nl2br($mogResponse)));
return false;
}
} else {
$this->isSuccessful = false;
$this->setErrorArray(array('action' => 'Could not mogrify image: ' . nl2br($msg)));
return false;
}
return true;
}
return false;
}
}
How can this be better fine-tuned?
Thanx
Phil