如何使用php将文本和图像写入jpg文件

如何使用php将文本和图像写入jpg文件,php,Php,嗨,朋友们,我正在尝试从mysql获取一些文本和图像,并希望用php将它们写入jpg文件。我的意思是文本和图像应该合并到一个jpg文件中。如果你有任何建议,请帮忙。谢谢您应该使用PHP在图像上编写文本。这正是你在这里需要的 代码片段。。 重复。请删除。非常感谢你救了我的命:)嗨,你能告诉我如何在图像末尾添加文本意味着不覆盖图像谢谢againhi shankar我如何在图像文件末尾写入文本你可以在那里指定坐标吗 <?php header('Content-Type: image/png')

嗨,朋友们,我正在尝试从mysql获取一些文本和图像,并希望用php将它们写入jpg文件。我的意思是文本和图像应该合并到一个jpg文件中。如果你有任何建议,请帮忙。谢谢

您应该使用PHP在图像上编写文本。这正是你在这里需要的

代码片段。。


重复。请删除。非常感谢你救了我的命:)嗨,你能告诉我如何在图像末尾添加文本意味着不覆盖图像谢谢againhi shankar我如何在图像文件末尾写入文本你可以在那里指定坐标吗
<?php
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$text = 'Testing...';
$font = 'arial.ttf';
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);
<?php

/*** set the header for the image ***/
header("Content-type: image/jpeg");

/*** specify an image and text ***/
$im = writeToImage('test.jpg', 'PHPRO rules again');

/*** spit the image out the other end ***/
imagejpeg($im);

/**
 *
 * @Write text to an existing image
 *
 * @Author Kevin Waterson
 *
 * @access public
 *
 * @param string The image path
 *
 * @param string The text string
 *
 * @return resource
 *
 */
function writeToImage($imagefile, $text){
/*** make sure the file exists ***/
if(file_exists($imagefile))
    {    
    /*** create image ***/
    $im = @imagecreatefromjpeg($imagefile);

    /*** create the text color ***/
    $text_color = imagecolorallocate($im, 233, 14, 91);

    /*** splatter the image with text ***/
    imagestring($im, 6, 25, 150,  "$text", $text_color);
    }
else
    {
    /*** if the file does not exist we will create our own image ***/
    /*** Create a black image ***/
    $im  = imagecreatetruecolor(150, 30); /* Create a black image */

    /*** the background color ***/
    $bgc = imagecolorallocate($im, 255, 255, 255);

    /*** the text color ***/
    $tc  = imagecolorallocate($im, 0, 0, 0);

    /*** a little rectangle ***/
    imagefilledrectangle($im, 0, 0, 150, 30, $bgc);

    /*** output and error message ***/
    imagestring($im, 1, 5, 5, "Error loading $imagefile", $tc);
    }
return $im;
}

?>