risolto! e mi sembra giusto lasciare disponibile la soluzione per i posteri![]()
Codice PHP:<?php
// variabili definite dalla pagina che richiama lo script
// es. immagine.php?id=8&width=150
$id = $_GET["id"];
$wid = $_GET["width"];
include("../config.inc.php");
// Esegui la query
$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 dell'immagine temporanea
$t_img_name = tempnam ("/tmp", "timg");
$t_img = fopen($t_img_name, "w");
// $row['immagine'] è il campo blob del database
fwrite($t_img, $row['immagine']);
fclose($t_img);
// Qui eseguo le modifiche desiderate sull'immagine
Header("Content-type: image/jpeg");
list( $width, $height, $type ) = getimagesize( $t_img_name );
$new_width = $wid;
$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);
Imagejpeg($im,'',95);
ImageDestroy($im);
// cancello il file temporaneo creato
unlink($t_img_name);
mysql_close($db);
?>

Rispondi quotando