note 94306 added to function.imagestring

From: Date: Wed, 28 Oct 2009 15:02:37 +0000
Subject: note 94306 added to function.imagestring
Groups: php.notes 
Request: Send a blank email to php-notes+get-162181@lists.php.net to get a copy of this message
I created this very simple function to place text in the horizontal center of an image. image = the image. image_width = the width of the image. string = the text you want to add. font_size = font size, between 1 and 5. y = vertical position of the text. color = the color of the text <? //place text in the center of the image 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); } ?> To use the function in your script, you can do like this: <? header("Content-type: image/png"); $picture = imagecreate(100,100); $black = ImageColorAllocate ($picture, 0, 0, 0); CenterImageString($picture, 100, "Centered text", 2, 45, $black); ImagePng ($picture); ?> ---- Server IP: 91.199.167.18 Probable Submitter: 145.97.226.121 ---- Manual Page -- http://www.php.net/manual/en/function.imagestring.php Edit -- https://master.php.net/note/edit/94306 Del: integrated -- https://master.php.net/note/delete/94306/integrated Del: useless -- https://master.php.net/note/delete/94306/useless Del: bad code -- https://master.php.net/note/delete/94306/bad+code Del: spam -- https://master.php.net/note/delete/94306/spam Del: non-english -- https://master.php.net/note/delete/94306/non-english Del: in docs -- https://master.php.net/note/delete/94306/in+docs Del: other reasons-- https://master.php.net/note/delete/94306 Reject -- https://master.php.net/note/reject/94306 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162181) next »