image resize zf2

前端 未结 5 1471
情话喂你
情话喂你 2020-12-30 13:52

I need to implement image resize functionality (preferably with gd2 library extension) in zend framework 2.

I could not find any component/helper for the same. Any

5条回答
  •  不知归路
    2020-12-30 14:37

    In order to resize uploaded image on the fly you should do this:

    public function imageAction() 
    {
    // ...
    $imagine = $this->getImagineService();
    $size = new \Imagine\Image\Box(150, 150);
    $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
    
    $image = $imagine->open($destinationPath);
    $image->thumbnail($size, $mode)->save($destinationPath);
    // ...
    }
    
    public function getImagineService()
    {
        if ($this->imagineService === null)
        {
            $this->imagineService = $this->getServiceLocator()->get('my_image_service');
        }
        return $this->imagineService;
    }
    

提交回复
热议问题