Test Failed
Push — master ( 398493...d4ef72 )
by Michael
11:04
created

TTF   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A writeText() 0 23 2
A __construct() 0 5 1
1
<?php
2
	/**
3
##DOC-SIGNATURE##
4
5
    This file is part of WideImage.
6
		
7
    WideImage is free software; you can redistribute it and/or modify
8
    it under the terms of the GNU Lesser General Public License as published by
9
    the Free Software Foundation; either version 2.1 of the License, or
10
    (at your option) any later version.
11
		
12
    WideImage is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU Lesser General Public License for more details.
16
		
17
    You should have received a copy of the GNU Lesser General Public License
18
    along with WideImage; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21
    * @package WideImage
22
  **/
23
24
namespace WideImage\Font;
25
26
use WideImage\Coordinate;
27
28
/**
29
 * TTF font support class
30
 * 
31
 * @package WideImage
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
	 * Writes text onto an image
48
	 * 
49
	 * @param \WideImage\Image $image
50
	 * @param mixed $x smart coordinate
51
	 * @param mixed $y smart coordinate
52
	 * @param string $text
53
	 * @param int $angle Angle in degrees clockwise
54
	 */
55
	public function writeText($image, $x, $y, $text, $angle = 0)
56
	{
57
		if ($image->isTrueColor()) {
58
			$image->alphaBlending(true);
0 ignored issues
show
Bug introduced by
The method alphaBlending() does not exist on WideImage\Image. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
			$image->/** @scrutinizer ignore-call */ 
59
           alphaBlending(true);
Loading history...
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']);
0 ignored issues
show
Bug introduced by
$obox['width'] of type double is incompatible with the type integer expected by parameter $sec_dim of WideImage\Coordinate::fix(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

71
		$x = Coordinate::fix($x, $image->getWidth(), /** @scrutinizer ignore-type */ $obox['width']);
Loading history...
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