ci ho lavorato molto ma non riesco a farlo funzionare
penso che vada tutto bene tranne che l'impostazione del content-type, perchè se lo setto a image/jpeg mi stampa a video la url dello script, se invece lo tolgo mi visualizza tutti caratteri strani
posto qui il codice:
codice:
<?php
include("../config.inc.php");
$query = "SELECT * FROM prodotti WHERE id_prodotto LIKE '$id'";
$result = mysql_query($query) or die('Query non valida: ' . mysql_error());
$row = mysql_fetch_array($result);
// creazione di un nome di immagine temporeno
$t_img_name = tempnam ("/tmp", "timg");
$t_img = fopen($t_img_name, "w");
// $content è il campo blob che contiene l'immagine
fwrite($t_img, $row['immagine']);
fclose($t_img);
// qui eseguto operazioni sull'immagine
list( $width, $height, $type ) = getimagesize( $t_img_name );
$new_width = 150;
$new_height = $height / $width * $new_width;
if ($type == 1)
$src_img = imagecreatefromgif( $t_img_name );
if ($type == 2)
$src_img = imagecreatefromjpeg( $t_img_name );
elseif ($type == 3)
$src_img = imagecreatefrompng( $t_img_name );
$im = Imagecreatetruecolor( $new_width, $new_height );
imagecopyresampled( $im, $src_img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
ob_start();
imagejpeg( $im );
imagedestroy( $im );
$data = ob_get_clean();
$data = addslashes( $data );
header('Content-Type: image/jpeg');
echo $data;
// cancello il file temporaneo creato
unlink($t_img_name);
mysql_close($db);
?>