2010-05-30 6 views
0

몇 분 전에 해결 된 나의 이전 질문을 읽었을 수도 있습니다. <새로 추가 된 썸네일 관련 문제 - PHP 직접 복사 방법

on-the-fly PHP 스크립트는 완벽하게 작동하지만 내가 직접 만든 갤러리에 새 이미지를 업로드하면 이미지는 원하는대로 150x150으로 크기가 조절됩니다. 당신이 폴더에 업로드 디렉토리가 데이터베이스에 추가 된 세 개의 검은 색 이미지를 볼 수 있듯이 그것은

alt text http://i48.tinypic.com/2qth175.png

... 그것은 모두 검은 색으로 추가 된 새로운 이미지로 제공됩니다.

다른 이미지 (검은 색이 아닌 이미지)는 이미 image.php로 크기가 조정됩니다.

이 문제의 원인은 무엇입니까?

I 소스를 보면, 코드 괜찮합니다 ... PHP의 while 루프 출력 같이 생성

<div class="view-wrap" id="photo-10"> 
    <div class="view-icon"> 
     <div class="img-label"> 
      <a href="#" id="10" class="delete"><img src="img/small-delete.png" /> Delete</a> 
     </div> 

     <a href="img/events/Paintballing/24251_1395408043148_1170626626_1204038_5382765_n.jpg"> 
      <img src="image.php?dir=img/events/Paintballing/24251_1395408043148_1170626626_1204038_5382765_n.jpg" alt="" width="110" height="110" /> 
     </a> 
    </div> 
</div> 

하나 개의 블록의 예. 내가 (Firefox에서) 소스를 확인하고 image.php? 디렉토리를 클릭하면

는 = IMG는/이벤트/exmaple로/24251_1395408043148_1170626626_1204038_5382765_n.jpg 페인트 볼, 나는 그것이 150 X 150 크기의에서 미리보기를 볼 수 있지만 레이아웃의 수 , 검은 색 섬네일을 보여줍니다 ...

왜 이런 일이 일어나는 지 알고 계십니까?

편집 :이 image.php가

<?php 

$dir = $_GET['dir']; 

header('Content-type: image/jpeg'); 

$create = imagecreatetruecolor(150, 150); 

$img = imagecreatefromjpeg($dir); 

list($width, $height) = getimagesize($dir); 

imagecopyresampled($create, $img, 0, 0, 0, 0, 150, 150, $width, $height); 

imagejpeg($create, null, 100); 

?> 

입니다.

+0

내 게시물을 업데이트하십시오! – RobertPitt

답변

0

게시물을 업데이트 해 주셔서 감사합니다.

이미지가 업로드하는 jpg/jpeg가 좋으십니까?

시도는 오히려 왜 안 테두리를 추가 이미지를 스트레칭보다 다음

<?php 

$dir = $_GET['dir']; 
$ext = strtoupper(pathinfo($dir, PATHINFO_EXTENSION)); 
switch($ext) 
{ 
    case 'jpeg': 
    case 'jpg': 
     $img = imagecreatefromjpeg($dir); 
    break; 
    case 'png': 
     $img = imagecreatefrompng($dir); 
    break; 
    case 'gif': 
     $img = imagecreatefromgif($dir); 
    break; 
} 
if(isset(img)) 
{ 
    header('Content-type: image/jpeg'); 
    $create = imagecreatetruecolor(150, 150); 
    list($width, $height) = getimagesize($dir); 
    imagecopyresampled($create, $img, 0, 0, 0, 0, 150, 150, $width, $height); 
    imagejpeg($create, null, 100); 
}else 
{ 
    echo sprintf('Unable to process image, Unknown format %s',$ext); 
} 
?> 
+0

게시물을 편집했습니다. – MacMac

+0

그러면 그게 효과가 있었나요? – RobertPitt

0

로 변경?

여기에이 기능은 원본 파일을 대체하지만 쉽게 새로운 썸네일 이미지를 생성하도록 수정 기능

function resize_to_canvas($filename,$canvas_w=100,$canvas_h=225){ 
list($width, $height, $type) = getimagesize($filename); 

$original_overcanvas_w = $width/$canvas_w; 
$original_overcanvas_h = $height/$canvas_h; 

$dst_w = round($width/max($original_overcanvas_w,$original_overcanvas_h),0); 
$dst_h = round($height/max($original_overcanvas_w,$original_overcanvas_h),0); 

$dst_image = imagecreatetruecolor($canvas_w, $canvas_h); 
$background = imagecolorallocate($dst_image, 255, 255, 255); 
imagefill($dst_image, 0, 0, $background); 

$src_image = imagecreatefromjpeg($filename); 
imagecopyresampled($dst_image, $src_image, ($canvas_w-$dst_w)/2, ($canvas_h-$dst_h)/2, 0, 0, $dst_w, $dst_h, $width, $height); 
imagegif($dst_image, $filename); 
imagedestroy($dst_image);} 

입니다. 그냥 파일 이름을 줄 imagegif ($ dst_image, $ filename);

관련 문제