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.
It’s a shame that the Zend Framework team doesn’t want to implement a class like this. It’s such a pain to manipulate images in procedural style.
i agree with eduardo that it is a bit of a shame. i don’t really like having to step out of zend when it could easily be part of the dist.
i was going to checkout the zend_image stuff mentioned above but when i went to the google code page it stated:
“Hooray! First working version available. Now it supports only gd2 and transform tools. New milestone — overlays. ”
which is no good to me as i need to use imagemagick, not gd2.
rob ganly