/usr/share/php/Horde/Image/Effect/Gd/TextWatermark.php is in php-horde-image 2.5.2-1.
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | <?php
/**
* Copyright 2007-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
* @package Image
*/
/**
* Image effect for watermarking images with text.
*
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @category Horde
* @copyright 2007-2017 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL-2.1
* @package Image
*/
class Horde_Image_Effect_Gd_TextWatermark extends Horde_Image_Effect
{
/**
* Valid parameters for watermark effects:
* - text: [REQUIRED] (string) The text of the watermark.
* - halign: (string) The horizontal placement
* - valign: (string) The vertical placement
* - font: (string) The font name or family to use
* - fontsize: (string) The size of the font to use (small, medium,
* large, giant)
*
* @var array
*/
protected $_params = array(
'halign' => 'right',
'valign' => 'bottom',
'font' => 'courier',
'fontsize' => 'small'
);
/**
* Applies the effect.
*/
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;
}
}
}
|