2016-12-19 5 views
2

При загрузке изображения я хочу изменить размер изображения до 400 X 400. Я использовал GD код библиотеки как:PHP изменить размер изображения & хранить в BLOB & access хотя 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); 

& Я показал изображение, используя этот код:

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

Но я получаю сообщение об ошибке, как: Warning: file_get_contents() ожидает параметр 1, чтобы быть правильный путь, строка, заданная

ответ

0

Я получил код для этого на этой ссылке по вкладам пользователей scaleImageFileToBlob()

http://php.net/manual/en/function.imagejpeg.php