<?php
 class phMagick_resize{ function resize(phmagick $p , $width, $height = 0, $exactDimentions = false){ $modifier = $exactDimentions ? '!' : '>'; $width = $width == 0 ? '' : $width ; $height = $height == 0 ? '' : $height ; $cmd = $p->getBinary('convert'); $cmd .= ' -scale "'. $width .'x'. $height . $modifier ; $cmd .= '" -quality '. $p->getImageQuality() ; $cmd .= ' "' . $p->getSource() .'" "'. $p->getDestination().'"'; $p->execute($cmd); $p->setSource($p->getDestination()); $p->setHistory($p->getDestination()); return $p ; } function resizeExactly(phmagick $p , $width, $height){ $p->requirePlugin('crop'); $p->requirePlugin('info'); list($w,$h) = $p->getInfo($p->getSource()); $wOrg = $w; $hOrg = $h; if($w > $h){ $h = $height; $w = $h*$wOrg/$hOrg; }else{ $w = $width; $h = $w*$hOrg/$wOrg; } if($w AND $w<$width) { $w = $width; $h=0; } else if($h AND $h<$height) { $h = $height; $w = 0; } $p->resize($w, $h)->crop($width, $height); } function onTheFly(phmagick $p,$imageUrl, $width, $height, $exactDimentions = false, $webPath = '', $physicalPath=''){ $basePath = str_replace($webPath,$physicalPath, dirname($imageUrl) ); $sourceFile = $basePath .'/'. basename($imageUrl); ; $thumbnailFile = $basePath . '/'.$width . '_' . $height . '_' . basename($imageUrl) ; $P->setSource($sourceFile); $p->setDestination($thumbnailFile); if (! file_exists($thumbnailFile)){ $p->resize($p,$width, $height, $exactDimentions); } if (! file_exists($thumbnailFile)){ $thumbnailFile = $sourceFile; } return str_replace($physicalPath, $webPath, $thumbnailFile ); } } ?>