I had been on the prowl for an MVC approach to image manipulation. Especially a method that did it the Zend way. In the forums and documentation for the framework the developers didn’t see a real need to implement a “Zend_Image” class in the libraries as this was already available through the PHP GD and Imagick hooks.
Some of us however did and there are a few tutorials on how to incorporate the PHPThumb library into Zend. I have used the PHPThumb Library on the mokocharlie.com project and found it I however stumbled on a much simpler way of doing this that feels more native to the framework Zend_Image is that implementation hidden somewhere on the code.google.com hosting servers.
$image = new Zend_Image( APPLICATION_PATH.'/../public/media/images/large/'.$filename,
new Zend_Image_Driver_Gd());
$transform = new Zend_Image_Transform($image);
if($image->getWidth() > $image->getHeight()){
$transform->fitToWidth(295)
->save(APPLICATION_PATH.'/../public/media/images/medium/'.$filename);
$transform->fitToWidth(147)
->save(APPLICATION_PATH.'/../public/media/images/small/'.$filename);
$transform->center()->middle()->crop(74, 74)
->save(APPLICATION_PATH.'/../public/media/images/tiny/'.$filename);
}else{
$transform->fitToHeight(300)
->save(APPLICATION_PATH.'/../public/media/images/medium/'.$filename);
$transform->fitToWidth(147)
->save(APPLICATION_PATH.'/../public/media/images/small/'.$filename);
$transform->center()->middle()->crop(74, 74)
->save(APPLICATION_PATH.'/../public/media/images/tiny/'.$filename);
}
The above is my implementation of it as I create three versions of an uploaded image.
Share this post
Twitter
Google+
Facebook
Reddit
LinkedIn
StumbleUpon
Pinterest
Email