This function is based on phpion's code but with added PNG-24 alpha channel support. Took me a while to figure it out, but imagecopymerge doesn't support transparency (don't ask me) so I had to use imagecopy and turn on imageAlphaBlending (despite what people in PHP manual's comments say). Too bad it couldn't be done in application/ and I had to edit system/ files.
system/libraries/Image.php:
public function watermark(Image $image, $left = 0, $top = 0) { $this->actions['watermark'] = array( 'image' => $image, 'transparency' => (int)$transparency, 'left' => (int)$left, 'top' => (int)$top ); return $this; }
system/libraries/drivers/Image/GD.php:
public function watermark($properties) { $img = $this->tmp_image; switch ($properties['image']->type) { case IMAGETYPE_JPEG: $create = 'imagecreatefromjpeg'; break; case IMAGETYPE_GIF: $create = 'imagecreatefromgif'; break; case IMAGETYPE_PNG: $create = 'imagecreatefrompng'; break; } $watermark = $create($properties['image']->file); imageAlphaBlending($img, true); imagecopy($img, $watermark, $properties['left'], $properties['top'], 0, 0, $properties['image']->width, $properties['image']->height); $this->tmp_image = $img; return $img; }
It's not perfect, I'll have to add some fancy stuff in the future, but for now I can get back to work.
Sajam
Dzisiaj o mało co nie musiałem się z tym zmierzyć ;) Wystarczył CSS. Ale na pewno przyda się w przyszłości ;)