2
在圖像上傳,我想調整圖像大小爲400 X 400的比例。我用GD庫代碼爲: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);
&我已經使用此代碼所示的圖像:
<img width="70" height="70" src="data:image/jpeg;base64, '.base64_encode($doctor->imgProfilePicture).' "/>
但是我收到錯誤爲: 警告:file_get_contents()函數預計參數1是一個有效路徑,串給出