2014-02-25 5 views
1

이미지 변환 기능을 만들고 있습니다. 예 : 파일 확장명이 변경되지 않았습니다. oldfile.png out newfile.png. 하지만 파일 변환 후 확장자를 변경해야합니다. newfile.jpg 맞습니까?Imagejpeg 기능이 파일 확장자를 변경하지 않습니다.

function convertimg($target, $new, $ext, $converto) { 
    if ($ext['mime'] == 'image/jpeg') { 
     $img = imagecreatefromjpeg($target); 
    } elseif ($ext['mime'] == 'image/png') { 
     $img = imagecreatefrompng($target); 
    } elseif ($ext['mime'] == 'image/gif') { 
     $img = imagecreatefromgif($target); 
    } 
    $ictc = imagecreatetruecolor($ext[0], $ext[1]); 
    imagecopyresampled($ictc, $img, 0, 0, 0, 0, $ext[0], $ext[1], $ext[0], $ext[1]); 
    ob_start(); 
    header("Content-type: " . $converto); 
    if ($converto == 'image/jpeg') { 
     imagejpeg($ictc, $new, 84); 
    } elseif ($converto == 'image/png') { 
     imagepng($ictc, $new, 84); 
    } elseif ($converto == 'image/gif') { 
     imagegif($ictc, $new, 84); 
    } 
    ob_get_clean(); 
    imagedestroy($ictc); 
} 

답변

1

아니요, 새 파일 이름을 제공 했으므로 아무 것도 할 수 없습니다.

따라서 변환하는 경우 새 확장을 제공해야합니다. imagegpeg의 유일한 작업은 RAW 이미지를 jpeg 형식으로 저장하는 것입니다.

+0

오, 그렇다면 이미지를 변환 할 때 확장을 지정해야합니다. 예 : '.jpg' 또는'.png'? – user3315433

+0

@ user3315433 yes – baldrs

+0

thnx, 나는 그 일을 잘했지만 문제는 내가'getimagesize()'로 다시 검사 할 때 여전히 jpg가 아닌 png 파일을 보여주는 것이다. 왜? – user3315433

관련 문제