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

My program is able to crop images successfully sometimes, but other times it is not.

There are three possible outcomes (even using the same image)

  1. successfully crop the image (correct outcome)
  2. cannot crop the image, the image is unchanged (incorrect outcome)
  3. the image has been croped, but the image is black (incorrect outcome)

Is this a programming problem or a server setting problem?

//$_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);
}