MasterACE14 Posted June 13, 2008 Share Posted June 13, 2008 hello, I found a simple PHP progress bar and I simply want to add some text in the center of the progress bar. here's the code(relevant code only): <?php // creating bar (int)$barWidth = $percent*$barX/100; $img = imagecreate($barX, $barY); $bgColor = ImageColorAllocate ($img, $bg_rgb[0], $bg_rgb[1], $bg_rgb[2]); $barColor = ImageColorAllocate ($img, $bar_rgb[0], $bar_rgb[1], $bar_rgb[2]); ImageString($img, "testing", "FFFFFF"); // this is what im trying to add unsuccessfully ImageFilledRectangle($img, 0, 0, $barWidth, $barY, $barColor); // output bar imagepng($img); // destroy !!! imagedestroy($img); ?> it all works fine, except in the ImageString() function line it doesn't add the text. besides that the actual bar works fine. Regards ACE Link to comment https://forums.phpfreaks.com/topic/110041-solved-progress-type-bar-trouble-adding-text/ Share on other sites More sharing options...
conker87 Posted June 13, 2008 Share Posted June 13, 2008 bool imagestring ( resource $image , int $font , int $x , int $y , string $string , int $color ) Your syntax isn't correct. Link to comment https://forums.phpfreaks.com/topic/110041-solved-progress-type-bar-trouble-adding-text/#findComment-564635 Share on other sites More sharing options...
MasterACE14 Posted June 13, 2008 Author Share Posted June 13, 2008 i've changed the string function to this with no success =/ : <?php ImageString($img, "monospace", 1, 1, "testing", "FFFFFF"); Link to comment https://forums.phpfreaks.com/topic/110041-solved-progress-type-bar-trouble-adding-text/#findComment-564649 Share on other sites More sharing options...
conker87 Posted June 13, 2008 Share Posted June 13, 2008 I think the font has to actually be a filename. Link to comment https://forums.phpfreaks.com/topic/110041-solved-progress-type-bar-trouble-adding-text/#findComment-564652 Share on other sites More sharing options...
saint959 Posted June 13, 2008 Share Posted June 13, 2008 Hey, here is code that i have used way back to create text on an image. <?php $colorBlack=imagecolorallocate($image, 0, 0, 0); imagestring ($image, 3, 200, 10, "hey there", $colorBlack); ?> FONT - Can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) Link to comment https://forums.phpfreaks.com/topic/110041-solved-progress-type-bar-trouble-adding-text/#findComment-564653 Share on other sites More sharing options...
MasterACE14 Posted June 13, 2008 Author Share Posted June 13, 2008 I have it working now, just gotta center the text now. latest code: <?php // creating bar (int)$barWidth = $percent*$barX/100; $img = imagecreate($barX, $barY); $bgColor = ImageColorAllocate ($img, $bg_rgb[0], $bg_rgb[1], $bg_rgb[2]); $barColor = ImageColorAllocate ($img, $bar_rgb[0], $bar_rgb[1], $bar_rgb[2]); $colorBlack=imagecolorallocate($img, 255, 255, 255); ImageString($img, 3, 1, 1, "testing", $colorBlack); ImageFilledRectangle($img, 0, 0, $barWidth, $barY, $barColor); ?> Link to comment https://forums.phpfreaks.com/topic/110041-solved-progress-type-bar-trouble-adding-text/#findComment-564674 Share on other sites More sharing options...
MasterACE14 Posted June 13, 2008 Author Share Posted June 13, 2008 sorry for double post... latest code: <?php // creating bar (int)$barWidth = $percent*$barX/100; $img = imagecreate($barX, $barY); $bgColor = ImageColorAllocate ($img, $bg_rgb[0], $bg_rgb[1], $bg_rgb[2]); $barColor = ImageColorAllocate ($img, $bar_rgb[0], $bar_rgb[1], $bar_rgb[2]); $textColor=imagecolorallocate($img, 255, 255, 255); ImageFilledRectangle($img, 0, 0, $barWidth, $barY, $barColor); ImageString($img, 5, 1, 1, $text, $textColor); Link to comment https://forums.phpfreaks.com/topic/110041-solved-progress-type-bar-trouble-adding-text/#findComment-564680 Share on other sites More sharing options...
saint959 Posted June 13, 2008 Share Posted June 13, 2008 try taking the $barwidth and dividing it by two to get the text in the center of the image. I.e. add: <?php // creating bar (int)$barWidth = $percent*$barX/100; $img = imagecreate($barX, $barY); $bgColor = ImageColorAllocate ($img, $bg_rgb[0], $bg_rgb[1], $bg_rgb[2]); $barColor = ImageColorAllocate ($img, $bar_rgb[0], $bar_rgb[1], $bar_rgb[2]); $textColor=imagecolorallocate($img, 255, 255, 255); $barCenter = $barWidth / 2; ImageFilledRectangle($img, 0, 0, $barWidth, $barY, $barColor); ImageString($img, 5, 1, 1, $text, $textColor); ?> Link to comment https://forums.phpfreaks.com/topic/110041-solved-progress-type-bar-trouble-adding-text/#findComment-564700 Share on other sites More sharing options...
MasterACE14 Posted June 13, 2008 Author Share Posted June 13, 2008 yep thats working, Thanks Regards ACE Link to comment https://forums.phpfreaks.com/topic/110041-solved-progress-type-bar-trouble-adding-text/#findComment-565228 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.