相关疑难解决方法(0)

PHP imagecreatefromjpeg有效,为什么png/bmp/gif没有工作?

我想上传和调整不同扩展名的图片.php从原始图片的中心裁剪出最大可能的正方形,然后将其保存为360*360像素.

代码适用于jpeg文件,但使用gif,bmp和png我得到一个33字节大小的损坏文件.

这是大部分代码:

$file_temp = $_FILES["pic"]["tmp_name"];
list ($width, $height, $type) = getimagesize ($file_temp);

$picture_name = "... a name.ext ...";
$upload = "... some dir/$picture_name";



if (move_uploaded_file($file_temp, "$upload"))
{



    //switches content-type and calls the imagecreatefrom... function
    if ($type == 1)
    {
        header ('Content-Type: image/gif');
        $image = imagecreatefromgif($upload);
    }
    elseif ($type == 2)
    {
        header ('Content-Type: image/jpeg');
        $image = imagecreatefromjpeg($upload);
    }
    elseif ($type == 3)
    {
        header ('Content-Type: image/png');
        $image = imagecreatefrompng($upload);
    }
    else
    {
        header ('Content-Type: image/x-ms-bmp');
        $image = imagecreatefromwbmp($upload);
    } …
Run Code Online (Sandbox Code Playgroud)

php image image-resizing

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

image ×1

image-resizing ×1

php ×1