1: <?php
2: 3: 4: 5: 6: 7:
8: class Horde_Image_Effect_Gd_TextWatermark extends Horde_Image_Effect
9: {
10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22: protected $_params = array('halign' => 'right',
23: 'valign' => 'bottom',
24: 'font' => 'courier',
25: 'fontsize' => 'small');
26: 27: 28:
29: public function apply()
30: {
31: $color = $this->_image->call('imageColorClosest', array($this->_image->_im, 255, 255, 255));
32: $shadow = $this->_image->call('imageColorClosest', array($this->_image->_im, 0, 0, 0));
33:
34:
35: $drop = 1;
36:
37:
38: $maxwidth = 200;
39:
40:
41: $padding = 10;
42:
43: $f = $this->_image->getFont($this->_params['fontsize']);
44: $fontwidth = $this->_image->call('imageFontWidth', array($f));
45: $fontheight = $this->_image->call('imageFontHeight', array($f));
46:
47:
48: $margin = floor($padding + $drop) / 2;
49: if ($maxwidth) {
50: $maxcharsperline = floor(($maxwidth - ($margin * 2)) / $fontwidth);
51: $text = wordwrap($this->_params['text'], $maxcharsperline, "\n", 1);
52: }
53:
54:
55: $lines = explode("\n", $text);
56:
57: switch ($this->_params['valign']) {
58: case 'center':
59: $y = ($this->_image->call('imageSY', array($this->_image->_im)) - ($fontheight * count($lines))) / 2;
60: break;
61:
62: case 'bottom':
63: $y = $this->_image->call('imageSY', array($this->_image->_im)) - (($fontheight * count($lines)) + $margin);
64: break;
65:
66: default:
67: $y = $margin;
68: break;
69: }
70:
71: switch ($this->_params['halign']) {
72: case 'right':
73: foreach ($lines as $line) {
74: $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));
75: $this->_image->call('imageString', array($this->_image->_im, $f, ($this->_image->call('imageSX', array($this->_image->_im)) - $fontwidth * strlen($line)) - $margin, $y, $line, $color));
76: $y += $fontheight;
77: }
78: break;
79:
80: case 'center':
81: foreach ($lines as $line) {
82: $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));
83: $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));
84: $y += $fontheight;
85: }
86: break;
87:
88: default:
89: foreach ($lines as $line) {
90: $this->_image->call('imageString', array($this->_image->_im, $f, $margin + $drop, ($y + $drop), $line, $shadow));
91: $this->_image->call('imageString', array($this->_image->_im, $f, $margin, $y, $line, $color));
92: $y += $fontheight;
93: }
94: break;
95: }
96: }
97:
98: }