6
6
/**
7
7
* Pdf
8
8
*
9
- * This class is a slim wrapper around wkhtmltoimage.
9
+ * This class is a slim wrapper around ` wkhtmltoimage` .
10
10
*
11
11
* @author Michael Härtl <[email protected] >
12
12
* @license http://www.opensource.org/licenses/MIT
@@ -20,13 +20,14 @@ class Image
20
20
const TMP_PREFIX = 'tmp_wkhtmlto_pdf_ ' ;
21
21
22
22
/**
23
- * @var string the name of the `wkhtmltoimage` binary. Default is `wkhtmltoimage`. You can also
24
- * configure a full path here.
23
+ * @var string the name of the `wkhtmltoimage` binary. Default is
24
+ * `wkhtmltoimage`. You can also configure a full path here.
25
25
*/
26
26
public $ binary = 'wkhtmltoimage ' ;
27
27
28
28
/**
29
- * @var string the image type. Default is 'png'. Other options are 'jpg' and 'bmp'.
29
+ * @var string the image type. Default is 'png'. Other options are 'jpg'
30
+ * and 'bmp'.
30
31
*/
31
32
public $ type = 'png ' ;
32
33
@@ -36,12 +37,14 @@ class Image
36
37
public $ commandOptions = array ();
37
38
38
39
/**
39
- * @var string|null the directory to use for temporary files. If null (default) the dir is autodetected.
40
+ * @var string|null the directory to use for temporary files. If `null`
41
+ * (default) the dir is autodetected.
40
42
*/
41
43
public $ tmpDir ;
42
44
43
45
/**
44
- * @var bool whether to ignore any errors if some PDF file was still created. Default is false.
46
+ * @var bool whether to ignore any errors if some PDF file was still
47
+ * created. Default is `false`.
45
48
*/
46
49
public $ ignoreWarnings = false ;
47
50
@@ -51,12 +54,14 @@ class Image
51
54
protected $ _isCreated = false ;
52
55
53
56
/**
54
- * @var \mikehaertl\tmp\File|string the page input or a File instance for HTML string inputs
57
+ * @var \mikehaertl\tmp\File|string the page input or a `File` instance for
58
+ * HTML string inputs
55
59
*/
56
60
protected $ _page ;
57
61
58
62
/**
59
- * @var array options for wkhtmltoimage as array('--opt1', '--opt2'=>'val', ...)
63
+ * @var array options for `wkhtmltoimage` as `['--opt1', '--opt2' => 'val',
64
+ * ...]`
60
65
*/
61
66
protected $ _options = array ();
62
67
@@ -76,9 +81,10 @@ class Image
76
81
protected $ _error = '' ;
77
82
78
83
/**
79
- * @param array|string $options global options for wkhtmltoimage, a page URL, a HTML string or a filename
84
+ * @param array|string $options global options for wkhtmltoimage, a page
85
+ * URL, a HTML string or a filename
80
86
*/
81
- public function __construct ($ options= null )
87
+ public function __construct ($ options = null )
82
88
{
83
89
if (is_array ($ options )) {
84
90
$ this ->setOptions ($ options );
@@ -119,14 +125,17 @@ public function saveAs($filename)
119
125
}
120
126
121
127
/**
122
- * Send image to client, either inline or as download (triggers image creation)
128
+ * Send image to client, either inline or as download (triggers image
129
+ * creation)
123
130
*
124
- * @param string|null $filename the filename to send. If empty, the PDF is streamed inline. Note, that
125
- * the file extension must match what you configured as $type (png, jpg, ...).
126
- * @param bool $inline whether to force inline display of the image, even if filename is present.
131
+ * @param string|null $filename the filename to send. If empty, the PDF is
132
+ * streamed inline. Note, that the file extension must match what you
133
+ * configured as $type (png, jpg, ...).
134
+ * @param bool $inline whether to force inline display of the image, even
135
+ * if filename is present.
127
136
* @return bool whether image was created successfully
128
137
*/
129
- public function send ($ filename= null ,$ inline= false )
138
+ public function send ($ filename = null ,$ inline = false )
130
139
{
131
140
if (!$ this ->_isCreated && !$ this ->createImage ()) {
132
141
return false ;
@@ -141,9 +150,9 @@ public function send($filename=null,$inline=false)
141
150
* @param array $options list of image options to set as name/value pairs
142
151
* @return static the Image instance for method chaining
143
152
*/
144
- public function setOptions ($ options= array ())
153
+ public function setOptions ($ options = array ())
145
154
{
146
- foreach ($ options as $ key=> $ val ) {
155
+ foreach ($ options as $ key => $ val ) {
147
156
if (is_int ($ key )) {
148
157
$ this ->_options [] = $ val ;
149
158
} elseif ($ key [0 ]!=='_ ' && property_exists ($ this , $ key )) {
@@ -160,7 +169,7 @@ public function setOptions($options=array())
160
169
*/
161
170
public function getCommand ()
162
171
{
163
- if ($ this ->_command ===null ) {
172
+ if ($ this ->_command === null ) {
164
173
$ options = $ this ->commandOptions ;
165
174
if (!isset ($ options ['command ' ])) {
166
175
$ options ['command ' ] = $ this ->binary ;
@@ -183,7 +192,7 @@ public function getError()
183
192
*/
184
193
public function getImageFilename ()
185
194
{
186
- if ($ this ->_tmpImageFile ===null ) {
195
+ if ($ this ->_tmpImageFile === null ) {
187
196
$ this ->_tmpImageFile = new File ('' , '. ' .$ this ->type , self ::TMP_PREFIX );
188
197
}
189
198
return $ this ->_tmpImageFile ->getFileName ();
@@ -195,11 +204,11 @@ public function getImageFilename()
195
204
*/
196
205
public function getMimeType ()
197
206
{
198
- if ($ this ->type ==='jpg ' ) {
207
+ if ($ this ->type === 'jpg ' ) {
199
208
return 'image/jpeg ' ;
200
- } elseif ($ this ->type ==='png ' ) {
209
+ } elseif ($ this ->type === 'png ' ) {
201
210
return 'image/png ' ;
202
- } elseif ($ this ->type ==='bmp ' ) {
211
+ } elseif ($ this ->type === 'bmp ' ) {
203
212
return 'image/bmp ' ;
204
213
} else {
205
214
throw new \Exception ('Invalid image type ' );
0 commit comments