Skip to content

Commit f0fce23

Browse files
committed
DOC Document upgrading intervention/image
1 parent d7f6b7e commit f0fce23

File tree

3 files changed

+66
-10
lines changed

3 files changed

+66
-10
lines changed

en/02_Developer_Guides/14_Files/02_Images.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,19 @@ SilverStripe\Assets\Image:
318318
lazy_loading_enabled: false
319319
```
320320

321-
## Changing the manipulation driver to imagick
321+
## Changing the manipulation driver {#intervention-image-driver}
322322

323-
If you want to change the image manipulation driver to use Imagick instead of GD, you'll need to change your config so
324-
that the `Intervention\Image\ImageManager` is instantiated with the `imagick` driver instead of GD:
323+
If you have the [imagick PHP extension](https://www.php.net/manual/en/book.imagick.php) installed, it will be used as the driver for `intervention/image` by default. If you don't, the assumption is that you have the [GD PHP extension](https://www.php.net/manual/en/book.image.php) installed, and it will be used instead.
324+
325+
If you want to change the image manipulation driver to something else (either a third-party driver, or else use GD even when imagick is installed), you need to configure that via the injector:
325326

326327
```yml
328+
---
329+
After: '#assetsimage-imagick'
330+
---
327331
SilverStripe\Core\Injector\Injector:
328-
Intervention\Image\ImageManager:
329-
constructor:
330-
- { driver: imagick }
332+
InterventionImageDriver:
333+
class: 'Intervention\Image\Drivers\Gd\Driver'
331334
```
332335

333336
## Storage

en/02_Developer_Guides/14_Files/05_File_Manipulation.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ This can be very useful if you want to convert a file to a different format for
209209

210210
#### Making our own `FileConverter`
211211

212-
Converting between image formats is the easiest example, because we can let [Intervention Image](https://image.intervention.io/v2) do the heavy lifting for us. Note that there is a built in [`InterventionImageFileConverter`](api:SilverStripe\Assets\Conversion\InterventionImageFileConverter) class which does this already, but we'll use this as an example for how to create our own `FileConverter`.
212+
Converting between image formats is the easiest example, because we can let [Intervention Image](https://image.intervention.io/v3) do the heavy lifting for us. Note that there is a built in [`InterventionImageFileConverter`](api:SilverStripe\Assets\Conversion\InterventionImageFileConverter) class which does this already, but we'll use this as an example for how to create our own `FileConverter`.
213213

214214
The `FileConverter` interface requires us to implement two methods:
215215

@@ -219,7 +219,7 @@ The `FileConverter` interface requires us to implement two methods:
219219
```php
220220
namespace App\Conversion;
221221
222-
use Intervention\Image\Exception\ImageException;
222+
use Intervention\Image\Exceptions\RuntimeException;
223223
use SilverStripe\Assets\Conversion\FileConverter;
224224
use SilverStripe\Assets\Conversion\FileConverterException;
225225
use SilverStripe\Assets\File;
@@ -248,7 +248,7 @@ class ImageFileConverter implements FileConverter
248248
return [$tuple, $backend];
249249
}
250250
);
251-
} catch (ImageException $e) {
251+
} catch (RuntimeException $e) {
252252
throw new FileConverterException('Failed to convert: ' . $e->getMessage(), $e->getCode(), $e);
253253
}
254254
}
@@ -320,7 +320,7 @@ Our callback returns both the information about the variant file and the `Image_
320320
```php
321321
try {
322322
// ...
323-
} catch (ImageException $e) {
323+
} catch (RuntimeException $e) {
324324
throw new FileConverterException('Failed to convert: ' . $e->getMessage(), $e->getCode(), $e);
325325
}
326326
```

en/08_Changelogs/6.0.0.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ title: 6.0.0 (unreleased)
1010
- [Run `CanonicalURLMiddleware` in all environments by default](#url-middleware)
1111
- [Changes to scaffolded form fields](#scaffolded-fields)
1212
- [Other new features](#other-new-features)
13+
- [Dependency changes](#dependency-changes)
14+
- [`intervention/image` has been upgraded from v2 to v3](#intervention-image)
1315
- [Bug fixes](#bug-fixes)
1416
- [API changes](#api-changes)
1517
- [Most extension hook methods are now protected](#hooks-protected)
@@ -58,6 +60,57 @@ All other models used `SearchableDropdownField` for `has_one` relations and `Gri
5860
- Native indexed PHP arrays can now be passed into templates and iterated over with `<% loop $MyArray %>`. Under the hood they are wrapped in [`ArrayList`](api:SilverStripe\View\ViewableData), so you can get the count using `$Count` and use `<% if $ArrayList %>` as a shortcut for `<% if $ArrayList.Count %>`. Other functionality from `ArrayList` such as filtering and sorting cannot be used on arrays since they don't have keys to filter or sort against.
5961
- Modules no longer need to have a root level `_config.php` or `_config` directory to be recognised as a Silverstripe CMS module. They will now be recognised as a module if they have a `composer.json` file with a `type` of `silverstripe-vendormodule` or `silverstripe-theme`.
6062

63+
## Dependency changes
64+
65+
### `intervention/image` has been upgraded from v2 to v3 {#intervention-image}
66+
67+
We've upgraded from `intervention/image` v2 to v3. One of the main improvements included in this upgrade is full support for animated GIFs.
68+
69+
If you are directly interacting with APIs from `intervention/image` in your project or module you should check out [their upgrade guide](https://image.intervention.io/v3/introduction/upgrade).
70+
71+
#### Animated vs still images {#intervention-image-animations}
72+
73+
Manipulating animated images takes longer, and results in a larger filesize.
74+
75+
Because of this, the [`ThumbnailGenerator`](api:SilverStripe\AssetAdmin\Model\ThumbnailGenerator) will provide still images as thumbnails for animated gifs by default. You can change that for a given instance of `ThumbnailGenerator` by passing `true` to the [`setAllowsAnimation()`](api:SilverStripe\AssetAdmin\Model\ThumbnailGenerator::setAllowsAnimation()) method. For example, to allow animated thumbnails for `UploadField`:
76+
77+
```yml
78+
---
79+
After: '#assetadminthumbnails'
80+
---
81+
SilverStripe\Core\Injector\Injector:
82+
SilverStripe\AssetAdmin\Model\ThumbnailGenerator.assetadmin:
83+
properties:
84+
AllowsAnimation: true
85+
```
86+
87+
When manipulating images yourself, you can use the new [`RemoveAnimation()`](api:SilverStripe\Assets\ImageManipulation::RemoveAnimation()) method before your resizing methods:
88+
89+
```ss
90+
$MyImage.RemoveAnimation.FitMax(300, 200)
91+
```
92+
93+
If the image isn't animated `RemoveAnimation()` will just return the original image without generating a variant, so it's safe to use without first checking if the image is animated.
94+
95+
#### Using GD or Imagick {#intervention-image-driver}
96+
97+
One of the changes that comes as a result of this upgrade is a change in how you configure which manipulation driver (GD or Imagick) to use.
98+
99+
To facilitate upgrades and to ensure we are providing optimal defaults out of the box, if you have the [imagick PHP extension](https://www.php.net/manual/en/book.imagick.php) installed, it will be used as the driver for `intervention/image` by default. If you don't, the assumption is that you have the [GD PHP extension](https://www.php.net/manual/en/book.image.php) installed, and it will be used instead.
100+
101+
See [changing the manipulation driver](/developer_guides/files/images/#intervention-image-driver) for the new configuration for swapping the driver used by `intervention/image`.
102+
103+
#### New API {#intervention-image-new-api}
104+
105+
The following new methods have been added to facilitate this upgrade:
106+
107+
|Method name|Where the method was added|
108+
|---|---|
109+
|`getIsAnimated()`|[`AssetContainer::getIsAnimated()`](api:SilverStripe\Assets\Storage\AssetContainer::getIsAnimated()), [`ImageManipulation::getIsAnimated()`](api:SilverStripe\Assets\ImageManipulation::getIsAnimated()) (and therefore `DBFile`, `File`, and their subclasses), [`Image_Backend::getIsAnimated()`](api:SilverStripe\Assets\Image_Backend::getIsAnimated()), [`InterventionBackend::getIsAnimated()`](api:SilverStripe\Assets\InterventionBackend::getIsAnimated())|
110+
|`RemoveAnimation()`|[`ImageManipulation::RemoveAnimation()`](api:SilverStripe\Assets\ImageManipulation::RemoveAnimation()) (and therefore `DBFile`, `File`, and their subclasses), [`Image_Backend::removeAnimation()`](api:SilverStripe\Assets\Image_Backend::removeAnimation()), [`InterventionBackend::removeAnimation()`](api:SilverStripe\Assets\InterventionBackend::removeAnimation())|
111+
|`getAllowsAnimation()`|[`ThumbnailGenerator::getAllowsAnimation()`](api:SilverStripe\AssetAdmin\Model\ThumbnailGenerator::getAllowsAnimation())|
112+
|`setAllowsAnimation()`|[`ThumbnailGenerator::setAllowsAnimation()`](api:SilverStripe\AssetAdmin\Model\ThumbnailGenerator::setAllowsAnimation())|
113+
61114
## Bug fixes
62115

63116
This release includes a number of bug fixes to improve a broad range of areas. Check the change logs for full details of these fixes split by module. Thank you to the community members that helped contribute these fixes as part of the release!

0 commit comments

Comments
 (0)