Skip to content

Commit c7f0c2e

Browse files
committed
Default background color in case of png is transparent
1 parent f2de905 commit c7f0c2e

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ And the resulted image format
6565
// allowed formats are 'jpg' and 'png', default is 'jpg'.
6666
$screenCapture->setFormat('png');
6767
```
68+
* 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.
6869

6970
And most importantly, save the result
7071
``` php

demo/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ <h2>Give it a test drive...</h2>
9797
<input type="number" class="form-control" name="h" placeholder="768">
9898
</div>
9999

100-
101100
<div class="form-group col-md-6">
102101
<label for="user-agent">User Agent String</label>
103102
<input type="text" class="form-control" name="user-agent"
@@ -115,7 +114,7 @@ <h2>Give it a test drive...</h2>
115114
<div class="col-md-6"></div>
116115
<div class="form-group col-md-3">
117116
<label for="bg-color">Background color</label>
118-
<input type="text" name="bg-color" value="#ffffff" class="form-control color-picker" data-format="hex"/>
117+
<input type="text" name="bg-color" value="" class="form-control color-picker" data-format="hex"/>
119118
</div>
120119

121120
<div class="form-group col-md-3">

src/Capture.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Capture
5454
*
5555
* @var string
5656
*/
57-
protected $backgroundColor = '#FFFFFF';
57+
protected $backgroundColor = '';
5858

5959
/**
6060
* Image format
@@ -135,6 +135,10 @@ public function save($imageLocation, $deleteFileIfExists = true)
135135

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

140144
if ($this->userAgentString) {

0 commit comments

Comments
 (0)