-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
use Intervention\Image\Encoders\JpegEncoder as GenericJpegEncoder; | ||
use Intervention\Image\Interfaces\ImageInterface; | ||
use Intervention\Image\Interfaces\SpecializedInterface; | ||
use Jcupitt\Vips\Config as VipsConfig; | ||
use Jcupitt\Vips\ForeignKeep; | ||
|
||
class JpegEncoder extends GenericJpegEncoder implements SpecializedInterface | ||
|
@@ -20,27 +21,36 @@ class JpegEncoder extends GenericJpegEncoder implements SpecializedInterface | |
*/ | ||
public function encode(ImageInterface $image): EncodedImage | ||
{ | ||
$blendingColor = $this->driver()->handleInput( | ||
$this->driver()->config()->blendingColor | ||
); | ||
|
||
$vipsImage = $image->core()->native(); | ||
|
||
if ($image->isAnimated()) { | ||
$vipsImage = $image->core()->frame(0)->native(); | ||
} | ||
|
||
$keep = $this->strip || (is_null($this->strip) && | ||
$this->driver()->config()->strip) ? ForeignKeep::ICC : ForeignKeep::ALL; | ||
$result = $vipsImage->writeToBuffer('.jpg', $this->getOptions()); | ||
|
||
$result = $vipsImage->writeToBuffer('.jpg', [ | ||
return new EncodedImage($result, 'image/jpeg'); | ||
} | ||
|
||
protected function getOptions(): array | ||
Check failure on line 35 in src/Encoders/JpegEncoder.php
|
||
{ | ||
$options = [ | ||
'Q' => $this->quality, | ||
'interlace' => $this->progressive, | ||
'keep' => $keep, | ||
'optimize_coding' => true, | ||
'background' => array_slice($blendingColor->convertTo(Rgb::class)->toArray(), 0, 3), | ||
]); | ||
'background' => array_slice($this->driver()->handleInput( | ||
Check failure on line 41 in src/Encoders/JpegEncoder.php
|
||
$this->driver()->config()->blendingColor | ||
)->convertTo(Rgb::class)->toArray(), 0, 3), | ||
]; | ||
|
||
return new EncodedImage($result, 'image/jpeg'); | ||
$strip = $this->strip || $this->driver()->config()->strip; | ||
|
||
if (VipsConfig::atLeast(8, 15)) { | ||
$options['keep'] = $strip ? ForeignKeep::ICC : ForeignKeep::ALL; | ||
} else { | ||
$options['strip'] = true; | ||
} | ||
|
||
return $options; | ||
} | ||
} |