我有一个拍摄图像的功能,并将它们组合成一个宽图像。这似乎有效。现在我试图在图像上放一些文字,但事实并非如此。
以下五行://为文本分配颜色,是我为创建文本而添加的颜色。有什么我想念的吗?我运行代码时没有看到任何错误。
function merge($filename_w, $filename_x, $filename_y, $filename_z,$filename_result, $text) {
// Get dimensions for specified images
list($width_w, $height_w) = getimagesize($filename_w);
list($width_x, $height_x) = getimagesize($filename_x);
list($width_y, $height_y) = getimagesize($filename_y);
list($width_z, $height_z) = getimagesize($filename_z);
// Create new image with desired dimensions
$image = imagecreatetruecolor($width_w + $width_x + $width_y + $width_z, $height_x);
// Load images and then copy to destination image
$image_w = imagecreatefromjpeg($filename_w);
$image_x = imagecreatefromjpeg($filename_x);
$image_y = imagecreatefromjpeg($filename_y);
$image_z = imagecreatefromjpeg($filename_z);
imagecopy($image, $image_w, 0, 0, 0, 0, $width_w, $height_w);
imagecopy($image, $image_x, $width_w, 0, 0, 0, $width_x, $height_x);
imagecopy($image, $image_y, $width_w + $width_x, 0, 0, 0, $width_y, $height_y);
imagecopy($image, $image_z, $width_w + $width_x + $width_y, 0, 0, 0, $width_z, $height_z);
// Allocate A Color For The Text
$white = imagecolorallocate($image, 255, 255, 255);
// Set Path to Font File
$font_path = './tahoma.ttf';
// Print Text On Image
imagettftext($image, 25, 0, 75, 300, $white, $font_path, "Test text");
// Save the resulting image to disk (as JPEG)
imagejpeg($image, $filename_result);
// Clean up
imagedestroy($image);
imagedestroy($image_w);
imagedestroy($image_x);
imagedestroy($image_y);
imagedestroy($image_z);
}