diff --git a/readme.md b/readme.md index 8378c88..e0b51d0 100644 --- a/readme.md +++ b/readme.md @@ -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. @@ -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. diff --git a/src/claviska/SimpleImage.php b/src/claviska/SimpleImage.php index 503edd2..c646dc9 100644 --- a/src/claviska/SimpleImage.php +++ b/src/claviska/SimpleImage.php @@ -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. //