Skip to content

Commit 0428533

Browse files
joshp23MASNathan
authored andcommitted
Add render delay option (#76)
* Adds delay option * adds delay
1 parent 74ba54e commit 0428533

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/Capture.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ class Capture
8383
* @var int
8484
*/
8585
protected $timeout = 0;
86+
87+
/**
88+
* Sets the delay period
89+
*
90+
* @var int
91+
*/
92+
protected $delay = 0;
8693

8794
/**
8895
* Bin directory, should contain the phantomjs file, otherwise it won't work
@@ -203,6 +210,10 @@ public function save($imageLocation, $deleteFileIfExists = true)
203210
if ($this->timeout) {
204211
$data['timeout'] = $this->timeout;
205212
}
213+
214+
if ($this->delay) {
215+
$data['delay'] = $this->delay;
216+
}
206217

207218
if ($this->includedJsScripts) {
208219
$data['includedJsScripts'] = $this->includedJsScripts;
@@ -441,6 +452,23 @@ public function setTimeout($timeout)
441452
return $this;
442453
}
443454

455+
/**
456+
* Sets the delay period
457+
*
458+
* @param int $delay Delay period
459+
*
460+
* @return Capture
461+
* @throws InvalidArgumentException
462+
*/
463+
public function setDelay($delay)
464+
{
465+
if (!is_numeric($delay)) {
466+
throw new InvalidArgumentException('The delay value must be a number.');
467+
}
468+
$this->delay = $delay;
469+
470+
return $this;
471+
}
444472
/**
445473
* Adds a JS script or snippet to the screen shot script
446474
*

templates/screen-capture.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
<?php endif ?>
4242
});
4343

44-
page.render('<?php echo $imageLocation ?>');
45-
phantom.exit();
44+
setTimeout(function() {
45+
page.render('<?php echo $imageLocation ?>');
46+
phantom.exit();
47+
}, <?php echo (isset($delay) ? $delay : 0); ?>);
4648
});

0 commit comments

Comments
 (0)