zend framework2 - image resize zf2 -
i need implement image resize functionality (preferably gd2 library extension) in zend framework 2.
i not find component/helper same. references?
if want create one, should add together it. in older zend framework, there concept of action helper, zend framework 2 ?
please suggest best solution here.
i utilize imagine zend framework 2 handle this.
install imagine:php composer.phar require imagine/imagine:0.3.*
create service mill imagine
service (in yourmodule::getserviceconfig
):
return array( 'invokables' => array( // defining invokable here, mill 'my_image_service' => 'imagine\gd\imagine', ), );
use in logic (hereby little illustration controller):
public function imageaction() { $file = $this->params('file'); // @todo: apply strict validation! $width = $this->params('width', 30); // @todo: apply validation! $height = $this->params('height', 30); // @todo: apply validation! $imagine = $this->getservicelocator()->get('my_image_service'); $image = $imagine->open($file); $transformation = new \imagine\filter\transformation(); $transformation->thumbnail(new \imagine\image\box($width, $height)); $transformation->apply($image); $response = $this->getresponse(); $response->setcontent($image->get('png')); $response ->getheaders() ->addheaderline('content-transfer-encoding', 'binary') ->addheaderline('content-type', 'image/png') ->addheaderline('content-length', mb_strlen($imagecontent)); homecoming $response; }
this "quick , dirty" way, since should next (optional practice re-usability):
probably handle image transformations in service retrieve images service use input filter validate files , parameters cache output (see http://zend-framework-community.634137.n4.nabble.com/how-to-handle-404-with-action-controller-td4659101.html eventually)related: zend framework - returning image/file using controller
zend-framework2 image-resizing
No comments:
Post a Comment