note 85197 modified in function.imagestring by felipe

From: Date: Wed, 20 Aug 2008 21:59:13 +0000
Subject: note 85197 modified in function.imagestring by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143688@lists.php.net to get a copy of this message
this is a function that is based on imagestring but it produces text in the center of an image i hope it helps :D <?php function ImageStringCenter($image_resource, $font_size, $line_number, $total_lines, $text, $color ) { $center_x = ceil( ( imagesx($image_resource) - ( ImageFontWidth($font_size) * strlen($text) ) ) / 2 ); $center_y = ceil( ( ( imagesy($image_resource) - ( ImageFontHeight($font_size) * $total_lines ) ) / 2) + ( ($line_number-1) * ImageFontHeight($font_size) ) ); ImageString($image_resource, $font_size, $center_x, $center_y, $text, $color ); } ?> --was-- this is a function that is based on imagestring but it produces text in the center of an image i hope it helps :D function ImageStringCenter($image_resource, $font_size, $line_number, $total_lines, $text, $color ) { $center_x = ceil( ( imagesx($image_resource) - ( ImageFontWidth($font_size) * strlen($text) ) ) / 2 ); $center_y = ceil( ( ( imagesy($image_resource) - ( ImageFontHeight($font_size) * $total_lines ) ) / 2) + ( ($line_number-1) * ImageFontHeight($font_size) ) ); ImageString($image_resource, $font_size, $center_x, $center_y, $text, $color ); } http://php.net/manual/en/function.imagestring.php

« previous php.notes (#143688) next »