From fea36f2d7b67e0527f70b57ba58aff200fb54634 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Thu, 22 Jun 2017 17:39:33 +0100 Subject: [PATCH] DOCS Update Image docs to reflect intervention/image changes --- .../02_Developer_Guides/14_Files/02_Images.md | 97 +++++++++---------- docs/en/04_Changelogs/4.0.0.md | 2 + 2 files changed, 49 insertions(+), 50 deletions(-) diff --git a/docs/en/02_Developer_Guides/14_Files/02_Images.md b/docs/en/02_Developer_Guides/14_Files/02_Images.md index 83799ccc0..f232b01bf 100644 --- a/docs/en/02_Developer_Guides/14_Files/02_Images.md +++ b/docs/en/02_Developer_Guides/14_Files/02_Images.md @@ -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. :::php - class MyImage extends DataExtension { - - public function Landscape() { - return $this->owner->getWidth() > $this->owner->getHeight(); - } - - public function Portrait() { - return $this->owner->getWidth() < $this->owner->getHeight(); - } - - public function PerfectSquare() { - $variant = $this->owner->variantName(__FUNCTION__); - return $this->owner->manipulateImage($variant, function(Image_Backend $backend) { - return $backend->croppedResize(100,100); - }); - } - - public function Exif(){ - //http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data - $mime = $this->owner->getMimeType(); - $content = $this->owner->getAsString(); - $image = "data://{$mime};base64," . base64_encode($content); - $d=new ArrayList(); - $exif = exif_read_data($image, 0, true); - 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; - } - } + class ImageExtension extends \SilverStripe\Core\Extension + { + + public function Square($width) + { + $variant = $this->owner->variantName(__FUNCTION__, $width); + return $this->owner->manipulateImage($variant, function (\SilverStripe\Assets\Image_Backend $backend) use($width) { + $clone = clone $backend; + $resource = clone $backend->getImageResource(); + $resource->fit($width); + $clone->setImageResource($resource); + return $clone; + }); + } + + public function Blur($amount = null) + { + $variant = $this->owner->variantName(__FUNCTION__, $amount); + return $this->owner->manipulateImage($variant, function (\SilverStripe\Assets\Image_Backend $backend) use ($amount) { + $clone = clone $backend; + $resource = clone $backend->getImageResource(); + $resource->blur($amount); + $clone->setImageResource($resource); + return $clone; + }); + } + + } :::yml - Image: + SilverStripe\Assets\Image: extensions: - - MyImage + - ImageExtension SilverStripe\Filesystem\Storage\DBFile: extensions: - - MyImage + - ImageExtension ### 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: :::yml - GDBackend: - default_quality: 90 - # or - ImagickBackend: - default_quality: 90 - -The default value is 75. + SilverStripe\Core\Injector\Injector: + SilverStripe\Assets\InterventionBackend: + properties: + Quality: 90 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 @@ -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 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:File] diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md index 6fa1d7632..5cd8e6240 100644 --- a/docs/en/04_Changelogs/4.0.0.md +++ b/docs/en/04_Changelogs/4.0.0.md @@ -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). * Behat support updated to behat 3. See the [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. ## Upgrading