izbryte Posted May 15, 2008 Share Posted May 15, 2008 I want to make it bigger with a bigger red background and a larger font. I want to center the font too in the middle of the box. I don't know how to do it. Can you help? Here's the code: <?php session_start(); $RandomStr = md5(microtime());// md5 to generate the random string $ResultStr = substr($RandomStr,0,5);//trim 5 digit $NewImage =imagecreatefromjpeg("img.jpg");//image create by existing image and as back ground $LineColor = imagecolorallocate($NewImage,233,239,239);//line color $TextColor = imagecolorallocate($NewImage, 255, 255, 255);//text color-white imageline($NewImage,1,1,40,40,$LineColor);//create line 1 on image imageline($NewImage,1,100,60,0,$LineColor);//create line 2 on image imagestring($NewImage, 10, 20, 8, $ResultStr, $TextColor);// Draw a random string horizontally $_SESSION['key'] = $ResultStr;// carry the data through session header("Content-type: image/jpeg");// out out the image imagejpeg($NewImage);//Output image to browser ?> Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 15, 2008 Share Posted May 15, 2008 Seems pretty straighforward, if you read the documentation for the functions being called. You might notice for example, that this technique starts with an existing image and then adds to it. So if you modify that original image, you will already have modified the resultant image. $NewImage =imagecreatefromjpeg("img.jpg");//image create by existing image and as back ground Quote Link to comment Share on other sites More sharing options...
izbryte Posted May 15, 2008 Author Share Posted May 15, 2008 I understand how to make the background bigger. What I don't know how to do it make th font bigger and center it. Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 19, 2008 Share Posted May 19, 2008 The text is written using the imagestring($NewImage, 10, 20, 8, $ResultStr, $TextColor);// Line. I'm not sure why this works, because the 2nd param, is suppossed to indicate the Font. Theoretically, making 10 something bigger would pick a bigger font, but it's not indicated in the manual that even a param of 10 is supported. Centering is tricky, you'd have to do a bit of math using the imagefontwidth() function. Theoretically, this value times the number of characters being added onto the image, would allow you to figure out where to start printing (x,y), by getting the 1/2 way point of the image, and subtracting 1/2 of the length of the string from that number (to get the X coord). Notice that currently the x,y values are hardcoded as 20,8, so you'd need to make those into variables. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.