creating thumbnails

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
loloziberlo

Wed Sep 11, 2002 3:20 am

Hi, i have tried this "thumbnail on the fly" script, but doesn't work; it seems that i must copy the mysql image to a temp file in order to use the "ImageCreateFromJPEG" function correctly. Does anybody know how to do this preliminar operation?

here is my script:

<?php
mysql_connect("localhost", "root", "password");
mysql_select_db("yourDB");

$query = "select bin_data,filetype from youTABLE where fid=$id";
$result = mysql_query($query);
$data = mysql_result($result,0,"bin_data");
$type = mysql_result($result,0,"filetype");

Header("Content-type: $type");

$src = imagecreatefromjpeg($data);
// HERE IS THE PROBLEM:
// instead of using $data, i should use a filename
// HELP!

$twidth = imagesx($src)/3;
$theight = imagesy($src)/3;
$img = imagecreate($twidth,$theight);
imagecopyresized($img,$src,0,0,0,0,$twidth,$theight,imagesx($src),imagesy($src));
imagejpeg($img);
imagedestroy($img);
?>

User avatar
WiZARD
Moderator
Moderator
Posts: 1240
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Thu Sep 12, 2002 3:33 am

loloziberlo wrote:Hi, i have tried this "thumbnail on the fly" script, but doesn't work; it seems that i must copy the mysql image to a temp file in order to use the "ImageCreateFromJPEG" function correctly. Does anybody know how to do this preliminar operation?

here is my script:

<?php
mysql_connect("localhost", "root", "password");
mysql_select_db("yourDB");

$query = "select bin_data,filetype from youTABLE where fid=$id";
$result = mysql_query($query);
$data = mysql_result($result,0,"bin_data");
$type = mysql_result($result,0,"filetype");

Header("Content-type: $type");

$src = imagecreatefromjpeg($data);
// HERE IS THE PROBLEM:
// instead of using $data, i should use a filename
// HELP!

$twidth = imagesx($src)/3;
$theight = imagesy($src)/3;
$img = imagecreate($twidth,$theight);
imagecopyresized($img,$src,0,0,0,0,$twidth,$theight,imagesx($src),imagesy($src));
imagejpeg($img);
imagedestroy($img);
?>

Try this:

Code: Select all

$query="select bin_data,filetype from youTABLE where fid=$id"; 
if (!$qurey) echo("Sorry....");
imagejpeg($query,'',80);
"Sex,Drugs and Rock&Roll " replaced at "Sucks,Bugs and Plug&Play";
Image

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest