Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generate thumbnail on uploading image using zend framework

I am back again with a question in zend framework. Can someone explain me, how to generate thumbnail images in zend framework after uploading an image.

Thanks!

like image 911
anurodh Avatar asked Oct 10 '22 13:10

anurodh


2 Answers

Zend itself seems will not provide this ability http://framework.zend.com/wiki/display/ZFPROP/Zend_Image+-+Eric+Potvin and propose to use http://www.imagemagick.org/script/index.php. then you are free to use your own way

like image 64
Subdigger Avatar answered Oct 20 '22 04:10

Subdigger


Not a purely Zend Framework answer, but lately I have found myself cheating like crazy, as follows.

I install phpThumb somewhere inside a web-accessible folder, say:

http://example.com/img/t/phpThumb.php

I make sure to configure phpThumb to use a cache folder:

/path/to/myapp/public/img/t/cache

which I chmod to be web-server writable.

Then I have a phpThumb view-helper that allows me to call an original image with some resize parameters:

<img src="<?php $view->phpThumb($origImgUrl, $desiredWidth, $desiredHeight) ?>">

All the view helper really does is transform the src url into one that runs through my phpThumb installation, making sure to add the cool (!) zoom-center parameter:

<img src="/img/t/phpThumb.php?src=origUrl&w=200&h=150&zc=1">

The first call to this image with these resize params results in a full GD/ImageMagick-driven resize, with the full performance hit. But subsequent calls for that image will pull from cache. Not as good as a request for a truly static image, but usually acceptable for my relatively low-volume purposes.

This is especially useful during design/development, when I am not sure precisely how big I want some front-end, eye-candy image to be. So I can just stash a single, relatively-large verison of my image (say 640x480) out in public/img/someBigImage.png and then resize at will.

It's a hack - probably better to perform this resizing on upload, as you are actually asking - but I must admit I have used it in a few spots. Don't tell anybody. ;-)

like image 22
David Weinraub Avatar answered Oct 20 '22 04:10

David Weinraub