【发布时间】:2015-09-05 02:41:05
【问题描述】:
我制作了一个负责上传图像的文件,然后将这些图像移动到服务器中的文件夹中。我想我不能直接在 $_FILES 数组中调整图像大小,所以我认为我必须在服务器中调整图像大小,所以我的问题是,如何调整服务器中的图像大小?
这是我拥有的代码的一部分:
//This is after getting target which is the file saved on the server
move_uploaded_file($_FILES[$str]['tmp_name'], $target);
scale_image($target);
现在函数 scale_image()
function scale_image($image)
{
if(!empty($image)) //the image to be uploaded is a JPG I already checked this
{
$source_image = imagecreatefromjpeg($image);
$source_imagex = imagesx($source_image);
$source_imagey = imagesy($source_image);
$dest_imagex = 300;
$dest_imagey = 200;
$image = imagecreatetruecolor($dest_imagex, $dest_imagey);
imagecopyresampled($image, $source_image, 0, 0, 0, 0,
$dest_imagex, $dest_imagey, $source_imagex, $source_imagey);
}
}
但这似乎不起作用,它移动了文件但没有调整大小。
【问题讨论】:
-
resize image in PHP的可能重复
标签: php image-resizing