/** * Writes the Error on the picture. * * @param Exception $exception */ public function drawException($exception) { $this->w = 1; $this->h = 1; $this->init(); // Is the image big enough? $w = imagesx($this->im); $h = imagesy($this->im); $text = 'Error: ' . $exception->getMessage(); $width = imagefontwidth(2) * strlen($text); $height = imagefontheight(2); if ($width > $w || $height > $h) { $width = max($w, $width); $height = max($h, $height); // We change the size of the image $newimg = imagecreatetruecolor($width, $height); imagefill($newimg, 0, 0, imagecolorat($this->im, 0, 0)); imagecopy($newimg, $this->im, 0, 0, 0, 0, $w, $h); $this->im = $newimg; } $black = new BCGColor('black'); imagestring($this->im, 2, 0, 0, $text, $black->allocate($this->im)); }
/** * Returns class of BCGColor depending of the string color * * If the color doens't exist, it takes the default one. * * @param string $code * @param string $default */ function getColor($code, $default = 'white') { // static switch (strtolower($code)) { case '': case 'white': return 0xffffff; case 'black': return 0x0; case 'maroon': return 0x800000; case 'red': return 0xff0000; case 'orange': return 0xffa500; case 'yellow': return 0xffff00; case 'olive': return 0x808000; case 'purple': return 0x800080; case 'fuchsia': return 0xff00ff; case 'lime': return 0xff00; case 'green': return 0x8000; case 'navy': return 0x80; case 'blue': return 0xff; case 'aqua': return 0xffff; case 'teal': return 0x8080; case 'silver': return 0xc0c0c0; case 'gray': return 0x808080; default: return BCGColor::getColor($default, 'white'); } }