2012-07-16 1 views
0

누군가 나를 도울 수 있습니까? 내 크기 조정이 제대로 작동하는지 확인하고 싶지만 imagecopyresampled 이미지를 출력 할 수 없습니다. 지금 이상한 캐릭터를 출력합니다.imagecopyresampled 후 새 이미지를 출력 할 수 없음

//uploading image 
    $image_file = $_FILES['image']['tmp_name']; 
    $image_size = @getimagesize($image_file); 

    $image_mime = $image_size['mime']; 
    $image_width = $image_size['0']; 
    $image_height = $image_size['1']; 
    $image_ratio = $image_width/$image_height; 

    //not an image 
    if ($image_size === false) { 
     error('1'); 
    } 

    //check to see if valid image type 
    switch ($image_mime){ 
     case 'image/jpg': 
     case 'image/jpeg': 
     case 'image/pjpeg': 
      $image_file = @imagecreatefromjpeg($image_file); 
      break; 

     case 'image/png': 
      $image_file = @imagecreatefrompng($image_file); 
      break; 

     default: 
      error('2'); 
      break; 
    } 

    if ($image_width < 450 || $image_height < 350) { 
     //image too small 
     error('3'); 
    } 

    if ($image_ratio >= 1){ 
     //resize by height 
     $height = 350; 
     $ratio = $height/$image_height; 
     $width = $image_width * $ratio; 
    } else { 
     //resize by width 
     $width = 450; 
     $ratio = $width/$image_width; 
     $height = $image_height * $ratio; 
    } 

    //get the center axis 
    $x_center = ($image_width - $width)/2; 
    $y_center = ($image_height - $height)/2; 

    $new_image = imagecreatetruecolor($width, $height); 
    imagecopyresampled($new_image, $image_file, 0, 0, $x_center, $y_center, $width, $height, $image_width, $image_height); 

    imagepng($new_image); 


    exit(); 

답변

1

그 이상한 문자 는 이진수 출력 된 화상이다. 귀하의 브라우저는 그것이 당신이 말하지 않았기 때문에 그 이미지가 있어야한다는 것을 모릅니다. 브라우저가 어떤 종류의 데이터를 처리하고 있는지 알려주려면 이미지 출력 전에 헤더를 추가하십시오.

header('Content-Type: image/png'); 
관련 문제