【发布时间】:2013-01-23 08:58:47
【问题描述】:
我想移动一个使用 imagettftext 创建并保存为 png 的文件。如您所见,在下面的代码中,我使用了 move_uploaded_file 但无济于事。请帮忙。
tq
// 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);
【问题讨论】:
-
从
imagecreatefromjpeg()中删除@符号,看看是否有任何错误,同时确保error_reporting处于打开状态。 -
move_uploaded_file 仅移动通过表单上传的文件,您应该使用函数rename
标签: php upload imagettftext