Skip to content

Commit

Permalink
Added backgroundColor method
Browse files Browse the repository at this point in the history
  • Loading branch information
bartko-s committed Jan 19, 2014
1 parent d07843e commit 25bdc8a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ This is output
```
$width = 350;
$height = 150;
$color = array(35, 210, 240);
$resizer = new \StefanoImage\Image();
$resizer->sourceImage($sourceImage)
->pad($width, $height, $color)
->pad($width, $height)
->backgroundColor(35, 210, 240)
->save($outputDir, $name);
```

Expand Down
6 changes: 2 additions & 4 deletions src/StefanoImage/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function clearWatermarks() {
return $this;
}

private function backgroundColor($red, $green, $blue) {
public function backgroundColor($red, $green, $blue) {
$this->bacgroundColor = array(
'red' => (int) $red,
'green' => (int) $green,
Expand Down Expand Up @@ -116,15 +116,13 @@ public function adaptiveResize($width, $height) {
return $this;
}

public function pad($width, $height, $color = array(200, 200, 200)) {
public function pad($width, $height) {
$this->maxOutputWidth = (int) $width;
$this->maxOutputHeight = (int) $height;
$this->adaptOutputResolution = false;

$this->keepSourceImageAspectRatio = true;

$this->backgroundColor($color[0], $color[1], $color[2]);

return $this;
}

Expand Down
13 changes: 10 additions & 3 deletions src/StefanoImage/ImageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ public function adaptiveResize($width, $height);
/**
* @param int $width
* @param int $height
* @param array|null $color
* @return self
*/
public function pad($width, $height, $color = array(200, 200, 200));

public function pad($width, $height);

/**
* @param int $red
* @param int $green
* @param int $blue
* @return self
*/
public function backgroundColor($red, $green, $blue);

/**
* @param int $quality form 1 to 100
* @return self
Expand Down
5 changes: 3 additions & 2 deletions tests/StefanoImageTest/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function testDefaultBackgroundColor() {

$image = new Image($adapterMock);
$image->sourceImage($sourceImagePath)
->pad(100, 100, array(200, 200, 200))
->pad(100, 100)
->save($targetPath, $newName);
}

Expand All @@ -272,7 +272,8 @@ public function testChangeBackgroundColor() {

$image = new Image($adapterMock);
$image->sourceImage($sourceImagePath)
->pad(100, 100, array(125, 250, 75))
->pad(100, 100)
->backgroundColor(125, 250, 75)
->save($targetPath, $newName);
}

Expand Down

0 comments on commit 25bdc8a

Please sign in to comment.