Skip to content

Commit

Permalink
Added opacity filter
Browse files Browse the repository at this point in the history
  • Loading branch information
claviska committed Jan 20, 2017
1 parent aa6f05f commit c584537
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ try {
- Reads and writes files, data URIs, and image strings.
- Manipulation: crop, resize, overlay/watermark, adding TTF text
- Drawing: arc, border, dot, ellipse, line, polygon, rectangle, rounded rectangle
- Filters: blur, brighten, colorize, contrast, darken, desaturate, edge detect, emboss, invert, pixelate, sepia, sharpen, sketch
- Filters: blur, brighten, colorize, contrast, darken, desaturate, edge detect, emboss, invert, opacity, pixelate, sepia, sharpen, sketch
- Utilities: color adjustment, darken/lighten color, extract colors
- Properties: exif data, height/width, mime type, orientation
- Color arguments can be passed in as any CSS color (e.g. `LightBlue`), a hex color, or an RGB(A) array.
Expand Down Expand Up @@ -542,6 +542,14 @@ Inverts the image's colors.

Returns a SimpleImage object.

#### `opacity()`

Changes the image's opacity level.

- `$opacity`* (float) - The desired opacity level (0 - 1).

Returns a SimpleImage object.

#### `pixelate($size)`

Applies the pixelate filter.
Expand Down
26 changes: 26 additions & 0 deletions src/claviska/SimpleImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,32 @@ public function invert() {
return $this;
}

//
// Changes the image's opacity level.
//
// $opacity* (float) - The desired opacity level (0 - 1).
//
// Returns a SimpleImage object.
//
public function opacity($opacity) {
// Create a transparent image
$newImage = new SimpleImage();
$newImage->fromNew($this->getWidth(), $this->getHeight());

// Copy the current image (with opacity) onto the transparent image
self::imageCopyMergeAlpha(
$newImage->image,
$this->image,
$x, $y,
0, 0,
$this->getWidth(),
$this->getHeight(),
self::keepWithin($opacity, 0, 1) * 100
);

return $this;
}

//
// Applies the pixelate filter.
//
Expand Down

0 comments on commit c584537

Please sign in to comment.