2012-03-30 3 views
0

이것은 제가 작업중인 thumnbail 스크립트이며 손상된 33 바이트 이미지를 생성합니다. 문제는 ifif_imagetype if 문에 있다고 생각하지만 확실하지 않습니다. 나는 어떤 도움을 주셔서 감사합니다.PHP가 손상된 thumnbail을 만듭니다

// Original image 
    $filename = 'images/T' . $neutralName; 

    // Get dimensions of the original image 
    list($current_width, $current_height) = getimagesize($filename); 

    // The x and y coordinates on the original image where we 
    // will begin cropping the image 
    $left = 10; 
    $top = 5; 

    // This will be the final size of the image (e.g. how many pixels 
    // left and down we will be going) 
    $crop_width = 140; 
    $crop_height = 100; 

    // Resample the image 
    $canvas = imagecreatetruecolor($crop_width, $crop_height); 
    if ((exif_imagetype($_FILES['photo']['tmp_name'])) == IMAGETYPE_JPEG) { 
     $current_image = imagecreatefromjpeg($filename); 
     imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height); 
     imagejpeg($canvas, $filename, 100); 
    } else if ((exif_imagetype($_FILES["photo"]['tmp_name'])) == IMAGETYPE_GIF) { 
     $current_image = imagecreatefromgif($filename); 
     imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height); 
     imagegif($canvas, $filename, 100); 
    } else { 
     $current_image = imagecreatefrompng($filename); 
     imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height); 
     imagepng($canvas, $filename, 100); 
    } 
+0

더 많은 코드가 있습니까? 그 성명서 뒤에 $ 캔버스로 무엇을하고 있습니까? – mikevoermans

+2

이미지의 내부 내용은 무엇입니까? 어쩌면 그것은 33 심볼의 오류 메시지입니까? –

+1

모든 코드가 바로 거기에 있습니다. 캔버스가 if 문 바로 위에 정의되어 있습니다. 그리고 그래, 나는 33 가지의 오류가 있다고 믿는다. 어떤 그림이 PNG인지 계속 생각하므로 JPG 일지라도 첫 번째 및 두 번째 테스트가 실패한 것입니다. – Ramin

답변

0

나는 당신의 문제는 당신이, 당신이 $_FILES["photo"]['tmp_name']하지만 통해 파일 형식을 발견하고 당신의 각 각에서 ... 존재하지 않거나 이미지지지 않습니다 이미지를 열려고하는 생각 조건이 참일 경우 바로 아래에 imagecreatefromXXX($filename)을 사용하고 있습니다. 이미지를 저장하는 경로가 아닌 업로드 된 이미지 파일을 열면 안됩니까? 경로 $filename (존재한다고 가정)을 열면 항상 동일한 정확한 사각형을 복사하고 저장합니다. 당신이 할 수있는 실행 가능한 것처럼 보이지 않습니다.

+0

당신은 완전히 옳았습니다. 지금 고쳤습니다. 원래의 그림을 확인하고 JPG 또는 PNG인지 또는 다른 파일인지 확인하는 대신 $ filename을 테스트하여 사진의 유형을 확인합니다. 나는 이미 그것을 테스트하고 작동합니다. 엄청 고마워! 그것은 내가 맹인 된 것입니다. – Ramin