PHP Class mikehaertl\wkhtmlto\Image

This class is a slim wrapper around wkhtmltoimage.
Author: Michael Härtl ([email protected])
Show file Open project: mikehaertl/phpwkhtmltopdf Class Usage Examples

Public Properties

Property Type Description
$binary the name of the wkhtmltoimage binary. Default is wkhtmltoimage. You can also configure a full path here.
$commandOptions options to pass to the Command constructor. Default is none.
$ignoreWarnings whether to ignore any errors if some PDF file was still created. Default is false.
$tmpDir the directory to use for temporary files. If null (default) the dir is autodetected.
$type the image type. Default is 'png'. Other options are 'jpg' and 'bmp'.

Protected Properties

Property Type Description
$_command the command instance that executes wkhtmltopdf
$_error the detailed error message. Empty string if none.
$_isCreated whether the PDF was created
$_options options for wkhtmltoimage as array('--opt1', '--opt2'=>'val', ...)
$_page the page input or a File instance for HTML string inputs
$_tmpImageFile the temporary image file

Public Methods

Method Description
__construct ( array | string $options = null )
getCommand ( ) : Command
getError ( ) : string
getImageFilename ( ) : string
getMimeType ( ) : string
saveAs ( string $filename ) : boolean Save the image to given filename (triggers image creation)
send ( string | null $filename = null, boolean $inline = false ) : boolean Send image to client, either inline or as download (triggers image creation)
setOptions ( array $options = [] ) : static Set options
setPage ( string $page ) : static Add a page object to the output

Protected Methods

Method Description
createImage ( ) : boolean Run the Command to create the tmp image file

Method Details

__construct() public method

public __construct ( array | string $options = null )
$options array | string global options for wkhtmltoimage, a page URL, a HTML string or a filename

createImage() protected method

Run the Command to create the tmp image file
protected createImage ( ) : boolean
return boolean whether creation was successful

getCommand() public method

public getCommand ( ) : Command
return Command the command instance that executes wkhtmltopdf

getError() public method

public getError ( ) : string
return string the detailed error message. Empty string if none.

getImageFilename() public method

public getImageFilename ( ) : string
return string the filename of the temporary image file

getMimeType() public method

public getMimeType ( ) : string
return string the mime type for the current image

saveAs() public method

Save the image to given filename (triggers image creation)
public saveAs ( string $filename ) : boolean
$filename string to save image as
return boolean whether image was created successfully

send() public method

Send image to client, either inline or as download (triggers image creation)
public send ( string | null $filename = null, boolean $inline = false ) : boolean
$filename string | null the filename to send. If empty, the PDF is streamed inline. Note, that the file extension must match what you configured as $type (png, jpg, ...).
$inline boolean whether to force inline display of the image, even if filename is present.
return boolean whether image was created successfully

setOptions() public method

Set options
public setOptions ( array $options = [] ) : static
$options array list of image options to set as name/value pairs
return static the Image instance for method chaining

setPage() public method

Add a page object to the output
public setPage ( string $page ) : static
$page string either a URL, a HTML string or a filename
return static the Image instance for method chaining

Property Details

$_command protected property

the command instance that executes wkhtmltopdf
protected $_command

$_error protected property

the detailed error message. Empty string if none.
protected $_error

$_isCreated protected property

whether the PDF was created
protected $_isCreated

$_options protected property

options for wkhtmltoimage as array('--opt1', '--opt2'=>'val', ...)
protected $_options

$_page protected property

the page input or a File instance for HTML string inputs
protected $_page

$_tmpImageFile protected property

the temporary image file
protected $_tmpImageFile

$binary public property

the name of the wkhtmltoimage binary. Default is wkhtmltoimage. You can also configure a full path here.
public $binary

$commandOptions public property

options to pass to the Command constructor. Default is none.
public $commandOptions

$ignoreWarnings public property

whether to ignore any errors if some PDF file was still created. Default is false.
public $ignoreWarnings

$tmpDir public property

the directory to use for temporary files. If null (default) the dir is autodetected.
public $tmpDir

$type public property

the image type. Default is 'png'. Other options are 'jpg' and 'bmp'.
public $type