-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert mime types for gd + add im comments
- Loading branch information
Showing
2 changed files
with
98 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,34 +8,77 @@ | |
use Kirby\Image\Darkroom; | ||
use Kirby\Toolkit\F; | ||
|
||
/** | ||
* ImageMagick | ||
* | ||
* @package Kirby Image | ||
* @author Bastian Allgeier <[email protected]> | ||
* @link https://getkirby.com | ||
* @copyright Bastian Allgeier GmbH | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
class ImageMagick extends Darkroom | ||
{ | ||
/** | ||
* Activates imagemagick's auto-orient feature unless | ||
* it is deactivated via the options | ||
* | ||
* @param string $file | ||
* @param array $options | ||
* @return string | ||
*/ | ||
protected function autoOrient(string $file, array $options) | ||
{ | ||
if ($options['autoOrient'] === true) { | ||
return '-auto-orient'; | ||
} | ||
} | ||
|
||
/** | ||
* Applies the blur settings | ||
* | ||
* @param string $file | ||
* @param array $options | ||
* @return string | ||
*/ | ||
protected function blur(string $file, array $options) | ||
{ | ||
if ($options['blur'] !== false) { | ||
return '-blur 0x' . $options['blur']; | ||
} | ||
} | ||
|
||
/** | ||
* Keep animated gifs | ||
* | ||
* @param string $file | ||
* @param array $options | ||
* @return string | ||
*/ | ||
protected function coalesce(string $file, array $options) | ||
{ | ||
if (F::extension($file) === 'gif') { | ||
return '-coalesce'; | ||
} | ||
} | ||
|
||
/** | ||
* Creates the convert command with the right path to the binary file | ||
* | ||
* @param string $file | ||
* @param array $options | ||
* @return string | ||
*/ | ||
protected function convert(string $file, array $options): string | ||
{ | ||
return sprintf($options['bin'] . ' "%s"', $file); | ||
} | ||
|
||
/** | ||
* Returns additional default parameters for imagemagick | ||
* | ||
* @return array | ||
*/ | ||
protected function defaults(): array | ||
{ | ||
return parent::defaults() + [ | ||
|
@@ -44,20 +87,44 @@ protected function defaults(): array | |
]; | ||
} | ||
|
||
/** | ||
* Applies the correct settings for grayscale images | ||
* | ||
* @param string $file | ||
* @param array $options | ||
* @return string | ||
*/ | ||
protected function grayscale(string $file, array $options) | ||
{ | ||
if ($options['grayscale'] === true) { | ||
return '-colorspace gray'; | ||
} | ||
} | ||
|
||
/** | ||
* Applies the correct settings for interlaced JPEGs if | ||
* activated via options | ||
* | ||
* @param string $file | ||
* @param array $options | ||
* @return string | ||
*/ | ||
protected function interlace(string $file, array $options) | ||
{ | ||
if ($options['interlace'] === true) { | ||
return '-interlace line'; | ||
} | ||
} | ||
|
||
/** | ||
* Creates and runs the full imagemagick command | ||
* to process the image | ||
* | ||
* @param string $file | ||
* @param array $options | ||
* @return array | ||
* @throws \Exception | ||
*/ | ||
public function process(string $file, array $options = []): array | ||
{ | ||
$options = $this->preprocess($file, $options); | ||
|
@@ -96,11 +163,26 @@ public function process(string $file, array $options = []): array | |
return $options; | ||
} | ||
|
||
/** | ||
* Applies the correct JPEG compression quality settings | ||
* | ||
* @param string $file | ||
* @param array $options | ||
* @return string | ||
*/ | ||
protected function quality(string $file, array $options): string | ||
{ | ||
return '-quality ' . $options['quality']; | ||
} | ||
|
||
/** | ||
* Creates the correct options to crop or resize the image | ||
* and translates the crop positions for imagemagick | ||
* | ||
* @param string $file | ||
* @param array $options | ||
* @return string | ||
*/ | ||
protected function resize(string $file, array $options): string | ||
{ | ||
// simple resize | ||
|
@@ -135,11 +217,26 @@ protected function resize(string $file, array $options): string | |
return $command; | ||
} | ||
|
||
/** | ||
* Makes sure to not process too many images at once | ||
* which could crash the server | ||
* | ||
* @param string $file | ||
* @param array $options | ||
* @return string | ||
*/ | ||
protected function save(string $file, array $options): string | ||
{ | ||
return sprintf('-limit thread 1 "%s"', $file); | ||
} | ||
|
||
/** | ||
* Removes all metadata from the image | ||
* | ||
* @param string $file | ||
* @param array $options | ||
* @return string | ||
*/ | ||
protected function strip(string $file, array $options): string | ||
{ | ||
return '-strip'; | ||
|