diff options
Diffstat (limited to 'kohana/libraries')
-rw-r--r-- | kohana/libraries/Image.php | 29 | ||||
-rw-r--r-- | kohana/libraries/drivers/Image.php | 7 | ||||
-rw-r--r-- | kohana/libraries/drivers/Image/GD.php | 22 | ||||
-rw-r--r-- | kohana/libraries/drivers/Image/GraphicsMagick.php | 10 | ||||
-rw-r--r-- | kohana/libraries/drivers/Image/ImageMagick.php | 10 |
5 files changed, 78 insertions, 0 deletions
diff --git a/kohana/libraries/Image.php b/kohana/libraries/Image.php index bd723a27..6fcce090 100644 --- a/kohana/libraries/Image.php +++ b/kohana/libraries/Image.php @@ -255,6 +255,35 @@ class Image_Core { } /** + * Overlay a second image on top of this one. + * + * @throws Kohana_Exception + * @param string $overlay_file path to an image file + * @param integer $x x offset for the overlay + * @param integer $y y offset for the overlay + * @param integer $transparency transparency percent + */ + public function composite($overlay_file, $x, $y, $transparency) + { + $image_info = getimagesize($overlay_file); + + // Check to make sure the image type is allowed + if ( ! isset(Image::$allowed_types[$image_info[2]])) + throw new Kohana_Exception('image.type_not_allowed', $overlay_file); + + $this->actions['composite'] = array + ( + 'overlay_file' => $overlay_file, + 'mime' => $image_info['mime'], + 'x' => $x, + 'y' => $y, + 'transparency' => $transparency + ); + + return $this; + } + + /** * Flip an image horizontally or vertically. * * @throws Kohana_Exception diff --git a/kohana/libraries/drivers/Image.php b/kohana/libraries/drivers/Image.php index 0f900c74..33f0f940 100644 --- a/kohana/libraries/drivers/Image.php +++ b/kohana/libraries/drivers/Image.php @@ -146,4 +146,11 @@ abstract class Image_Driver { */ abstract public function sharpen($amount); + /** + * Overlay a second image. Valid properties are: overlay_file, mime, x, y and transparency. + * + * @return boolean + */ + abstract public function composite($properties); + } // End Image Driver
\ No newline at end of file diff --git a/kohana/libraries/drivers/Image/GD.php b/kohana/libraries/drivers/Image/GD.php index c3789b6d..24657c56 100644 --- a/kohana/libraries/drivers/Image/GD.php +++ b/kohana/libraries/drivers/Image/GD.php @@ -331,6 +331,28 @@ class Image_GD_Driver extends Image_Driver { return imageconvolution($this->tmp_image, $matrix, $amount - 8, 0); } + public function composite($properties) + { + switch($properties['mime']) + { + case "image/jpeg": + $overlay_img = imagecreatefromjpeg($properties['overlay_file']); + break; + + case "image/gif": + $overlay_img = imagecreatefromgif($properties['overlay_file']); + break; + + case "image/png": + $overlay_img = imagecreatefrompng($properties['overlay_file']); + break; + } + + imagecopymerge($this->tmp_image, $overlay_img, $properties['x'], $properties['y'], 0, 0, imagesx($overlay_img), imagesy($overlay_img), $properties['transparency']); + imagedestroy($overlay_img); + return TRUE; + } + protected function properties() { return array(imagesx($this->tmp_image), imagesy($this->tmp_image)); diff --git a/kohana/libraries/drivers/Image/GraphicsMagick.php b/kohana/libraries/drivers/Image/GraphicsMagick.php index 8840eb80..a8bc4d9b 100644 --- a/kohana/libraries/drivers/Image/GraphicsMagick.php +++ b/kohana/libraries/drivers/Image/GraphicsMagick.php @@ -203,6 +203,16 @@ class Image_GraphicsMagick_Driver extends Image_Driver { return TRUE; } + public function composite($properties) + { + if ($error = exec(escapeshellcmd($this->dir.'gm'.$this->ext.' composite').' -geometry ' . escapeshellarg('+'.$properties['x'].'+'.$properties['y']).' -dissolve '.escapeshellarg($properties['transparency']).' '.escapeshellarg($properties['overlay_file']).' '.$this->cmd_image.' '.$this->cmd_image)) + { + $this->errors[] = $error; + return FALSE; + } + return TRUE; + } + protected function properties() { return array_slice(getimagesize($this->tmp_image), 0, 2, FALSE); diff --git a/kohana/libraries/drivers/Image/ImageMagick.php b/kohana/libraries/drivers/Image/ImageMagick.php index 3397e1d0..497dd8c4 100644 --- a/kohana/libraries/drivers/Image/ImageMagick.php +++ b/kohana/libraries/drivers/Image/ImageMagick.php @@ -204,6 +204,16 @@ class Image_ImageMagick_Driver extends Image_Driver { return TRUE; } + public function composite($properties) + { + if ($error = exec(escapeshellcmd($this->dir.'composite'.$this->ext).' -geometry ' . escapeshellarg('+'.$properties['x'].'+'.$properties['y']).' -dissolve '.escapeshellarg($properties['transparency']).' '.escapeshellarg($properties['overlay_file']).' '.$this->cmd_image.' '.$this->cmd_image)) + { + $this->errors[] = $error; + return FALSE; + } + return TRUE; + } + protected function properties() { return array_slice(getimagesize($this->tmp_image), 0, 2, FALSE); |