3 namespace Zumba\GastonJS\Browser;
6 * Trait BrowserRenderTrait
7 * @package Zumba\GastonJS\Browser
9 trait BrowserRenderTrait {
11 * Check and fix render options
15 protected function checkRenderOptions($options) {
16 //Default is full and no selection
17 if (count($options) === 0) {
18 $options["full"] = true;
19 $options["selector"] = null;
22 if (isset($options["full"]) && isset($options["selector"])) {
23 if ($options["full"]) {
24 //Whatever it is, full is more powerful than selection
25 $options["selector"] = null;
28 if (!isset($options["full"]) && isset($options["selector"])) {
29 $options["full"] = false;
36 * Renders a page or selection to a file given by path
38 * @param array $options
41 public function render($path, $options = array()) {
42 $fixedOptions = $this->checkRenderOptions($options);
43 return $this->command('render', $path, $fixedOptions["full"], $fixedOptions["selector"]);
47 * Renders base64 a page or selection to a file given by path
48 * @param string $imageFormat (PNG, GIF, JPEG)
49 * @param array $options
52 public function renderBase64($imageFormat, $options = array()) {
53 $fixedOptions = $this->checkRenderOptions($options);
54 return $this->command('render_base64', $imageFormat, $fixedOptions["full"], $fixedOptions["selector"]);
58 * Sets the paper size, useful when saving to PDF
62 public function setPaperSize($paperSize) {
63 return $this->command('set_paper_size', $paperSize);