Home > Backend Development > PHP Tutorial > Using the image processing library Integration/Image in Laravel

Using the image processing library Integration/Image in Laravel

WBOY
Release: 2016-08-08 09:32:37
Original
1071 people have browsed it

System Requirements

  • PHP >= 5.3
  • Fileinfo Extension
  • GD Library (>=2.0) … or …
  • Imagick PHP extension (>=6.5.7)


Install and deploy Integration/image
Add in composer.json [require] section, then execute composer update

<span>"</span><span>intervention/image</span><span>"</span>: <span>"</span><span>2.0.15</span><span>"</span>
Copy after login

Laravel configuration

After the installation and deployment of Integration/image is completed, open the configuration file config/app.php and add code in the corresponding location, and then the Image class will be automatically loaded and available for use. It's powerful enough to handle almost all your image processing needs.

<span>//</span><span>服务提供器</span>
<span>'</span><span>Intervention\Image\ImageServiceProvider</span><span>'</span>

<span>//</span><span>别名配置</span>
<span>'</span><span>Image</span><span>'</span> => <span>'</span><span>Intervention\Image\Facades\Image</span><span>'</span>
Copy after login

Configuration settings
By default, Integration/Image uses PHP’s GD library extension. If you want to switch to imagick, you can use php artisan to create a configuration file to add the corresponding configuration.

$ php artisan config:publish intervention/imag
Copy after login

Basic use

A few basic functions are listed here. For more detailed instructions, please check the relevant interface documents.
1. Display a picture

Route::get('/', <span>function</span><span>()
{
       </span><span>$img</span> = Image::make('foo.jpg')->resize(300, 200<span>);
       </span><span>return</span> <span>$img</span>->response('jpg'<span>);
});</span>
Copy after login

2. Read an image file

<span>$img</span> = Image::make('foo/bar/baz.jpg');
Copy after login

3. Draw a picture

<span>$img</span> = Image::canvas(800, 600, '#ccc');
Copy after login

4. Edit a picture

<span>$img</span> = Image::make('foo.jpg')->resize(320, 240)->insert('watermark.png');
Copy after login

The above introduces the use of the image processing library Integration/Image in Laravel, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template