嘿,我想知道我在哪里缺少文本所在的文本框的大小?
$img = imagecreatefromjpeg("Desert.jpg"); //http://s7.postimage.org/ceb440itn/Desert.jpg
$width = imagesx($img);
$height = imagesy($img);
$new_width = $width;
$new_height = $height;
$tmp_img = imagecreatetruecolor($new_width, $new_height);
imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Create some colors
$black = imagecolorallocate($tmp_img, 65, 173, 196);
// Define Font
$font = 'ARIAL.TTF';
// The text to draw
$text = 'This is a test here here blah';
//font size
$size = 75;
// Compute size of text and get the x and y for centering the text into the image
$box = imagettfbbox( $size, 0, $font, $text );
$x = 5;//($width - $box[2]) / 2 - 5;
$y = 75;//($height - $box[5]) / 2;
// Add some shadow to the text
imagettftext($tmp_img, $size, 0, $x+1, $y-1, $grey, $font, $text);
// Add the text
imagettftext($tmp_img, $size, 0, $x, $y, $black, $font, $text);
imagejpeg($tmp_img, "testing.jpg", 100);
imagedestroy($img);
imagedestroy($tmp_img);
输出图像如下所示:
--------------------------
|This is a test here here|blah
| |
| |--Image
| --+----Inside image
| |
--------------------------
请注意,它在*图像本身内*之后不包含单词blah 。
这应该是这样的:
--------------------------
|This is a test here here|
| blah |
| |--Image
| --+----Inside image
| |
--------------------------
我在哪里错过了它定义文本框大小的地方?