|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Sep 2003
Città: Milano
Messaggi: 4623
|
[php]modificare la grandezza delle immagini in upload??
vorrei sapere se posso salvare durante l'upload sul server le immagini in grandezze diverse, nel senso che vorrei salvare una versione originale nomeimmagine.jpg e automaticamente una versione del file nominata nomeimmagine_small.jpg con un formato fisso tipo 80x60 da usare come preview nella mia applicazione web.
è possibile?
__________________
Ho trattato con : lahiri, czame, RC, allXXX, dfruggeri, JMM, Paperone, xej, Pappez, iperfly, Red81, Playmake, ryan78, Rob66, XP2200, Peach1200, faberjack, Stewie82, supermario_bros, hft500, Axelscorpio, pipes lee, Piccolospazio, RohanKish, miki66, kabira85 |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Certo, devi usare le librerie gd2...che sono solitamente comprese in php...
|
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Sep 2002
Città: Monza
Messaggi: 598
|
io ho usato il codice sotto riportato per limitare la dimensione dei file in upload e per creare le miniature, spero ti sia di aiuto.
Codice:
$sizelimit = "yes"; //Vuoi imporre un limete massimo di dimensioni? $sizebytes = "225760"; //dimensioni massime in bytes $absolute_path = "/qualcosa/qualcosaltro/ecc"; //indirizzo assoluto sul server $dir = "dir"; if ($file != "") { if (file_exists("$absolute_path/$file_name")) { die("errore2: Un file con lo stesso nome è già online, RINOMINARLO e inviarlo nuovamente"); } if (($sizelimit == "yes") && ($file_size > $sizebytes)) { die("errore3: Il file che stai per caricare è troppo grande. Le dimensioni massime consentite sono di 200Kb"); } @copy($file, "$absolute_path/$file_name") or die("errore4: Problemi sul server... riprova più tardi o scrivici una email"); echo "File <b>".$file_name."</b> caricato Correttamente"; l//crea la miniatura $wsize = 100; //larghezza massima e... $hsize = 100; //altezza massima della thumbnail $im_size = GetImageSize($file); $imageWidth = $im_size[0]; $imageHeight = $im_size[1]; $thumb_width = $wsize; $thumb_height = $hsize; $im2 = ImageCreateFromJPEG($file); if ($imageWidth>=$imageHeight) { $width = $thumb_width; $height = ($width/$imageWidth)*$imageHeight; } else { $height = $thumb_height; $width = ($height/$imageHeight)*$imageWidth; } $im = imageCreateTrueColor($width, $height); if (function_exists('ImageCopyResampled')) { ImageCopyResampled($im,$im2, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight); } else { ImageCopyResized($im,$im2, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight); } $nome_file_output=$absolute_path."/miniature/mini_".$file_name; Header("Content-type: image/jpg"); Imagejpeg($im, $nome_file_output, 85); //85 è la qualità (da 1 a 100) ImageDestroy($im); ImageDestroy($im2); } else { die("errore5: Non hai selezionanto nessun file!!!"); } a presto
__________________
Nunc est bibendum |
![]() |
![]() |
![]() |
#4 | |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
#5 | |
Senior Member
Iscritto dal: Sep 2003
Città: Milano
Messaggi: 4623
|
Quote:
ehm.... cosa non va? Codice:
File prova.jpg caricato Correttamente Fatal error: Call to undefined function: imagecreatefromjpeg() in c:\programmi\easyphp1-8\www\testup.php on line 38
__________________
Ho trattato con : lahiri, czame, RC, allXXX, dfruggeri, JMM, Paperone, xej, Pappez, iperfly, Red81, Playmake, ryan78, Rob66, XP2200, Peach1200, faberjack, Stewie82, supermario_bros, hft500, Axelscorpio, pipes lee, Piccolospazio, RohanKish, miki66, kabira85 |
|
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Non hai abilitato l'estensione php_gd2.dll
|
![]() |
![]() |
![]() |
#7 |
Senior Member
Iscritto dal: Sep 2003
Città: Milano
Messaggi: 4623
|
ok perfetto funziona, ma.... unica cosa ho 2 file uno con una form ed il secodo esegue tutto, devo salvare delle locandine... beh praticamente
Codice:
<? $sizelimit = "no"; //Vuoi imporre un limete massimo di dimensioni? $sizebytes = "225760"; //dimensioni massime in bytes $absolute_path = "./prova"; //indirizzo assoluto sul server $dir = "dir"; if ($_POST['file'] != "") { $mese=$_POST['mese']; $giorno=$_POST['giorno']; $file=$_POST['file']; $file_name ="locandina_".$giorno."_".$mese."_big.jpg"; if (file_exists("$absolute_path/$file_name")) { die("errore2: Un file con lo stesso nome è già online, RINOMINARLO e inviarlo nuovamente"); } if (($sizelimit == "yes") && ($file_size > $sizebytes)) { die("errore3: Il file che stai per caricare è troppo grande. Le dimensioni massime consentite sono di 200Kb"); } @copy($file, "$absolute_path/$file_name") or die("errore4: Problemi sul server... riprova più tardi o scrivici una email"); //crea la miniatura $wsize = 200; //larghezza massima e... $hsize = 200; //altezza massima della thumbnail $im_size = GetImageSize($file); $imageWidth = $im_size[0]; $imageHeight = $im_size[1]; $thumb_width = $wsize; $thumb_height = $hsize; $im2 = imagecreatefromjpeg($file); if ($imageWidth>=$imageHeight) { $width = $thumb_width; $height = ($width/$imageWidth)*$imageHeight; } else { $height = $thumb_height; $width = ($height/$imageHeight)*$imageWidth; } $im = imageCreateTrueColor($width, $height); if (function_exists('ImageCopyResampled')) { ImageCopyResampled($im,$im2, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight); } else { ImageCopyResized($im,$im2, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight); } $nome_file_output="$absolute_path/locandina_".$giorno."_".$mese."_small.jpg"; Header("Content-type: image/jpg"); Imagejpeg($im, $nome_file_output, 85); //85 è la qualità (da 1 a 100) ImageDestroy($im); ImageDestroy($im2); } else { die("errore5: Non hai selezionanto nessun file!!!"); } ?>
__________________
Ho trattato con : lahiri, czame, RC, allXXX, dfruggeri, JMM, Paperone, xej, Pappez, iperfly, Red81, Playmake, ryan78, Rob66, XP2200, Peach1200, faberjack, Stewie82, supermario_bros, hft500, Axelscorpio, pipes lee, Piccolospazio, RohanKish, miki66, kabira85 |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 06:40.