Php Imagettfbbox和imagettftext
嘿,所有我想知道我在哪里丢失了文本框的大小,文本在里面Php Imagettfbbox和imagettftext,php,imagettftext,Php,Imagettftext,嘿,所有我想知道我在哪里丢失了文本框的大小,文本在里面 $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_w
$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
| |
--------------------------
请注意,*图像本身中,*此处的后面不包含单词等等
它应该是这样的:
--------------------------
|This is a test here here|
| blah |
| |--Image
| --+----Inside image
| |
--------------------------
我在哪里遗漏了它定义了文本框的大小?使用最少的编辑次数,我得到了$grey的一个未定义的var。输出图像在这里 所以我的下一个问题是,嗯?我没有Arial字体。这就是你看到的吗?
$desert = 'http://s7.postimage.org/ceb440itn/Desert.jpg';
$img = imagecreatefromjpeg($desert); //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';
$font = 'fonts/verdana.ttf';
// The text to draw
$text = 'This is a test here here blah';
//font size
$size = 22;
// 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, "RAY_junk/testing.jpg", 100);
imagedestroy($img);
imagedestroy($tmp_img);
我不认为你遗漏了什么——我只是认为需要手动完成单词包装。如果有机会,我会验证这个理论。请发一个链接到Desert.jpg,谢谢。@RayPaseur:对不起,字体大小应该是75$尺寸=75;字体本身可以在windows计算机上的c:\windows\fonts目录中找到,我刚刚在文本字符串的末尾添加了内容。PHP只是让字符串变长了。所以我想你得自己把它包装起来。字体大小为75,文本就在屏幕上显示出来了。你的目标到底是什么?让文本下拉。就像你说的,包起来。