Skip to content

Commit

Permalink
Default background color in case of png is transparent
Browse files Browse the repository at this point in the history
  • Loading branch information
MASNathan committed Jul 28, 2016
1 parent f2de905 commit c7f0c2e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -65,6 +65,7 @@ And the resulted image format
// allowed formats are 'jpg' and 'png', default is 'jpg'.
$screenCapture->setFormat('png');
```
* If the format is ```jpg``` and the background color is not set, the default value will be ```#FFFFFF```, if ```png``` the default background color will be transparent.

And most importantly, save the result
``` php
Expand Down
3 changes: 1 addition & 2 deletions demo/index.html
Expand Up @@ -97,7 +97,6 @@ <h2>Give it a test drive...</h2>
<input type="number" class="form-control" name="h" placeholder="768">
</div>


<div class="form-group col-md-6">
<label for="user-agent">User Agent String</label>
<input type="text" class="form-control" name="user-agent"
Expand All @@ -115,7 +114,7 @@ <h2>Give it a test drive...</h2>
<div class="col-md-6"></div>
<div class="form-group col-md-3">
<label for="bg-color">Background color</label>
<input type="text" name="bg-color" value="#ffffff" class="form-control color-picker" data-format="hex"/>
<input type="text" name="bg-color" value="" class="form-control color-picker" data-format="hex"/>
</div>

<div class="form-group col-md-3">
Expand Down
6 changes: 5 additions & 1 deletion src/Capture.php
Expand Up @@ -54,7 +54,7 @@ class Capture
*
* @var string
*/
protected $backgroundColor = '#FFFFFF';
protected $backgroundColor = '';

/**
* Image format
Expand Down Expand Up @@ -135,6 +135,10 @@ public function save($imageLocation, $deleteFileIfExists = true)

if ($this->backgroundColor) {
$data['backgroundColor'] = $this->backgroundColor;
} elseif ($this->getFormat() == 'jpg') {
// If there is no background color set, and it's a jpeg
// we need to set a bg color, otherwise the background will be black
$data['backgroundColor'] = '#FFFFFF';
}

if ($this->userAgentString) {
Expand Down

0 comments on commit c7f0c2e

Please sign in to comment.