| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: |
|
| 23: |
|
| 24: | namespace WideImage\Font;
|
| 25: |
|
| 26: | use WideImage\Coordinate;
|
| 27: |
|
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: |
|
| 33: | class TTF
|
| 34: | {
|
| 35: | public $face;
|
| 36: | public $size;
|
| 37: | public $color;
|
| 38: |
|
| 39: | public function __construct($face, $size, $color)
|
| 40: | {
|
| 41: | $this->face = $face;
|
| 42: | $this->size = $size;
|
| 43: | $this->color = $color;
|
| 44: | }
|
| 45: |
|
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: |
|
| 55: | public function writeText($image, $x, $y, $text, $angle = 0)
|
| 56: | {
|
| 57: | if ($image->isTrueColor()) {
|
| 58: | $image->alphaBlending(true);
|
| 59: | }
|
| 60: |
|
| 61: | $box = imageftbbox($this->size, $angle, $this->face, $text);
|
| 62: | $obox = array(
|
| 63: | 'left' => min($box[0], $box[2], $box[4], $box[6]),
|
| 64: | 'top' => min($box[1], $box[3], $box[5], $box[7]),
|
| 65: | 'right' => max($box[0], $box[2], $box[4], $box[6]) - 1,
|
| 66: | 'bottom' => max($box[1], $box[3], $box[5], $box[7]) - 1
|
| 67: | );
|
| 68: | $obox['width'] = abs($obox['left']) + abs($obox['right']);
|
| 69: | $obox['height'] = abs($obox['top']) + abs($obox['bottom']);
|
| 70: |
|
| 71: | $x = Coordinate::fix($x, $image->getWidth(), $obox['width']);
|
| 72: | $y = Coordinate::fix($y, $image->getHeight(), $obox['height']);
|
| 73: |
|
| 74: | $fixed_x = $x - $obox['left'];
|
| 75: | $fixed_y = $y - $obox['top'];
|
| 76: |
|
| 77: | imagettftext($image->getHandle(), $this->size, $angle, $fixed_x, $fixed_y, $this->color, $this->face, $text);
|
| 78: | }
|
| 79: | }
|
| 80: | |