LoginSignup
17
16

More than 5 years have passed since last update.

Laravel5 Intervention Image 2.xを利用した画像加工

Last updated at Posted at 2016-02-27

Intervention Image

構成

  • CentOS7
  • PHP 5.4
  • Laravel 5

準備

システム要件を確認

  • PHP >= 5.4
# php -v 
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27) 
  • Fileinfo Extension
# php -r 'phpinfo();'
fileinfo support => enabled
version => 1.0.5
  • GD Library (>=2.0) … or …
# php -r 'var_dump(gd_info());'
array(12) {
  ["GD Version"]=>
  string(26) "bundled (2.1.0 compatible)"
}
  • Imagick PHP extension (>=6.5.7)
# php -r 'print_r(imagick::getVersion());'
Array
(
    [versionNumber] => 1656
    [versionString] => ImageMagick 6.7.8-9 2014-06-10 Q16 http://www.imagemagick.org
)

GDを利用するか、Imagickを利用するか……。

インストール

Imagickのインストール

Imagickのインストール

GDのインストール

# yum install php-gd

LaravelにInterventionImageをインストール

  • インストール
# /usr/local/src/composer.phar require intervention/image
  • Laravelへ統合
config/app.php
'providers' => [  
    'Intervention\Image\ImageServiceProvider',
],
'aliases' => [ 
    'Image' => 'Intervention\Image\Facades\Image',
],
  • 設定ファイルの生成
# php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
  • 設定ファイル編集
config/image.php
return array(
    // GDか、Imagickどちらかを指定 
    //'driver' => 'gd'
    'driver' => 'imagick'
);

サンプルコード

app/Http/routes.php

Route::get('/', function() 
{ 
    $img = Image::make('http://upload.wikimedia.org/wikipedia/commons/2/2a/2008_ZB_Viper_SRT-10_blue.jpg')->resize(150, 100);
    return $img->response('jpg');   
});
17
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
16