creating thumbnails

images php coding issues or problems here.

Moderators: macek, egami, gesf

loloziberlo
New php-forum User
New php-forum User
Posts: 5
Joined: Fri Aug 30, 2002 2:19 am
Contact:

creating thumbnails

Postby 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: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: creating thumbnails

Postby WiZARD » 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);


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 2 guests