2016-12-19 1 views
2

이미지 업로드시 400 x 400 비율의 이미지 크기를 조정하고 싶습니다. 이 코드 사용하여 이미지를 보여PHP는 이미지를 크기를 조정하고 BLOB에 저장하고 액세스하지만 base64_encode를 사용합니다.

$profilePicture = $_FILES['imgProfilePicture']['tmp_name'];  
       // Get new dimensions 
     list($width_orig, $height_orig, $type) = getimagesize($profilePicture); 
     $ratio_orig = $width_orig/$height_orig; 

     if ($intWidth/$intHeigth > $ratio_orig) { 
     $intWidth = $intHeigth*$ratio_orig; 
     } else { 
     $intHeigth = $intWidth/$ratio_orig; 
     } 

     // Resample 
     $thumb = imagecreate($intWidth, $intHeigth); 
     ob_start(); 
     $extension = image_type_to_extension($type); 
     if($extension == ".jpg" OR $extension=='.jpeg'){ 
        $source = ImageCreateFromJpeg($profilePicture); 
        $newImage = imagejpeg($thumb, null, 9); 
        }elseif ($extension == ".gif"){ 
        $source = ImageCreateFromGIF($profilePicture); 
        $newImage = imagegif($thumb, null, 9); 
        }elseif ($extension == '.png'){ 
        $source = imageCreateFromPNG($profilePicture); 
        $newImage = imagepng($thumb, null, 9); 
        }       

     imagecopyresized($thumb, $source, 0, 0, 0, 0, $intWidth, $intHeigth, $width_orig, $height_orig); 

     $stream = ob_get_clean(); 
     $imgProfilePicture = file_get_contents($stream); 
     $sql="update `".$doctorTableName."` set`imgProfilePicture`='".$imgProfilePicture."' where id='".$id."'";    
     $wpdb->query($sql); 

& : 나는이 GD 라이브러리 코드를 사용했다

<img width="70" height="70" src="data:image/jpeg;base64, '.base64_encode($doctor->imgProfilePicture).' "/> 

을하지만 같은 오류가 점점 오전 :() 매개 변수 1이 될 것으로 기대 file_get_contents : 경고 유효한 경로, 문자열 내가 사용자의 기여에 따라이 링크를 scaleImageFileToBlob()

을 이것에 대한 코드를 가지고

답변

0

을 부여
http://php.net/manual/en/function.imagejpeg.php 
관련 문제