小编The*_*eil的帖子

调整服务器上的图像大小

我制作了一个负责上传图像的文件,然后将这些图像移动到服务器中的文件夹中.我想我不能直接在$ _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);
Run Code Online (Sandbox Code Playgroud)

现在函数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);

    }
}
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用,它移动文件但没有调整大小.

php image-resizing

0
推荐指数
1
解决办法
6979
查看次数

标签 统计

image-resizing ×1

php ×1