public function __construct($message, $iWidth = null, $iHeight = null) { $iFont = 2; if ($message instanceof Exception) { $message = $message->getMessage(); if (defined('DEBUG') && DEBUG) { $message .= "\n" . $message->getTraceAsString(); } } // calculate image size if ($iWidth == null || $iHeight != null) { $aMessage = explode("\n", $message); $iFontWidth = imagefontwidth($iFont); $iFontHeight = imagefontheight($iFont); foreach ($aMessage as $sLine) { $iHeight += $iFontHeight + 1; $iMessageWidth = $iFontWidth * (strlen($sLine) + 1); if ($iMessageWidth > $iWidth) { $iWidth = $iMessageWidth; } } $iHeight += 8; } parent::__construct($iWidth, $iHeight); $iFontColor = $this->getColor(255, 0, 0); $iBorderColor = $this->getColor(255, 0, 0); $iBGColor = $this->getColor(255, 255, 255); $iPadding = 4; $this->fill(0, 0, $iBGColor); $this->drawRectangle(0, 0, $this->getWidth() - 1, $this->getHeight() - 1, $iBorderColor); $this->drawText($message, $iFont, $iFontColor, $iPadding, $iPadding); }
function __construct() { session_start(); //---- header("Content-type: image/gif"); header("Expires: Mon, 1 Jun 1999 01:00:00 GMT"); //---- if (!function_exists('imagecreate')) { readfile('i/0.gif'); exit; } //---- $im = imagecreate(59, 22); //---- $bg = imagecolorallocate($im, 0xff, 0xff, 0xff); $black = imagecolorallocate($im, 0x62, 0x63, 0x63); //---- $verify_code = trim($_SESSION['verify_code']); $len = strlen($verify_code); //---- $x = 3; $y = 3; $w = imagefontwidth(5); mt_srand($this->MakeSeed()); //---- for ($i = 0; $i < $len; ++$i) { imagestring($im, 5, $x, $y + mt_rand(0, 4) - 2, $verify_code[$i], $black); //---- $x += $w; } //---- output the image imagegif($im); //---- exit; }
function execute($par) { global $wgRequest, $wgEmailImage; $size = 4; $text = $wgRequest->getText('img'); /* decode this rubbish */ $text = rawurldecode($text); $text = str_rot13($text); $text = base64_decode($text); $text = str_replace($wgEmailImage['ugly'], "", $text); $fontwidth = imagefontwidth($size); $fontheight = imagefontheight($size); $width = strlen($text) * $fontwidth + 4; $height = $fontheight + 2; $im = @imagecreatetruecolor($width, $height) or exit; $trans = imagecolorallocate($im, 0, 0, 0); /* must be black! */ $color = imagecolorallocate($im, 1, 1, 1); /* nearly black ;) */ imagecolortransparent($im, $trans); /* seems to work only with black! */ imagestring($im, $size, 2, 0, $text, $color); //header ("Content-Type: image/png"); imagepng($im); => IE is just so bad! header("Content-Type: image/gif"); imagegif($im); exit; }
/** * Generates image * * @param string $sMac verification code * * @return null */ function generateVerificationImg($sMac) { $iWidth = 80; $iHeight = 18; $iFontSize = 14; if (function_exists('imagecreatetruecolor')) { // GD2 $oImage = imagecreatetruecolor($iWidth, $iHeight); } elseif (function_exists('imagecreate')) { // GD1 $oImage = imagecreate($iWidth, $iHeight); } else { // GD not found return; } $iTextX = ($iWidth - strlen($sMac) * imagefontwidth($iFontSize)) / 2; $iTextY = ($iHeight - imagefontheight($iFontSize)) / 2; $aColors = array(); $aColors["text"] = imagecolorallocate($oImage, 0, 0, 0); $aColors["shadow1"] = imagecolorallocate($oImage, 200, 200, 200); $aColors["shadow2"] = imagecolorallocate($oImage, 100, 100, 100); $aColors["background"] = imagecolorallocate($oImage, 255, 255, 255); $aColors["border"] = imagecolorallocate($oImage, 0, 0, 0); imagefill($oImage, 0, 0, $aColors["background"]); imagerectangle($oImage, 0, 0, $iWidth - 1, $iHeight - 1, $aColors["border"]); imagestring($oImage, $iFontSize, $iTextX + 1, $iTextY + 0, $sMac, $aColors["shadow2"]); imagestring($oImage, $iFontSize, $iTextX + 0, $iTextY + 1, $sMac, $aColors["shadow1"]); imagestring($oImage, $iFontSize, $iTextX, $iTextY, $sMac, $aColors["text"]); header('Content-type: image/png'); imagepng($oImage); imagedestroy($oImage); }
function CenterImageString($image, $image_width, $string, $font_size, $y, $color) { $text_width = imagefontwidth($font_size) * strlen($string); $center = ceil($image_width / 2); $x = $center - ceil($text_width / 2); ImageString($image, $font_size, $x, $y, $string, $color); }
public function drawHeader() { $str = $this->header; $fontnum = $this->sizeX < 500 ? 2 : 4; $x = $this->fullSizeX / 2 - imagefontwidth($fontnum) * strlen($str) / 2; imagestring($this->im, $fontnum, $x, 1, $str, $this->GetColor('Dark Red No Alpha')); }
public static function placeholder($height, $width, $text) { // Dimensions //header ("Content-type: image/png"); $getsize = $height . 'x' . $width; $dimensions = explode('x', $getsize); // Create image $image = imagecreate($dimensions[0], $dimensions[1]); // Colours $bg = 'ccc'; $bg = Image::hex2rgb($bg); $setbg = imagecolorallocate($image, $bg['r'], $bg['g'], $bg['b']); $fg = '555'; $fg = Image::hex2rgb($fg); $setfg = imagecolorallocate($image, $fg['r'], $fg['g'], $fg['b']); // Text //$text = isset($_GET['text']) ? strip_tags($_GET['text']) : $getsize; //$text = str_replace('+', ' ', $text); // Text positioning $fontsize = 4; $fontwidth = imagefontwidth($fontsize); // width of a character $fontheight = imagefontheight($fontsize); // height of a character $length = strlen($text); // number of characters $textwidth = $length * $fontwidth; // text width $xpos = (imagesx($image) - $textwidth) / 2; $ypos = (imagesy($image) - $fontheight) / 2; // Generate text imagestring($image, $fontsize, $xpos, $ypos, $text, $setfg); // Render image imagepng($image); }
function hide($mail, $imgAttr = null) { // chequea si la librería GD esta instalada en el server if (!extension_loaded('gd') || !function_exists('gd_info')) { return $mail; } $filepath = IMAGES_URL . "mail/"; $filename = $filepath . md5($mail) . ".png"; $url = "mail/" . md5($mail) . ".png"; if (!file_exists($filename)) { if (!is_dir($filepath)) { @mkdir($filepath); } /*calculo el tamaño que va a tener la imagen*/ $width = imagefontwidth(3) * strlen($mail); $height = imagefontheight(3); $image = imagecreatetruecolor($width, $height); /*el color rojo lo uso como background transparente*/ $white = imagecolorallocate($image, 255, 255, 255); $fontColor = ImageColorAllocate($image, 88, 88, 90); imagefill($image, 0, 0, $white); imagecolortransparent($image, $white); imagestring($image, 3, 0, 0, $mail, $fontColor); imagepng($image, $filename); imagedestroy($image); } return $this->Html->image($url, $imgAttr); }
function erzeugePlotBalkenHorizontal($width, $barHeight, $filename, $bars) { $height = $barHeight * count($bars); $image = imagecreatetruecolor($width, $height); $black = imagecolorallocate($image, 0, 0, 0); imagefilledrectangle($image, 0, 0, $width, $height, imagecolorallocate($image, 255, 255, 255)); $y = 0; foreach ($bars as $bar) { $c1 = mt_rand(100, 220); $c2 = mt_rand(100, 220); $c3 = mt_rand(100, 220); $color = imagecolorallocate($image, $c1, $c2, $c3); $w = $bar["wert"] * $width; imagefilledrectangle($image, 0, $y, $w, $y + $barHeight, $color); imagerectangle($image, 0, $y, $w, $y + $barHeight, $black); if (imagefontwidth(3) * strlen($bar["beschriftung"]) > $w + 8) { imagestring($image, 3, $w + 4, $y + 3, $bar["beschriftung"], $black); } else { imagestring($image, 3, 4, $y + 3, $bar["beschriftung"], $black); } $y += $barHeight; } imagerectangle($image, 0, 0, $width - 1, $height - 1, $black); imagepng($image, $filename, 0); }
function create_image() { // *** Generate a passcode using md5 // (it will be all lowercase hex letters and numbers *** $md5 = md5(rand(0, 9999)); $pass = substr($md5, 10, 5); // *** Set the session cookie so we know what the passcode is *** $_SESSION["pass"] = $pass; // *** Create the image resource *** $image = ImageCreatetruecolor(100, 20); // *** We are making two colors, white and black *** $clr_white = ImageColorAllocate($image, 255, 255, 255); $clr_black = ImageColorAllocate($image, 0, 0, 0); // *** Make the background black *** imagefill($image, 0, 0, $clr_black); // *** Set the image height and width *** imagefontheight(15); imagefontwidth(15); // *** Add the passcode in white to the image *** imagestring($image, 5, 30, 3, $pass, $clr_white); // *** Throw in some lines to trick those cheeky bots! *** imageline($image, 5, 1, 50, 20, $clr_white); imageline($image, 60, 1, 96, 20, $clr_white); // *** Return the newly created image in jpeg format *** return imagejpeg($image); // *** Just in case... *** imagedestroy($image); }
private function _createScaleBarMap($label, $length) { $font = 1; $fullLabel = $label . ' ' . $this->_getLengthUnit(); $stringWidth = imagefontwidth($font) * strlen($fullLabel); if ($stringWidth > $length) { $width = $stringWidth; } else { $width = $length; } $width += 20; $height = imagefontheight($font) + 20; //@todo drawing of scalebar not work proper for some version GD, rememer to fix it $scaleBarImage = imagecreatetruecolor($width, $height); $transparentColor = imagecolorat($scaleBarImage, 0, 0); imagecolortransparent($scaleBarImage, $transparentColor); $transparent = imagecolorallocatealpha($scaleBarImage, 0, 0, 0, 127); imagefilledrectangle($scaleBarImage, 0, 0, $width, $height, $transparent); $barPosX = round(($width - $length) / 2); $barPosY = $height - 5; $color = imagecolorallocate($scaleBarImage, 1, 0, 0); imageline($scaleBarImage, $barPosX, $barPosY, $barPosX + $length, $barPosY, $color); imageline($scaleBarImage, $barPosX, $barPosY - 3, $barPosX, $barPosY + 3, $color); imageline($scaleBarImage, $barPosX + $length, $barPosY - 3, $barPosX + $length, $barPosY + 3, $color); $stringPosX = round(($width - $stringWidth) / 2); $stringPoxY = 10; imagestring($scaleBarImage, $font, $stringPosX, $stringPoxY, $fullLabel, $color); return $scaleBarImage; }
/** * @name : makeImageF * * Function for create image from text with selected font. * * @param String $text : String to convert into the Image. * @param String $font : Font name of the text. * @param int $W : Width of the Image. * @param int $H : Hight of the Image. * @param int $X : x-coordinate of the text into the image. * @param int $Y : y-coordinate of the text into the image. * @param int $fsize : Font size of text. * @param array $color : RGB color array for text color. * @param array $bgcolor : RGB color array for background. * */ public function createText($text, $font = "CENTURY.TTF", $W = 200, $H = 20, $X = 0, $Y = 100, $fsize = 20, $color = array(0xff, 0xff, 0xff), $bgcolor = array(0xff, 0xff, 0xff)) { $text_color = imagecolorallocate($this->im, $color[0], $color[1], $color[2]); $fontwidth = imagefontwidth($fsize); $center = imagesx($this->im) / 2 - $fontwidth * (strlen($text) / 2); imagettftext($this->im, $fsize, $X, $center - 20, $fsize + 15, $text_color, $font, $text); //imagestring($im, 5, 20, 20, 'See my "selfie review \n @ Robert Cafe"', $textcolor); }
public function build($text = '', $showText = true, $fileName = null) { if (trim($text) <= ' ') { throw new exception('barCode::build - must be passed text to operate'); } if (!($fileType = $this->outMode[$this->mode])) { throw new exception("barCode::build - unrecognized output format ({$this->mode})"); } if (!function_exists("image{$this->mode}")) { throw new exception("barCode::build - unsupported output format ({$this->mode} - check phpinfo)"); } $text = strtoupper($text); $dispText = "* {$text} *"; $text = "*{$text}*"; // adds start and stop chars $textLen = strlen($text); $barcodeWidth = $textLen * (7 * $this->bcThinWidth + 3 * $this->bcThickWidth) - $this->bcThinWidth; $im = imagecreate($barcodeWidth, $this->bcHeight); $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $white); $xpos = 0; for ($idx = 0; $idx < $textLen; $idx++) { if (!($char = $text[$idx])) { $char = '-'; } for ($ptr = 0; $ptr <= 8; $ptr++) { $elementWidth = $this->codeMap[$char][$ptr] ? $this->bcThickWidth : $this->bcThinWidth; if (($ptr + 1) % 2) { imagefilledrectangle($im, $xpos, 0, $xpos + $elementWidth - 1, $this->bcHeight, $black); } $xpos += $elementWidth; } $xpos += $this->bcThinWidth; } if ($showText) { $pxWid = imagefontwidth($this->fontSize) * strlen($dispText) + 10; $pxHt = imagefontheight($this->fontSize) + 2; $bigCenter = $barcodeWidth / 2; $textCenter = $pxWid / 2; imagefilledrectangle($im, $bigCenter - $textCenter, $this->bcHeight - $pxHt, $bigCenter + $textCenter, $this->bcHeight, $white); imagestring($im, $this->fontSize, $bigCenter - $textCenter + 5, $this->bcHeight - $pxHt + 1, $dispText, $black); } if (!$fileName) { header("Content-type: image/{$fileType}"); } switch ($this->mode) { case 'gif': imagegif($im, $fileName); case 'png': imagepng($im, $fileName); case 'jpeg': imagejpeg($im, $fileName); case 'wbmp': imagewbmp($im, $fileName); } imagedestroy($im); }
private function CenterTextBanner($z, $y, $zone) { $a = strlen($z); $b = imagefontwidth($y); $c = $a * $b; $d = $zone - $c; $e = $d / 2; return $e; }
public function getMinSize() { $fts_len = strlen((string) $this->unit) + 1; $this->offset = imagefontwidth(2) * $fts_len; $this->osSum = $this->offset + $this->space; $this->omSum = $this->offset + $this->margin; $this->xLen = $this->width - $this->osSum - $this->omSum; $this->yLen = $this->height - $this->osSum - $this->omSum; return $this->osSum + $this->omSum; }
function centeredtext($image, $text, $font, $x1, $y1, $x2, $y2, $textcolor, $bgcolor, $bordercolor) { imagerectangle($image, $x1, $y1, $x2, $y2, $bordercolor); imagerectangle($image, $x1 + 1, $y1 + 1, $x2 - 1, $y2 - 1, $bgcolor); $width = imagefontwidth($font) * strlen($text); $height = imagefontheight($font); $txtx = ($x2 - $x1 - $width) / 2 + $x1; $txty = ($y2 - $y1 - $height) / 2 + $y1; imagestring($image, $font, $txtx, $txty, $text, $textcolor); }
public function indexAction() { $points = $this->getRequest()->get("quantity"); $currency_id = $this->getRequest()->get("currency"); $currency = Mage::getModel('rewards/currency')->load($currency_id); $skin_dir = Mage::getDesign()->getSkinBaseDir(array('_type' => 'skin')) . "" . DS; $font = $skin_dir . $currency->getFont(); $image = $skin_dir . $currency->getImage(); $doPrintQty = (int) $currency->getImageWriteQuantity() === 1; $imageHeight = (int) $currency->getImageHeight(); $imageWidth = (int) $currency->getImageWidth(); $fontSize = (int) $currency->getFontSize(); $fontColor = (int) $currency->getFontColor(); $im = imageCreateFromPNG($image); $black = imagecolorallocate($im, 0x0, 0x0, 0x0); // Path to our ttf font file $font_file = $font; if ($imageHeight > 0 && $imageWidth > 0) { list($width, $height) = getimagesize($image); $newwidth = $imageWidth; $newheight = $imageHeight; // Load $resized_im = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefrompng($image); // Resize imagecopyresized($resized_im, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); $im = $resized_im; } //TODO: Externilize customization // Draw the text 'PHP Manual' using font size 13 $img_h = $imageHeight == 0 ? imagesy($im) : $imageHeight; $img_w = imagesx($im); $font_size = $fontSize; $text_color = $fontColor; $text = empty($points) ? "" : (int) $points; $offsetx = $currency->getTextOffsetX(); $offsety = $currency->getTextOffsetY(); if (empty($offsetx)) { $offsetx = round($img_w / 2 - strlen($text) * imagefontwidth($font_size) / 2 - 3, 1); if ((int) $text > 99) { $offsetx += 1; } } if (empty($offsety)) { $offsety = round($img_h / 2 + imagefontheight($font_size) / 2, 1); } if ($doPrintQty) { imagefttext($im, $font_size, 0, $offsetx, $offsety, $text_color, $font_file, $text); } // Output image to the browser header('Content-Type: image/png'); imagepng($im); imagedestroy($im); exit; }
public function generateImage() { $this->securityCode = $this->simpleRandString($this->codeLength); $img_path = dirname(__FILE__) . "/../../web/uploads/"; if (!is_writable($img_path) && !is_dir($img_path)) { $error = "The image path {$img_path} does not appear to be writable or the folder does not exist. Please verify your settings"; throw new Exception($error); } $this->img = imagecreatefromjpeg($img_path . $this->imageFile); $img_size = getimagesize($img_path . $this->imageFile); foreach ($this->fontColor as $fcolor) { $color[] = imagecolorallocate($this->img, hexdec(substr($fcolor, 1, 2)), hexdec(substr($fcolor, 3, 2)), hexdec(substr($fcolor, 5, 2))); } $line = imagecolorallocate($this->img, 255, 255, 255); $line2 = imagecolorallocate($this->img, 200, 200, 200); $fw = imagefontwidth($this->fontSize) + 3; $fh = imagefontheight($this->fontSize); // create a new string with a blank space between each letter so it looks better $newstr = ""; for ($i = 0; $i < strlen($this->securityCode); $i++) { $newstr .= $this->securityCode[$i] . " "; } // remove the trailing blank $newstr = trim($newstr); // center the string $x = ($img_size[0] - strlen($newstr) * $fw) / 2; $font[0] = '/usr/share/fonts/truetype/msttcorefonts/arial.ttf'; $font[1] = '/usr/share/fonts/truetype/msttcorefonts/arial.ttf'; $font[2] = '/usr/share/fonts/truetype/msttcorefonts/arial.ttf'; // create random lines over text for ($i = 0; $i < 3; $i++) { $s_x = rand(40, 180); $s_y = rand(5, 35); $e_x = rand($s_x - 50, $s_x + 50); $e_y = rand(5, 35); $c = rand(0, count($color) - 1); imageline($this->img, $s_x, $s_y, $e_x, $e_y, $color[$c]); } // random bg ellipses imageellipse($this->img, $s_x, $s_y, $e_x, $e_y, $line); imageellipse($this->img, $e_x, $e_y, $s_x, $s_y, $line2); // output each character at a random height and standard horizontal spacing for ($i = 0; $i < strlen($newstr); $i++) { $hz = mt_rand(10, $img_size[1] - $fh - 5); // randomize rotation $rotate = rand(-35, 35); // randomize font size $this->fontSize = rand(14, 18); // radomize color $c = rand(0, count($color) - 1); // imagechar( $this->img, $this->fontSize, $x + ($fw*$i), $hz, $newstr[$i], $color); imagettftext($this->img, $this->fontSize, $rotate, $x + $fw * $i, $hz + 12, $color[0], $font[$c], $newstr[$i]); } }
/** * Overloaded method for drawing special label * * @param ressource $im */ protected function DrawText($im) { if ($this->textfont != 0 && $this->a1 != '') { $bar_color = is_null($this->color1) ? NULL : $this->color1->allocate($im); if (!is_null($bar_color)) { $xPosition = $this->positionX / 2 - strlen($this->a1) / 2 * imagefontwidth($this->textfont); $text_color = is_null($this->color1) ? NULL : $this->color1->allocate($im); imagestring($im, $this->textfont, $xPosition, $this->maxHeight, $this->a1, $text_color); } $this->lastY = $this->maxHeight + imagefontheight($this->textfont); } }
function setFont($d) { $d = (int) $d; if ($d < 1) { $d = 1; } if ($d > 5) { $d = 5; } $this->_font = $d; $this->_fontw = imagefontwidth($d); $this->_fonth = imagefontheight($d); }
function Init($dane) { $this->fonttitlesize = $dane['fonttitlesize']; $this->fonttitlewidth = imagefontwidth($this->fonttitlesize); $this->fonttitleheight = imagefontheight($this->fonttitlesize); $this->fontlegendsize = $dane['fontlegendsize']; $this->fontlegendwidth = imagefontwidth($this->fontlegendsize); $this->fontlegendheight = imagefontheight($this->fontlegendsize); $this->width = $this->chart_width = $this->chart_x2 = (int) $dane['width']; $this->height = $this->chart_height = $this->chart_y2 = (int) $dane['height']; $this->chart_x1 = $this->chart_y1 = 0; $this->img = imagecreate($this->width, $this->height); $this->InitColors(); }
public function generateImage($securityCode = NULL) { $context = sfContext::getInstance(); $l = $context->getLogger(); if ($context->getRequest()->getGetParameter('reload') || !$securityCode || sfConfig::get('app_sf_captchagd_force_new_captcha', false)) { $this->securityCode = $this->simpleRandString($this->codeLength, $this->chars); } else { $this->securityCode = $securityCode; } $context->getUser()->setAttribute('captcha', $this->securityCode); $this->img = imagecreatetruecolor($this->image_width, $this->image_height); $bc_color = $this->allocateColor($this->img, $this->background_color); $border_color = $this->allocateColor($this->img, $this->border_color); imagefill($this->img, 0, 0, $bc_color); imagerectangle($this->img, 0, 0, $this->image_width - 1, $this->image_height - 1, $border_color); foreach ($this->fontColor as $fcolor) { $color[] = $this->allocateColor($this->img, $fcolor); } $fw = imagefontwidth($this->fontSize) + $this->image_width / 30; $fh = imagefontheight($this->fontSize); // create a new string with a blank space between each letter so it looks better $newstr = ""; for ($i = 0; $i < strlen($this->securityCode); $i++) { $newstr .= $this->securityCode[$i] . " "; } // remove the trailing blank $newstr = trim($newstr); // center the string $x = ($this->image_width * 0.95 - strlen($newstr) * $fw) / 2; // create random lines over text $stripe_size_max = $this->image_height / 3; for ($i = 0; $i < 15; $i++) { $x2 = rand(0, $this->image_width); $y2 = rand(0, $this->image_height); imageline($this->img, $x2, $y2, $x2 + rand(-$stripe_size_max, $stripe_size_max), $y2 + rand(-$stripe_size_max, $stripe_size_max), $color[rand(0, count($color) - 1)]); } // output each character at a random height and standard horizontal spacing for ($i = 0; $i < strlen($newstr); $i++) { $hz = $fh + ($this->image_height - $fh) / 2 + mt_rand(-$this->image_height / 10, $this->image_height / 10); // randomize rotation $rotate = rand(-25, 25); // randomize font size $newFontSize = $this->fontSize + $this->fontSize * (rand(0, 3) / 10); $a = imagettftext($this->img, $newFontSize, $rotate, $x + $fw * $i, $hz, $color[rand(0, count($color) - 1)], $this->fonts_dir . $this->fonts[rand(0, count($this->fonts) - 1)], $newstr[$i]); } $context->getResponse()->setContentType('image/gif'); imagegif($this->img); imagedestroy($this->img); $context->getResponse()->send(); }
function imagestringheight($font, $left, $top, $right, $bottom, $align, $valign, $leading, $text, $color) { // Get size of box $height = $bottom - $top; $width = $right - $left; // Break the text into lines, and into an array $lines = wordwrap($text, floor($width / imagefontwidth($font)), "\n", true); $lines = explode("\n", $lines); // Other important numbers $line_height = imagefontheight($font) + $leading; $line_count = floor($height / $line_height); $line_count = $line_count > count($lines) ? count($lines) : $line_count; return $line_count * $line_height; }
public function generate() { $src_x = $this->_owner->getImageWidth(); $src_y = $this->_owner->getImageHeight(); $temp = new Canvas(); $temp->createImageTrueColorTransparent($src_x, $src_y + 20); $text = str_replace('[Filename]', $this->_owner->getProperty('filename'), $this->_info); switch ($this->_position) { case 't': $x = 0; $y = 20; $bar_y = 0; $text_y = 3; break; case 'b': $x = 0; $y = 0; $bar_y = $src_y + 20; $text_y = $bar_y - 20 + 3; break; default: return false; break; } switch ($this->_justify) { case 'l': $text_x = 3; break; case 'c': $text_x = ($src_x - imagefontwidth($this->_font) * strlen($text)) / 2; break; case 'r': $text_x = $src_x - 3 - imagefontwidth($this->_font) * strlen($text); break; } //Draw the bar background $color = Color::hexColorToArrayColor($this->_barcolor); $bar_color = imagecolorallocate($temp->image, $color['red'], $color['green'], $color['blue']); imagefilledrectangle($temp->image, 0, $bar_y, $src_x, 20, $bar_color); //Copy the image imagecopy($temp->image, $this->_owner->image, $x, $y, 0, 0, $src_x, $src_y); //Draw the text (to be replaced with image_draw_text one day $color = Color::hexColorToArrayColor($this->_textcolor); $text_color = imagecolorallocate($temp->image, $color['red'], $color['green'], $color['blue']); imagestring($temp->image, $this->_font, $text_x, $text_y, $text, $text_color); $this->_owner->image = $temp->image; unset($temp); return true; }
function output($in) { global $in2; $string = date('r') . ""; imagecopy($in, $in2, 0, 0, 0, 0, 640, 480); $font = 1; $width = imagefontwidth($font) * strlen($string); $height = imagefontheight($font) + 30; $x = imagesx($in) - $width; $y = imagesy($in) - $height; $backgroundColor = imagecolorallocate($in, 255, 255, 255); $textColor = imagecolorallocate($in, 0, 0, 0); imagestring($in, $font, $x, $y, $string, $textColor); imagejpeg($in, NULL, 60); }
/** * @return ErrorDrawer **/ public function draw($string = 'ERROR!') { if (!ErrorDrawer::isDrawError()) { return $this; } $y = round($this->turingImage->getHeight() / 2 - imagefontheight(ErrorDrawer::FONT_SIZE) / 2); $textWidth = imagefontwidth(ErrorDrawer::FONT_SIZE) * strlen($string); if ($this->turingImage->getWidth() > $textWidth) { $x = round(($this->turingImage->getWidth() - $textWidth) / 2); } else { $x = 0; } $color = $this->turingImage->getOneCharacterColor(); imagestring($this->turingImage->getImageId(), ErrorDrawer::FONT_SIZE, $x, $y, $string, $color); return $this; }
function pc_ImageStringCenter($image, $text, $font) { // font sizes $width = imagefontwidth($font); $height = imagefontheight($font); // find the size of the image $xi = ImageSX($image); $yi = ImageSY($image); // find the size of the text $xr = $width * strlen($text); $yr = $height; // compute centering $x = intval(($xi - $xr) / 2); $y = intval(($yi - $yr) / 2); return array($x, $y); }
/** * */ protected function convert() { $h = imagefontheight($this->font); $w = imagefontwidth($this->font); $l = strlen($this->text) + 2; $im = imagecreate($w * $l, $h); // background $this->getColor($this->bg, $br, $bg, $bb); imagecolorallocate($im, $br, $bg, $bb); // textcolor $this->getColor($this->color, $tr, $tg, $tb); $textcolor = imagecolorallocate($im, $tr, $tg, $tb); imagestring($im, $this->font, $w, 0, $this->text, $textcolor); $result = imagepng($im, $this->file); imagedestroy($im); return $result; }
function imagestringcenter($img, $font, $x, $y, $w, $h, $text, $color) { $text = iconv("UTF-8", "ISO-8859-2//TRANSLIT", $text); $tw = strlen($text) * imagefontwidth($font); $th = imagefontheight($font); if ($w == -1) { $x -= $tw / 2; } elseif ($w != 0) { $x += ($w - $tw) / 2; } if ($h == -1) { $y -= $th / 2; } elseif ($h != 0) { $y += ($h - $th) / 2; } imagestring($img, $font, $x, $y, $text, $color); }
/** * Get the width of a string * * @param &$text A string */ function getTextWidth(&$text) { if ($text->getAngle() === 90) { $text->setAngle(45); return $this->getTextHeight($text); } else { if ($text->getAngle() === 45) { $text->setAngle(90); } } $font = $text->getFont(); $fontWidth = imagefontwidth($font->font); if ($fontWidth === FALSE) { trigger_error("Unable to get font size", E_USER_ERROR); } return (int) $fontWidth * strlen($text->getText()); }