2012-04-04 3 views
0

글을 쓸 시간이 많지 않습니다. 내 문제를 말하면서 이미지를 잘리는 PHP 코드가 있습니다. $ thumb_width를 넣으면 이미지가 잘 자릅니다. $ thumb_height 같은 값으로,하지만이 경우에는 내가이 해상도 (200 * 150) 여기에 코드와 내가 실수를 찾을 수없는 이미지를 원하는지 않습니다. 이 예에서 자르기 이미지 PHP 변형, 뒤틀림

<?php 
function create_thumb($directory, $image, $destination) { 
$image_file = $image; 
$image = $directory.$image; 

if (file_exists($image)) { 

$source_size = getimagesize($image); 

if ($source_size !== false) { 

    $thumb_width = 200; 
    $thumb_height = 150; 

    switch($source_size['mime']) { 
    case 'image/jpeg': 
     $source = imagecreatefromjpeg($image); 
    break; 
    case 'image/png': 
     $source = imagecreatefrompng($image); 
    break; 
    case 'image/gif': 
     $source = imagecreatefromgif($image); 
    break; 
    } 

    $source_aspect = round(($source_size[0]/$source_size[1]), 1); 
    $thumb_aspect = round(($thumb_width/$thumb_height), 1); 

    if ($source_aspect < $thumb_aspect) { 
    $new_size = array($thumb_width, ($thumb_width/$source_size[0]) * $source_size[1]); 
    $source_pos = array(0, ($new_size[1] - $thumb_height)/2); 
    } else if ($source_aspect > $thumb_aspect) { 
    $new_size = array(($thumb_width/$source_size[1]) * $source_size[0], $thumb_height); 
    $source_pos = array(($new_size[0] - $thumb_width)/2, 0); 
    } else { 
    $new_size = array($thumb_width, $thumb_height); 
    $source_pos = array(0, 0); 
    } 

    if ($new_size[0] < 1) $new_size[0] = 1; 
    if ($new_size[1] < 1) $new_size[1] = 1; 

    $thumb = imagecreatetruecolor($thumb_width, $thumb_height); 
    imagecopyresampled($thumb, $source, 0, 0, $source_pos[0], $source_pos[1], $new_size[0],                $new_size[1], $source_size[0], $source_size[1]); 

    switch($source_size['mime']) { 
    case 'image/jpeg': 
     imagejpeg($thumb, $destination.$image_file); 
    break; 
    case 'image/png': 
      imagepng($thumb, $destination.$image_file); 
    break; 
    case 'image/gif': 
     imagegif($thumb, $destination.$image_file); 
    break; 
} 


} 

} 
} 
?> 

, 내가 랩 (533px * 300 픽셀)가 변형 된 것의 이미지 "= 내 영어 죄송합니다)"를 넣어 경우, 나는이 도움이 필요하시기 바랍니다. 당신이 해결책을 찾으면 나는 정말로 열매를 맺을 것입니다.

감사합니다. Matias.

답변

1

이 이드.

온라인에서 더 많은 공백을 입력 했으므로 해당 줄에서 공백을 제거해야합니다.

+0

공백이 있습니까 ?? –

0

예. 일반적으로 하나 이상의 공간을 제공하더라도 보통 하나의 공간 만있을 것입니다. 그러나 여기에는 "& nbsp"의 여러 공백이 있습니다.

잘못된 구문 : imagecopyresampled ($ 엄지, $ 소스, 0, 0, $ source_pos [0], $ source_pos [1], $의 new_size [0]                                                       $ new_size [1], $의 source_size [0], $의 source_size [1]);

올바른 구문 : imagecopyresampled ($ thumb, $ source, 0, 0, $ source_pos [0], $ source_pos [1], $ new_size [0], $ new_size [1], $ source_size [0], $ source_size [1]);