Intervention/image图片处理

1. Installation

1). To get started with image, add to your composer.json file as a dependency:

composer require intervention/image

2). Integration in Laravel

After installing the image library, register the Intervention\Image\ImageServiceProvider in your config/app.php configuration file:

'providers' => [
    // ...
    Intervention\Image\ImageServiceProvider::class,
  ],

Also, add the Image facade to the aliases array in your app configuration file:

'aliases' => [
    // ...
    'Image' => Intervention\Image\Facades\Image::class,
  ],

2. Configuration

Currently Intervention Image supports two Image processing extensions.

  • GD
  • Imagick

Make sure you have one of these installed in your PHP environment, before you start.

You're able to configure Intervention Image to use one of these libraries for all its operations. Just pass the configuration as an array directly into the ImageManager.

Example

// include composer autoload
require 'vendor/autoload.php';

// import the Intervention Image Manager Class
use Intervention\Image\ImageManager;

// create an image manager instance with favored driver
$manager = new ImageManager(array('driver' => 'imagick'));

// to finally create image instances
$image = $manager->make('public/foo.jpg')->resize(300, 200);
You might also use the static version of ImageManager as shown in the example below.

Static Example

// include composer autoload
require 'vendor/autoload.php';

// import the Intervention Image Manager Class
use Intervention\Image\ImageManagerStatic as Image;

// configure with favored image driver (gd by default)
Image::configure(array('driver' => 'imagick'));

// and you are ready to go ...
$image = Image::make('public/foo.jpg')->resize(300, 200);

After installing the image library, register the Intervention\Image\ImageServiceProvider in your config/app.php configuration file:

'providers' => [
    // ...
    Intervention\Image\ImageServiceProvider::class,
  ],

Also, add the Image facade to the aliases array in your app configuration file:

'aliases' => [
    // ...
    'Image' => Intervention\Image\Facades\Image::class,
  ],

If you're using Laravel, you can pull a configuration file into your application by running the following artisan command.

php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"

In Laravel 5 applications the configuration file is copied to config/image.php, With this copy you can alter the image driver settings for you application locally and define which library should be used by all commands:

return array(
    'driver' => 'imagick'
);

Currently you can choose between gd and imagick support.

3. Basic Usage

// open an image file and resize it
$img = Image::make('images/avatar.jpg')->resize(200, 200);

// resize image instance
$img->resize(320, 240);

// insert a watermark at special position
$img->insert('images/watermark.png', 'bottom-right', 15, 10);

// save image in desired format
$img->save('images/new_avatar.jpg');

// also you can do that like this
$img = Image::make('images/avatar.jpg')->resize(200, 200)->insert('images/new_avatar.jpg', 'bottom-right', 15, 10);

That's it! �� �� ��

4. More usage

  • Image Uploads;
  • Image Cache;
  • Image Filters;
  • URL Manipulation;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值