zend Framework 2 で画像のサイズ変更機能を (できれば gd2 ライブラリ拡張を使用して) 実装する必要があります。
同じコンポーネント/ヘルパーが見つかりませんでした。参照はありますか?
作成したい場合は、どこに追加すればよいですか。古い Zend フレームワークにはアクション ヘルパーという概念がありましたが、Zend フレームワーク 2 ではどうでしょうか。
ここで最善の解決策を提案してください。
zend Framework 2 で画像のサイズ変更機能を (できれば gd2 ライブラリ拡張を使用して) 実装する必要があります。
同じコンポーネント/ヘルパーが見つかりませんでした。参照はありますか?
作成したい場合は、どこに追加すればよいですか。古い Zend フレームワークにはアクション ヘルパーという概念がありましたが、Zend フレームワーク 2 ではどうでしょうか。
ここで最善の解決策を提案してください。
私は現在、これを処理するためにImagineをZendFramework2と一緒に使用しています。
php composer.phar require imagine/Imagine:0.3.*サービスのサービスファクトリを作成しますImagine(でYourModule::getServiceConfig):
return array(
    'invokables' => array(
        // defining it as invokable here, any factory will do too
        'my_image_service' => 'Imagine\Gd\Imagine',
    ),
);
ロジックで使用します(これにより、コントローラーを使用した小さな例):
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));
    return $response;
}
これは明らかに「迅速で汚い」方法です。次のことを行う必要があるためです(オプションですが、再利用性のための優れた方法です)。
このためのサービスを使用して、機能を必要とするコントローラーに注入します。
これは、Zend Framework 2のWebinoImageThumbというモジュールです。これを確認してください。次のようないくつかの優れた機能があります-
アップロードされた画像のサイズをその場で変更するには、次のようにする必要があります。
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;
}