/usr/share/php/Horde/Image/Effect/Gd/TextWatermark.php is in php-horde-image 2.1.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | <?php
/**
* Image effect for watermarking images with text for the GD driver..
*
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @package Image
*/
class Horde_Image_Effect_Gd_TextWatermark extends Horde_Image_Effect
{
/**
* Valid parameters for watermark effects:
*
* text (required) - The text of the watermark.
* halign - The horizontal placement
* valign - The vertical placement
* font - The font name or family to use
* fontsize - The size of the font to use
* (small, medium, large, giant)
*
* @var array
*/
protected $_params = array('halign' => 'right',
'valign' => 'bottom',
'font' => 'courier',
'fontsize' => 'small');
/**
* Add the watermark
*/
public function apply()
{
$color = $this->_image->call('imageColorClosest', array($this->_image->_im, 255, 255, 255));
$shadow = $this->_image->call('imageColorClosest', array($this->_image->_im, 0, 0, 0));
// Shadow offset in pixels.
$drop = 1;
// Maximum text width.
$maxwidth = 200;
// Amount of space to leave between the text and the image border.
$padding = 10;
$f = $this->_image->getFont($this->_params['fontsize']);
$fontwidth = $this->_image->call('imageFontWidth', array($f));
$fontheight = $this->_image->call('imageFontHeight', array($f));
// So that shadow is not off the image with right align and bottom valign.
$margin = floor($padding + $drop) / 2;
if ($maxwidth) {
$maxcharsperline = floor(($maxwidth - ($margin * 2)) / $fontwidth);
$text = wordwrap($this->_params['text'], $maxcharsperline, "\n", 1);
}
// Split $text into individual lines.
$lines = explode("\n", $text);
switch ($this->_params['valign']) {
case 'center':
$y = ($this->_image->call('imageSY', array($this->_image->_im)) - ($fontheight * count($lines))) / 2;
break;
case 'bottom':
$y = $this->_image->call('imageSY', array($this->_image->_im)) - (($fontheight * count($lines)) + $margin);
break;
default:
$y = $margin;
break;
}
switch ($this->_params['halign']) {
case 'right':
foreach ($lines as $line) {
$this->_image->call('imageString', array($this->_image->_im, $f, ($this->_image->call('imageSX', array($this->_image->_im)) - $fontwidth * strlen($line)) - $margin + $drop, ($y + $drop), $line, $shadow));
$this->_image->call('imageString', array($this->_image->_im, $f, ($this->_image->call('imageSX', array($this->_image->_im)) - $fontwidth * strlen($line)) - $margin, $y, $line, $color));
$y += $fontheight;
}
break;
case 'center':
foreach ($lines as $line) {
$this->_image->call('imageString', array($this->_image->_im, $f, floor(($this->_image->call('imageSX', array($this->_image->_im)) - $fontwidth * strlen($line)) / 2) + $drop, ($y + $drop), $line, $shadow));
$this->_image->call('imageString', array($this->_image->_im, $f, floor(($this->_image->call('imageSX', array($this->_image->_im)) - $fontwidth * strlen($line)) / 2), $y, $line, $color));
$y += $fontheight;
}
break;
default:
foreach ($lines as $line) {
$this->_image->call('imageString', array($this->_image->_im, $f, $margin + $drop, ($y + $drop), $line, $shadow));
$this->_image->call('imageString', array($this->_image->_im, $f, $margin, $y, $line, $color));
$y += $fontheight;
}
break;
}
}
}
|