Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi !
Hope Someone can help me here.
What I'm trying to do is obtain data from an Image BLOB field in MySQL
and create a thumbnail from that info using PHP GD Toolkit.
Ok, so here's how I'm doin it :
I have the class maneja_img that goes something like this :Code: Select all
<?php
include "xml_feed.php" //Class that parses data from an XML File
?>
<?php
$xml_feed = &New xml_feed;
$datosxml = $xml_feed->leeyobt(); //Parse Now
$thumbnailmi = $datosxml['thumbnailmi']; //Value is 100
$thumbnailme = $datosxml['thumbnailme']; //Value is 400
define("ALTURA", $thumbnailmi);
define("ALTURA2", $thumbnailme);
define("NAMETHUMB", "/tmp/thumbtemp"); //Unused Here
define("NAMETHUMB2", "/tmp/thumbtemp2"); //Unused Here
?>
<?php
class maneja_img{
//this array defines Image mime Types
var $mimetypes = array("image/jpeg", "image/pjpeg", "image/gif", "image/png");
// Here we go !
function thumdbd($idfoto){
//SQL Query
$sql = "SELECT foto, mime FROM fotografias WHERE idfoto = $idfoto";
$link = mysql_connect("localhost:8889", "root", "root") or
die(mysql_error($link));;
mysql_select_db("filestorage", $link) or die(mysql_error($link));
$conn = mysql_query($sql, $link) or die(mysql_error($link));
$datos = mysql_fetch_array($conn);
$imagen = $datos['foto']; //Image BLOB Data
$mime = $datos['mime']; //Image mime type
//First I write BLOB data into a temporary file in /tmp dir
$t_img_name = tempnam("/tmp", "timg");
$t_img = fopen($t_img_name, "w");
//write data into file
fwrite($t_img, $imagen);
fclose($t_img);
//check for mime type
switch($mime) {
case $mimetypes[0]:
case $mimetypes[1]:
$img = imagecreatefromjpeg($t_img_name);
break;
case $mimetypes[2]:
$img = imagecreatefromgif($t_img_name);
break;
case $mimetypes[3]:
$img = imagecreatefrompng($t_img_name);
break;
}
//thumb attributes
$datos = getimagesize($t_img_name);
$ratio = ($datos[1]/ALTURA);
$ancho = round($datos[0]/$ratio);
$thumb = imagecreatetruecolor($ancho, ALTURA);
imagecopyresized($thumb, $img, 0, 0, 0, 0, $ancho, ALTURA,
$datos[0], $datos[1]);
switch($mime) {
case $mimetypes[0]:
case $mimetypes[1]:
imagejpeg($thumb, $t_img_name);
break;
case $mimetypes[2]:
imagegif($thumb, $t_img_name);
break;
case $mimetypes[3]:
imagepng($thumb, $t_img_name);
break;
}
$fp = fopen($t_img_name, "rb");
$tthumb = fread($fp, filesize($t_img_name));
$tthumb = addslashes($tthumb);
fclose($fp);
unlink($t_img_name);
//Specify a header and print the new Image
header("Content-type: $mime");
echo $tthumb;
}
}goes like this
Code: Select all
<html>
<body>
<?php
include "maneja_img.php"
?>
<?php
$maneja_img = &New maneja_img;
$id = 37; //index of the image in the DataBase
$maneja_img->thumdbd($id);
?>
</body>
</html>What I'm I doing wrong ??
Thanks in advance !!
Jose
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]