Codice PHP:
<?
if ((isset($_POST["act"])) AND ($_POST["act"] == "upload") ){
if(isset($_FILES["file"]["size"])){
$id = $_POST["id"];
$file =$_FILES["file"]["name"];
$arr_ext = array("gif","jpg","jpeg");
list($ok_upload,$end_result,$file_name) = uploadFile("../public/cani/".$id."/foto/",$_FILES["file"],$arr_ext);
if($ok_upload){
//-------------------------------- Funzione per creare la thumb
include("../include/gd.php");
$img = "../public/cani/".$id."/foto/".$file; // percorso al file dell'immagine
$dest = "../public/cani/".$id."/thumb/".$file; // directory di salvataggio delle miniature create
// dimensioni della miniatura da creare
$thumbWidth = 100; // larghezza
$thumbHeight = 100; // altezza
// livello di compressione della miniatura
$thumbComp = 80;
// creazione dell'immagine della miniatura
$thumb = imagecreatetruecolor($thumbWidth, $thumbHeight) or die("Impossibile creare la miniatura");
// apertura dell'immagine originale
$src = imagecreatefromjpeg($img) or die ("Impossibile aprire l'immagine originale");
// copio l'immagine originale in quella della miniatura ridimensionandola
imagecopyresampled($thumb, $src, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imageSx($src), imageSy($src)) or die("Impossibile ridimensionare l'immagine");
// salvataggio miniatura
imagejpeg($thumb, $dest, $thumbComp) or die("Impossibile salvare la miniatura");
echo "<script>self.location.href='appalti_foto.php?id=".$id."';</script>";
stampa_msg();
}else{
stampa_msg("Il file non è stato caricato:
".$end_result);
}
}else{
stampa_msg("Nessun file selezionato");
}
}else{
?>
Per quantoriguarad la funzione per l'inserimento dei cani nel database io fare i in questo modo:
Codice PHP:
<?
function GDVersion(){
if( !in_array('gd', get_loaded_extensions()) ) return 0;
elseif( isGD2supported() ) return 2;
else return 1;
}
function isGD2supported(){
global $GD2;
if( isset($GD2) AND $GD2 ) return $GD2;
else{
$php_ver_arr = explode('.', phpversion());
$php_ver = intval($php_ver_arr[0])*100+intval($php_ver_arr[1]);
if( $php_ver < 402 ){ // PHP <= 4.1.x
$GD2 = in_array('imagegd2',get_extension_funcs("gd"));
}
elseif( $php_ver < 403 ){ // PHP = 4.2.x
$im = @imagecreatetruecolor(10, 10);
if( $im ){
$GD2 = 1;
@imagedestroy($im);
}
else $GD2 = 0;
}
else{ // PHP = 4.3.x
$GD2 = function_exists('imagecreatetruecolor');
}
}
return $GD2;
}
function IsFormatSupported($format){
if( ($format == 'gif') AND (imagetypes() & IMG_GIF) )return true;
elseif( ($format == 'jpeg') AND (imagetypes() & IMG_JPG) )return true;
elseif( ($format == 'png') AND (imagetypes() & IMG_PNG) )return true;
else return false;
}
function ApplicaBordo(&$imres){
$h = imagesy($imres)-1;
$w = imagesx($imres)-1;
$white = imagecolorallocate($imres, 255, 255, 255);
$black = imagecolorallocate($imres, 0, 0, 0);
imagerectangle($imres, 0, 0, $w, $h, $black); // Bordo composto da una linea esterna nera
imagerectangle($imres, 1, 1, $w-1, $h-1, $white); // e da una linea interna bianca
}
function imagemyrectangle(&$imgres, $x1, $y1, $x2, $y2, $col){
imageline($imgres, $x1, $y1, $x2-2, $y1, $col ); //top
imageline($imgres, $x1+1, $y2-1, $x2, $y2-1, $col ); //bottom
imageline($imgres, $x2-1, $y1, $x2-1, $y2-2, $col ); //right
imageline($imgres, $x1, $y1+1, $x1, $y2, $col ); //left
}
//Watermark : Anche l'applicazione di un watermark, cioè di un'immagine salvata sopra all'originale per impedirne un utilizzo al di fuori dei termini di licenza è un'operazione abbastanza semplice con le librerie GD.
function AddWaterMark(&$imgres, &$imgWM){
imageCopyMerge($imgres, $imgWM, 5, 5, 0, 0, imageSX($imgWM), imageSY($imgWM), 50); }
function make_thumb($source, $destination, $size) {
// Check if GD is installed
if(extension_loaded(’gd’) AND function_exists(’imageCreateFromJpeg’)) {
// First figure out the size of the thumbnail
list($original_x, $original_y) = getimagesize($source);
if ($original_x > $original_y) {
$thumb_w = $size;
$thumb_h = $original_y*($size/$original_x);
}
if ($original_x < $original_y) {
$thumb_w = $original_x*($size/$original_y);
$thumb_h = $size;
}
if ($original_x == $original_y) {
$thumb_w = $size;
$thumb_h = $size;
}
// Now make the thumbnail
$source = imageCreateFromJpeg($source);
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
imagecopyresampled($dst_img,$source,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
imagejpeg($dst_img, $destination);
// Clear memory
imagedestroy($dst_img);
imagedestroy($source);
// Return true
return true;
} else {
return false;
}
}
function thumb($src,$dest,$thumb_width){
//Inizio il resize
$fullsize = getimagesize($src);
if( $fullsize[2] == 2 ){$im = @imagecreatefromjpeg($src);}
elseif( $fullsize[2] == 1 ){$im = @imagecreatefromgif($src);}
elseif( $fullsize[2] == 3 ){$im = @imagecreatefrompng($src);}
$fullsize_height=$fullsize[1];
$fullsize_width=$fullsize[0];
$thumb_height=floor($fullsize_height/($fullsize_width/$thumb_width));
if( (GDVersion() == 2) AND ($fullsize[2] != 1) ){
$thumb = imagecreatetruecolor($thumb_width,$thumb_height);
imagecopyresampled($thumb, $im, 0, 0, 0, 0, $thumb_width, $thumb_height, $fullsize[0], $fullsize[1]);
}else{
$thumb = imagecreate($thumb_width,$thumb_height);
imagecopyresized($thumb, $im, 0, 0, 0, 0,$thumb_width, $thumb_height, $fullsize[0], $fullsize[1]);
}
imagejpeg($thumb, $dest, 50);
imagedestroy($im);
imagedestroy($thumb);
}
// Recupero delle dimensioni dell'immagine
function dimimage($src){
$fullsize = getimagesize($src);
if( $fullsize[2] == 2 ){$im = @imagecreatefromjpeg($src);}
elseif( $fullsize[2] == 1 ){$im = @imagecreatefromgif($src);}
elseif( $fullsize[2] == 3 ){$im = @imagecreatefrompng($src);}
$fullsize_height=$fullsize[1];
$fullsize_width=$fullsize[0];
imagedestroy($im);
return array($fullsize_width,$fullsize_height);
}
?>
Spero che ti possa servire quello che ti ho scritto.