mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
DOCS Update Image docs to reflect intervention/image changes
This commit is contained in:
parent
b1d8c0308b
commit
fea36f2d7b
@ -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 {
|
||||
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);
|
||||
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 Portrait() {
|
||||
return $this->owner->getWidth() < $this->owner->getHeight();
|
||||
}
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:::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]
|
||||
|
@ -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.
|
||||
|
||||
## <a name="upgrading"></a>Upgrading
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user