depage-graphics
Toggle main menu visibility
Loading...
Searching...
No Matches
Graphicsmagick.php
Go to the documentation of this file.
1
<?php
2
10
11
namespace
Depage\Graphics\Providers;
12
19
class
Graphicsmagick
extends
Imagemagick
20
{
32
protected
function
crop
($width, $height, $x = 0, $y = 0): void
33
{
34
if
(!$this->
bypassTest
($width, $height, $x, $y)) {
35
// '+' for positive offset (the '-' is already there)
36
$x = ($x < 0) ? $x :
'+'
. $x;
37
$y = ($y < 0) ? $y :
'+'
. $y;
38
39
$xExtent = ($x > 0) ?
"+0"
: $x;
40
$yExtent = ($y > 0) ?
"+0"
: $y;
41
$this->command .=
" -gravity NorthWest -crop {$width}x{$height}{$x}{$y}! -gravity NorthWest -extent {$width}x{$height}{$xExtent}{$yExtent}"
;
42
$this->size = [$width, $height];
43
}
44
}
45
51
protected
function
getImageSize
(): array
52
{
53
$imageSize =
false
;
54
if
(is_callable(
'getimagesize'
)) {
55
$imageSize = getimagesize($this->input);
56
}
57
if
(!$imageSize) {
58
$pageNumber = $this->
getPageNumber
();
59
exec(
"{$this->executable} identify -ping -format \"%wx%h\" "
. escapeshellarg($this->input) . $pageNumber .
' 2>&1'
, $commandOutput, $returnStatus);
60
if
($returnStatus === 0) {
61
$imageSize = explode(
'x'
, $commandOutput[0]);
62
}
else
{
63
$this->
unlock
();
64
65
throw
new \Depage\Graphics\Exceptions\Exception(implode(
"\n"
, $commandOutput));
66
}
67
}
68
69
return
$imageSize;
70
}
71
81
public
function
render
(
$input
,
$output
=
null
): void
82
{
83
\Depage\Graphics\Graphics::render
(
$input
,
$output
);
84
85
$pageNumber = $this->
getPageNumber
();
86
87
$this->command = $this->executable .
" convert -auto-orient '+profile' '*' -auto-orient "
. escapeshellarg($this->input) .
"{$pageNumber} -background none"
;
88
$this->
processQueue
();
89
90
if
($this->otherRender && file_exists($this->output)) {
91
// do nothing file is already generated
92
} elseif (
93
$this->
bypass
94
&& $this->inputFormat == $this->outputFormat
95
) {
96
$this->
bypass
();
97
}
else
{
98
$quality
= $this->
getQuality
();
99
$optimize
= $this->
getOptimize
();
100
101
if
($this->background ===
'checkerboard'
) {
102
$tempFile = tempnam(sys_get_temp_dir(),
'depage-graphics-'
);
103
$this->command .=
" miff:{$tempFile}"
;
104
105
$this->
execCommand
();
106
107
$canvasSize = $this->size[0] .
"x"
. $this->size[1];
108
109
$this->command = $this->executable .
" convert"
;
110
$this->command .=
" -page {$canvasSize} -size {$canvasSize} pattern:checkerboard"
;
111
$this->command .=
" -page {$canvasSize} miff:{$tempFile} -colorspace rgb -flatten {$quality}{$optimize} +page {$this->outputFormat}:"
. escapeshellarg($this->output);
112
113
$this->
execCommand
();
114
unlink($tempFile);
115
}
else
{
116
$background
= $this->
getBackground
();
117
$this->command .=
"{$background} -colorspace rgb {$quality}{$optimize} +page {$this->outputFormat}:"
. escapeshellarg($this->output);
118
119
$this->
execCommand
();
120
121
if
($this->optimize) {
122
$this->
optimizeImage
($this->output);
123
}
124
}
125
}
126
127
parent::renderFinished();
128
}
129
135
protected
function
getBackground
()
136
{
137
if
($this->background[0] ===
'#'
) {
138
$background
=
" -flatten -background {$this->background}"
;
139
} elseif ($this->outputFormat ==
'jpg'
) {
140
$background
=
" -flatten -background #FFF"
;
141
}
else
{
142
$background
=
''
;
143
}
144
145
return
$background
;
146
}
147
}
148
149
/* vim:set ft=php sw=4 sts=4 fdm=marker et : */
Depage\Graphics\Graphics\$background
$background
Image background string.
Definition
Graphics.php:74
Depage\Graphics\Graphics\$quality
$quality
Image quality string.
Definition
Graphics.php:78
Depage\Graphics\Graphics\processQueue
processQueue()
Process action queue.
Definition
Graphics.php:329
Depage\Graphics\Graphics\bypassTest
bypassTest($width, $height, $x=0, $y=0)
Tests if action would change current image.
Definition
Graphics.php:558
Depage\Graphics\Graphics\$input
$input
Input filename.
Definition
Graphics.php:46
Depage\Graphics\Graphics\$output
$output
Output filename.
Definition
Graphics.php:50
Depage\Graphics\Graphics\getPageNumber
getPageNumber()
getPageNumber
Definition
Graphics.php:540
Depage\Graphics\Graphics\render
render($input, $output=null)
Main method for image handling.
Definition
Graphics.php:347
Depage\Graphics\Graphics\optimizeImage
optimizeImage($filename)
Opimizes final image through one of the optimization programs.
Definition
Graphics.php:382
Depage\Graphics\Graphics\bypass
bypass()
Runs bypass (copies file).
Definition
Graphics.php:586
Depage\Graphics\Graphics\unlock
unlock()
unlock
Definition
Graphics.php:414
Depage\Graphics\Graphics\$optimize
$optimize
Optimize output images.
Definition
Graphics.php:82
Depage\Graphics\Providers\Graphicsmagick
GraphicsMagick interface.
Definition
Graphicsmagick.php:20
Depage\Graphics\Providers\Graphicsmagick\getBackground
getBackground()
Generates background command.
Definition
Graphicsmagick.php:135
Depage\Graphics\Providers\Graphicsmagick\getImageSize
getImageSize()
Determine size of input image.
Definition
Graphicsmagick.php:51
Depage\Graphics\Providers\Graphicsmagick\render
render($input, $output=null)
Main method for image handling.
Definition
Graphicsmagick.php:81
Depage\Graphics\Providers\Graphicsmagick\crop
crop($width, $height, $x=0, $y=0)
Crop action.
Definition
Graphicsmagick.php:32
Depage\Graphics\Providers\Imagemagick
ImageMagick interface.
Definition
Imagemagick.php:23
Depage\Graphics\Providers\Imagemagick\getQuality
getQuality()
Generates quality command.
Definition
Imagemagick.php:318
Depage\Graphics\Providers\Imagemagick\getOptimize
getOptimize()
Generates optimization parameters.
Definition
Imagemagick.php:335
Depage\Graphics\Providers\Imagemagick\execCommand
execCommand()
Executes ImageMagick command.
Definition
Imagemagick.php:238
Providers
Graphicsmagick.php
Generated on
for depage-graphics by
doxygen
1.18.0
For an overview of all docs, go to
docs.depage.net