View Full Version : Resize Image pulled from MYSQL

06-28-2005, 05:43 PM
Hi, I am storing an image of size X for a car, and i have various differnet pages i wish to display this image, and at different sizes and compressions. Here is my resize script, which is pretty much adapted from php.net example one for imagecopyresized, however, I am not sure how to adapt this for use with mysql.... the getimagesize fails b/c the variable is a binary string, not a path to a local file. Please help!
if(isset($_GET['car_id']) && isset($_GET['image_num']))
$car_id = $_GET['car_id'];
$img_num= 'img';
$img_num .= $_GET['image_num'];
//Get Image
require_once ('dbconnect.php');
$sql = "select $img_num from auto where id=$car_id";
$imgresult = mysql_query("$sql");

header("Content-type: image/jpeg;");
$img = mysql_result($imgresult, 0, $img_num);

$percent = 0.5;
list($width, $height) = getimagesize($img);
$new_width= $width * $percent;
$new_height = $height * $percent;

$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($img);
imagecopyresampled($image_p, $image, 0,0,0,0, $new_width, $new_height, $width, $height);
imagepeg($image_p, null, 100);