我的PHP裁剪图像程序是否正确?

时间:2012-10-06 18:47:17

标签: php image-processing gd

我的程序有时可以成功裁剪图像,但有时则不能。

有三种可能的结果(即使使用相同的图像)

  1. 成功裁剪图像(正确结果)
  2. 无法裁剪图像,图像不变(结果不正确)
  3. 图像已被歪曲,但图像为黑色(不正确的结果)
  4. 这是编程问题还是服务器设置问题?

    //$_GET['x'],$_GET['y'] = crop area left top position
    //$_GET['w'],$_GET['h'] = crop area width and height
    $filePath=getImageFilePath();
    $extension=strrchr($thisEventMember->filePath,'.');
    if(strtolower($extension)=='.jpg'||strtolower($extension)=='.jpeg')
    {
        $image=imagecreatefromjpeg($filePath);
        $tempImage=imagecreatetruecolor($_GET['w'], $_GET['h']);
        imagecopyresampled($tempImage,$image,0,0,$_GET['x'],$_GET['y'],$_GET['w'],$_GET['h'],$_GET['w'],$_GET['h']);
        imagejpeg($tempImage,$filePath,90);
    }
    

0 个答案:

没有答案