2011-10-01 132 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);