开发者

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!


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


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. ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜