圖片縮圖,放進資料庫img欄位

edited 六月 2014 in PHP新手區
我想把圖片先進行縮圖後在存放到資料庫 嘗試了以下語法(僅部分)
  $source = imageCreateFromJpeg($_FILES["upfile"]["tmp_name"]); 
	             
	            $decreaseSize=160; 
	            $sourceWidth  = imagesX($source);    
	                    $sourceHeight = imagesY($source);  
	                     
	                    $cropWidth = intval('300');    
	                    $cropHeight = intval('200'); 
	             
	            if ($cropWidth < $cropHeight) {   
	   $decreaseWidth = $decreaseSize;    
	   $decreaseHeight = intval($cropHeight*$decreaseSize/$cropWidth);   
	} else {   
	   $decreaseHeight=$decreaseSize;   
	   $decreaseWidth = intval($cropWidth*$decreaseSize/$cropHeight);   
	}   
	   
	// 建立縮圖所需要的圖片空間   
	$decrease = imageCreateTrueColor($decreaseWidth, $decreaseHeight);   
	   
	// 複製並縮小圖片   
	imageCopyResampled(   
	   $decrease,    
	   $source,    
	   0,    
	   0,    
	   0,    
	   0,    
	   $decreaseWidth,    
	   $decreaseHeight,    
	   $cropWidth,    
	   $cropHeight);   
	 
	$fileContents = base64_encode($decrease);

執行後在$fileContents = base64_encode($decrease);這行錯誤
base64_encode() expects parameter 1 to be string, resource

請問是否還需要轉換之類的? 還是本就不能這樣用??

評論

Sign In or Register to comment.