1

我想移动一个使用 imagettftext 创建并保存为 png 的文件。如您所见,在下面的代码中,我使用了 move_uploaded_file 但无济于事。请帮忙。

时间

// Set the content-type
header('Content-Type: image/png');



// Create the image from created image
//$im = imagecreatetruecolor(180, 180);
$im = @imagecreatefromjpeg('poloroid.jpg');

// Create some colors
$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);

// The text to draw
//$text = 'John...';
$fbid = $_POST["id"]; 
$text = $_POST["want"];
$fb_email =$_POST["email"];
$fb_name=$_POST["name"];

$uploads_dir = '/uploaded_files';
// Replace path by your own font path
$font = 'verdana.ttf';

//image file name
$name ="$fbid.png";


// Add some shadow to the text
imagettftext($im, 20, 0,  25, 126, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 25, 125, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
//imagepng($im);
imagepng($im,$name,9);
move_uploaded_file($name,"$uploads_dir/$name");
imagedestroy($im);
4

2 回答 2

5

您不是在上传文件,而是在生成一个文件!

imagepng具有filename参数,因此您可以将其保存到驱动器中:

$uploads_dir = '/uploaded_files/';
$name = $uploads_dir.$fbid.'.png';
imagepng($im,$name,9);
imagedestroy($im);
于 2013-01-23T09:01:33.803 回答
1

尝试使用rename 而不是move_uploaded_file

于 2013-01-23T09:13:15.860 回答