Image Manipulation with Zend

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.

2 thoughts on “Image Manipulation with Zend

  1. 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.

  2. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>