[英]How can i create white background color to an uploaded thumb image in php?
[英]php function to create thumb of uploaded image
我创建了一个函数来上传具有随机名称的图像,并且它可以正常工作。
function f_upload($file_name, $path)
{
$ext=end(explode('.', $file_name['name']));
$f_name=rand().time().'.'.$ext;
if(move_uploaded_file($file_name['tmp_name'], $path.$f_name))
{
return $f_name;
}
else
{
return false;
}
}
现在我想要的是在同一目录上创建宽度为75px的相同图像的缩略图,但名称以t_imagename
我尝试此功能,但它给错误。
function f_upload_gallary($file_name, $path)
{
$ext=end(explode('.', $file_name['name']));
$f_name=rand().time().'.'.$ext;
if(move_uploaded_file($file_name['tmp_name'], $path.$f_name))
{
$src=$path.$f_name;
$desired_width=75;
$dest=$path;
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
$desired_height = floor($height*($desired_width/$width));
$virtual_image = imagecreatetruecolor($desired_width,$desired_height);
imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);
imagejpeg($virtual_image,$dest);
return $f_name;
}
else
{
return false;
}
}
此功能不起作用。
我只想在名称为t_开头的同一文件夹上创建75的缩略图
谢谢
您未指定目标图片的文件名。 替换此行,
$dest = $path;
有了这个:
$dest = $path.'t_'.$f_name;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.