Skip to content

Commit a35006d

Browse files
author
Andrei Tomita
committed
Added '-depth' '-flatten' and '-colorspace' options
1 parent 167af5e commit a35006d

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

Command.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,37 @@ public function autoOrient(): self
562562
return $this;
563563
}
564564

565+
/**
566+
* @see https://imagemagick.org/script/command-line-options.php#depth
567+
*/
568+
public function depth(int $depth): self
569+
{
570+
$this->command[] = '-depth ' . $depth;
571+
572+
return $this;
573+
}
574+
575+
/**
576+
* @see https://imagemagick.org/script/command-line-options.php#flatten
577+
*/
578+
public function flatten(): self
579+
{
580+
$this->command[] = '-flatten';
581+
582+
return $this;
583+
}
584+
585+
/**
586+
* @see https://imagemagick.org/script/command-line-options.php#colorspace
587+
*/
588+
public function colorspace(string $colorspace): self
589+
{
590+
$this->command[] = '-colorspace';
591+
$this->command[] = $this->ref->colorspace($colorspace);
592+
593+
return $this;
594+
}
595+
565596
/**
566597
* /!\ Append a raw command to ImageMagick.
567598
* Not safe! Use at your own risks!

References.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ public function __construct()
5959
}
6060
}
6161

62+
/**
63+
* @return string[]
64+
*/
65+
public function getColorspaceValuesReference(): array
66+
{
67+
return $this->config['colorspace_values'];
68+
}
69+
6270
/**
6371
* @return string[]
6472
*/
@@ -120,6 +128,28 @@ public function color(string $color): string
120128
));
121129
}
122130

131+
/**
132+
* Checks that colorspace value is valid in the references.
133+
*/
134+
public function colorspace(string $colorspace): string
135+
{
136+
$colorspace = \mb_strtolower(\trim($colorspace));
137+
138+
$references = $this->getColorspaceValuesReference();
139+
140+
if (\in_array($colorspace, $references, true)) {
141+
return $colorspace;
142+
}
143+
144+
throw new \InvalidArgumentException(\sprintf(
145+
'The specified colorspace value (%s) is invalid.'."\n".
146+
'The available values are:'."\n%s\n".
147+
'Please refer to ImageMagick command line documentation:'."\n%s",
148+
$colorspace, \implode(', ', $references),
149+
'http://www.imagemagick.org/script/command-line-options.php#colorspace'
150+
));
151+
}
152+
123153
/**
124154
* Checks that a rotation option is correct according to ImageMagick command line reference.
125155
*

Resources/references.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,39 @@
2121
'gif',
2222
'png',
2323
],
24+
'colorspace_values' => [
25+
'CMY',
26+
'CMYK',
27+
'Gray',
28+
'HCL',
29+
'HCLp',
30+
'HSB',
31+
'HSI',
32+
'HSL',
33+
'HSV',
34+
'HWB',
35+
'Lab',
36+
'LCHab',
37+
'LCHuv',
38+
'LMS',
39+
'Log',
40+
'Luv',
41+
'OHTA',
42+
'Rec601YCbCr',
43+
'Rec709YCbCr',
44+
'RGB',
45+
'scRGB',
46+
'sRGB',
47+
'Transparent',
48+
'xyY',
49+
'XYZ',
50+
'YCbCr',
51+
'YCC',
52+
'YDbDr',
53+
'YIQ',
54+
'YPbPr',
55+
'YUV'
56+
],
2457
'colors' => [
2558
'snow',
2659
'snow1',

0 commit comments

Comments
 (0)