ImageException::getImage()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Imagecow;
4
5
/**
6
 * Exception class to manage the image errors.
7
 */
8
class ImageException extends \Exception
9
{
10
    /**
11
     * Generate an image with the message printed. Use always the Gd library.
12
     *
13
     * @param int $width  Width of the image
14
     * @param int $height Height of the image
15
     *
16
     * @return Image
17
     */
18
    public function getImage($width = 400, $height = 400)
19
    {
20
        $image = imagecreatetruecolor($width, $height);
21
        $textColor = imagecolorallocate($image, 255, 255, 255);
22
23
        foreach (str_split($this->getMessage(), intval($width / 10)) as $line => $text) {
24
            imagestring($image, 5, 10, (($line + 1) * 18), $text, $textColor);
25
        }
26
27
        return new Image(new Libs\Gd($image));
28
    }
29
}
30