mirror of
https://github.com/Intervention/image.git
synced 2025-08-30 09:10:21 +02:00
added opacity method
This commit is contained in:
@@ -54,6 +54,7 @@ Add the facade of this package to the `$aliases` array.
|
||||
* Image::crop - Crop the current image
|
||||
* Image::grab - Cut out a detail of the image in given ratio and resize to output size
|
||||
* Image::resizeCanvas - Resize image boundaries
|
||||
* Image::opacity - Set opacity of current image
|
||||
* Image::mask - Apply given image as alpha mask on current image
|
||||
* Image::insert - Insert another image on top of the current image
|
||||
* Image::brightness - Changes brightness of current image (-100 = min brightness, 0 = no change, +100 = max brightness)
|
||||
@@ -224,6 +225,9 @@ $img->mask('public/mask.png', true);
|
||||
// rotate image 90° clockwise
|
||||
$img->rotate(90);
|
||||
|
||||
// set 75% opacity
|
||||
$img->opacity(75);
|
||||
|
||||
// flip image horizontally
|
||||
$img->flip('h');
|
||||
|
||||
|
@@ -678,6 +678,30 @@ class Image
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set opacity of current image
|
||||
*
|
||||
* @param integer $value
|
||||
* @return Image
|
||||
*/
|
||||
public function opacity($value)
|
||||
{
|
||||
if ($value >= 0 && $value <= 100) {
|
||||
$value = intval($value) / 100;
|
||||
} else {
|
||||
throw new Exception('Opacity must be between 0 and 100');
|
||||
}
|
||||
|
||||
// create alpha mask
|
||||
$alpha = new self(null, $this->width, $this->height);
|
||||
$alpha->fill(sprintf('rgba(0, 0, 0, %.1f)', $value));
|
||||
|
||||
// apply alpha mask
|
||||
$this->mask($alpha, true);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply given image as alpha mask on current image
|
||||
*
|
||||
@@ -1128,7 +1152,8 @@ class Image
|
||||
/**
|
||||
* Save image in filesystem
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $path
|
||||
* @param integer $quality
|
||||
* @return Image
|
||||
*/
|
||||
public function save($path = null, $quality = 90)
|
||||
|
@@ -435,6 +435,28 @@ class ImageTest extends PHPUnit_Framework_Testcase
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
}
|
||||
|
||||
public function testOpacity()
|
||||
{
|
||||
// simple image mask
|
||||
$img = Image::make('public/test.jpg');
|
||||
$img->resize(32, 32)->opacity(50);
|
||||
$this->assertInstanceOf('Intervention\Image\Image', $img);
|
||||
$this->assertInternalType('int', $img->width);
|
||||
$this->assertInternalType('int', $img->height);
|
||||
$this->assertEquals($img->width, 32);
|
||||
$this->assertEquals($img->height, 32);
|
||||
$checkColor = $img->pickColor(15, 15, 'array');
|
||||
$this->assertEquals($checkColor['red'], 254);
|
||||
$this->assertEquals($checkColor['green'], 204);
|
||||
$this->assertEquals($checkColor['blue'], 112);
|
||||
$this->assertEquals($checkColor['alpha'], 64);
|
||||
$checkColor = $img->pickColor(31, 31, 'array');
|
||||
$this->assertEquals($checkColor['red'], 255);
|
||||
$this->assertEquals($checkColor['green'], 166);
|
||||
$this->assertEquals($checkColor['blue'], 0);
|
||||
$this->assertEquals($checkColor['alpha'], 64);
|
||||
}
|
||||
|
||||
public function testMaskImage()
|
||||
{
|
||||
// simple image mask
|
||||
|
Reference in New Issue
Block a user