@@ -23,16 +23,29 @@ In your existing Laravel application you can install this package using [Compose
2323composer require intervention/image-laravel
2424```
2525
26- Next, add the configuration files to your application using the ` vendor:publish ` command:
26+ ## Features
27+
28+ Although Intervention Image can be used with Laravel without this extension,
29+ this intergration package includes the following features that make image
30+ interaction with the framework much easier.
31+
32+ ### Application-wide configuration
33+
34+ The extension comes with a global configuration file that is recognized by
35+ Laravel. It is therefore possible to store the settings for Intervention Image
36+ once centrally and not have to define them individually each time you call the
37+ image manager.
38+
39+ The configuration file can be copied to the application with the following command.
2740
2841``` bash
2942php artisan vendor:publish --provider=" Intervention\Image\Laravel\ServiceProvider"
3043```
3144
32- This command will publish the configuration file ` image.php ` for the image
33- integration to your ` app/config ` directory. In this file you can set the
34- desired driver and its configuration options for Intervention Image. By default
35- the library is configured to use GD library for image processing.
45+ This command will publish the configuration file ` config/ image.php` . Here you
46+ can set the desired driver and its configuration options for Intervention
47+ Image. By default the library is configured to use GD library for image
48+ processing.
3649
3750The configuration files looks like this.
3851
@@ -89,20 +102,60 @@ You can read more about the different options for
89102[ decoding animations] ( https://image.intervention.io/v3/modifying/animations ) and
90103[ blending color] ( https://image.intervention.io/v3/basics/colors#transparency ) .
91104
92- ## Getting started
105+ ### Static Facade Interface
106+
107+ This package also integrates access to Intervention Image's central entry
108+ point, the ` ImageManager::class ` , via a static [ facade] ( https://laravel.com/docs/11.x/facades ) . The call provides access to the
109+ centrally configured [ image manager] ( https://image.intervention.io/v3/basics/instantiation ) via singleton pattern.
110+
111+ The following code example shows how to read an image from an upload request
112+ the image facade in a Laravel route and save it on disk with a random file
113+ name.
114+
115+ ``` php
116+ use Illuminate\Http\Request;
117+ use Illuminate\Support\Facades\Route;
118+ use Illuminate\Support\Facades\Storage;
119+ use Illuminate\Support\Str;
120+ use Intervention\Image\Laravel\Facades\Image;
121+
122+ Route::get('/', function (Request $request) {
123+ $upload = $request->file('image');
124+ $image = Image::read($upload)
125+ ->resize(300, 200);
126+
127+ Storage::put(
128+ Str::random() . '.' . $upload->getClientOriginalExtension(),
129+ $image->encodeByExtension($upload->getClientOriginalExtension(), quality: 70)
130+ );
131+ });
132+ ```
133+
134+ ### Image Response Macro
93135
94- The integration is now complete and it is possible to access the [ ImageManager] ( https://image.intervention.io/v3/basics/instantiation )
95- via Laravel's facade system.
136+ Furthermore, the package includes a response macro that can be used to
137+ elegantly encode an image resource and convert it to an HTTP response in a
138+ single step.
139+
140+ The following code example shows how to read an image from disk apply
141+ modifications and use the image response macro to encode it and send the image
142+ back to the user in one call. Only the first parameter is required.
96143
97144``` php
145+ use Illuminate\Support\Facades\Route;
146+ use Illuminate\Support\Facades\Storage;
147+ use Intervention\Image\Format;
98148use Intervention\Image\Laravel\Facades\Image;
99149
100150Route::get('/', function () {
101- $image = Image::read('images/example.jpg');
151+ $image = Image::read(Storage::get('example.jpg'))
152+ ->scale(300, 200);
153+
154+ return response()->image($image, Format::WEBP, quality: 65);
102155});
103156```
104157
105- Read the [ official documentation of Intervention Image] ( https://image.intervention.io ) for more information .
158+ You can read more about intervention image in general in the [ official documentation of Intervention Image] ( https://image.intervention.io ) .
106159
107160## Authors
108161
0 commit comments