DOCS Update Image docs to reflect intervention/image changes

This commit is contained in:
Daniel Hensby 2017-06-22 17:39:33 +01:00
parent b1d8c0308b
commit fea36f2d7b
No known key found for this signature in database
GPG Key ID: E38EC566FE29EB66
2 changed files with 49 additions and 50 deletions

View File

@ -98,54 +98,42 @@ Please refer to the [api:ImageManipulation] API documentation for specific funct
You can also create your own functions by decorating the `Image` class. You can also create your own functions by decorating the `Image` class.
:::php :::php
class MyImage extends DataExtension { class ImageExtension extends \SilverStripe\Core\Extension
{
public function Landscape() {
return $this->owner->getWidth() > $this->owner->getHeight(); public function Square($width)
} {
$variant = $this->owner->variantName(__FUNCTION__, $width);
public function Portrait() { return $this->owner->manipulateImage($variant, function (\SilverStripe\Assets\Image_Backend $backend) use($width) {
return $this->owner->getWidth() < $this->owner->getHeight(); $clone = clone $backend;
} $resource = clone $backend->getImageResource();
$resource->fit($width);
public function PerfectSquare() { $clone->setImageResource($resource);
$variant = $this->owner->variantName(__FUNCTION__); return $clone;
return $this->owner->manipulateImage($variant, function(Image_Backend $backend) { });
return $backend->croppedResize(100,100); }
});
} public function Blur($amount = null)
{
public function Exif(){ $variant = $this->owner->variantName(__FUNCTION__, $amount);
//http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data return $this->owner->manipulateImage($variant, function (\SilverStripe\Assets\Image_Backend $backend) use ($amount) {
$mime = $this->owner->getMimeType(); $clone = clone $backend;
$content = $this->owner->getAsString(); $resource = clone $backend->getImageResource();
$image = "data://{$mime};base64," . base64_encode($content); $resource->blur($amount);
$d=new ArrayList(); $clone->setImageResource($resource);
$exif = exif_read_data($image, 0, true); return $clone;
foreach ($exif as $key => $section) { });
$a=new ArrayList(); }
foreach ($section as $name => $val) {
$a->push(new ArrayData(array( }
"Title"=>$name,
"Content"=>$val
)));
}
$d->push(new ArrayData(array(
"Title"=>strtolower($key),
"Content"=>$a
)));
}
return $d;
}
}
:::yml :::yml
Image: SilverStripe\Assets\Image:
extensions: extensions:
- MyImage - ImageExtension
SilverStripe\Filesystem\Storage\DBFile: SilverStripe\Filesystem\Storage\DBFile:
extensions: extensions:
- MyImage - ImageExtension
### Form Upload ### Form Upload
@ -157,13 +145,10 @@ To adjust the quality of the generated images when they are resized add the
following to your mysite/config/config.yml file: following to your mysite/config/config.yml file:
:::yml :::yml
GDBackend: SilverStripe\Core\Injector\Injector:
default_quality: 90 SilverStripe\Assets\InterventionBackend:
# or properties:
ImagickBackend: Quality: 90
default_quality: 90
The default value is 75.
By default SilverStripe image functions will not resample an image if no By default SilverStripe image functions will not resample an image if no
cropping or resizing is taking place. You can tell SilverStripe to always to cropping or resizing is taking place. You can tell SilverStripe to always to
@ -183,6 +168,18 @@ to upload high quality (minimal compression) images as these will produce
better results when resampled. Very high resolution images may cause GD to better results when resampled. Very high resolution images may cause GD to
crash so a good size for website images is around 2000px on the longest edge. crash so a good size for website images is around 2000px on the longest edge.
## Changing the manipulation driver to Imagick
If you want to change the image manipulation driver to use Imagick instead of GD, you'll need to change your config so
that the `Intervention\Image\ImageManager` is instantiated with the `imagick` driver instead of GD:
```yml
SilverStripe\Core\Injector\Injector:
Intervention\Image\ImageManager:
constructor:
- { driver: imagick }
```
## API Documentation ## API Documentation
* [api:File] * [api:File]

View File

@ -56,6 +56,8 @@ guide developers in preparing existing 3.x code for compatibility with 4.0
* admin has been moved to a new module [silverstripe/admin](https://github.com/silverstripe/silverstripe-admin). * admin has been moved to a new module [silverstripe/admin](https://github.com/silverstripe/silverstripe-admin).
* Behat support updated to behat 3. See the * Behat support updated to behat 3. See the
[behat extension](https://github.com/silverstripe/silverstripe-behat-extension) for more information. [behat extension](https://github.com/silverstripe/silverstripe-behat-extension) for more information.
* The `GDBackend` and `ImagickBackend` classes have been replaced by a unified `InterventionBackend` which uses the
[intervention/image](https://github.com/intervention/image) library to power manipualations.
## <a name="upgrading"></a>Upgrading ## <a name="upgrading"></a>Upgrading