2011-10-01 98 views
0

我呼應從BLOB列收到從MySQL這樣的數據:PHP調整大小的團塊圖像

<?php 
$con = mysql_connect("localhost","username","pass"); 
if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 
    mysql_select_db("mydb", $con); 
    if(isset($_GET['imageid'])){ 
     $img=$_GET['imageid']; 
     $sql="SELECT image FROM vrzgallery WHERE id=$img"; 
     $que=mysql_query($sql); 
     $ar=mysql_fetch_assoc($que); 
     echo $ar['image']; 
     header('Content-type: image/jpeg'); 
    } 

?> 

問題:我怎樣才能減少我的形象的說像500像素X 500像素

+0

當然上面是一個錯字,並且要調用'標題()''之前回波$ AR [ '圖像']'而不是之後? –

+0

[用PHP調整圖像大小]的可能的副本(http://stackoverflow.com/questions/7393319/resize-images-with-php) –

+0

另一個示例http://stackoverflow.com/questions/7551608/image-resize- with -php –

回答

-1

它在DB中存儲圖像真的不好,因爲它們太大,難以維護,難以操作等等。您應該只存儲路徑或文件名。

要調整圖像大小,您可以使用PHP的GD庫。使用imagecreatefromstring()創建並使用imagecopyresized()imagecopyresampled()進行操作。 Example from manual

// File and new size 
$filename = 'test.jpg'; 
$percent = 0.5; 

// Content type 
header('Content-Type: image/jpeg'); 

// Get new sizes 
list($width, $height) = getimagesize($filename); 
$newwidth = $width * $percent; 
$newheight = $height * $percent; 

// Load 
$thumb = imagecreatetruecolor($newwidth, $newheight); 
$source = imagecreatefromjpeg($filename); 

// Resize 
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 

// Output 
imagejpeg($thumb);