Salve a tutti, io mi sono creato questo codice:
$sql = mysql_query("SELECT ext, data FROM ae_gallery WHERE id = $ID") or die(mysql_error());
$row = mysql_fetch_object($sql);
//-------------------------------------------------------
$desired_width = 500;
$desired_height = 300;
$im = imagecreatefromstring($row->data);
$new = imagecreatetruecolor($desired_width, $desired_height);
$x = imagesx($im);
$y = imagesy($im);
imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width, $desired_height, $x, $y);
$image = imagejpeg($new, null, 85);
imagedestroy($im);
$query = mysql_query("update ae_gallery set data ='$image' WHERE id = $ID") or die(mysql_error());
header('Content-type: image/$row->ext');
echo $image;
//-----------------------------------------------------
Serve per rimpicciolire immagini BLOB all'interno del database. Se pero' faccio la query $query, l'immagine $image non diventa piccola e il campo blob va giù a 1 KB, come mai? (io ho testato con un'immagine JPG di 84.6 kb e con la dimensione scelta da me dovrebbe diventare di 28 KB)
cosa dovrei modificare nella query?
Grazie a tutti in anticipo
$sql = mysql_query("SELECT ext, data FROM ae_gallery WHERE id = $ID") or die(mysql_error());
$row = mysql_fetch_object($sql);
//-------------------------------------------------------
$desired_width = 500;
$desired_height = 300;
$im = imagecreatefromstring($row->data);
$new = imagecreatetruecolor($desired_width, $desired_height);
$x = imagesx($im);
$y = imagesy($im);
imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width, $desired_height, $x, $y);
$image = imagejpeg($new, null, 85);
imagedestroy($im);
$query = mysql_query("update ae_gallery set data ='$image' WHERE id = $ID") or die(mysql_error());
header('Content-type: image/$row->ext');
echo $image;
//-----------------------------------------------------
Serve per rimpicciolire immagini BLOB all'interno del database. Se pero' faccio la query $query, l'immagine $image non diventa piccola e il campo blob va giù a 1 KB, come mai? (io ho testato con un'immagine JPG di 84.6 kb e con la dimensione scelta da me dovrebbe diventare di 28 KB)
cosa dovrei modificare nella query?
Grazie a tutti in anticipo