$hmax) { $d = $h / $hmax; $h = $hmax; $w = $w / $d; } if ($w > $wmax) { $d = $w / $wmax; $w = $wmax; $h = $h / $d; } $dim[] = $h; $dim[] = $w; return ($dim); } function gestimg_par($img, $hmax, $wmax){ $imagehw = getimagesize("$img"); $h = $imagehw[1]; $w = $imagehw[0]; if ($h > $hmax) { $d = $h / $hmax; $h = $hmax; $w = $w / $d; } if ($w > $wmax) { $d = $w / $wmax; $w = $wmax; $h = $h / $d; } $dim[] = intval($h); $dim[] = intval($w); return ($dim); } function generate_rnd($len){ $rnd = ""; for ($i = 0; $i<$len; $i++) if ($i % 2) $rnd .= rand (0,9); else $rnd .= chr(rand(65,90)); return ($rnd); } $basepath = "./Gestione/uploads_blog/"; $destpath = "./Gestione/uploads_blog/"; function generaimg($foto, $wmax, $hmax, $suffisso,$marg,$rgb,$ignora,$ritaglio){ global $basepath, $destpath; $srcX = 0; $srcY = 0; if (( $foto != "" ) && file_exists($basepath.$foto)){ $source = $basepath.$foto; $d = gestimg_par($source,$hmax,$wmax); $img = $destpath.$suffisso."_".$foto; $info = stat("$source"); $byte = $info[7]; if ($byte >= 1800000) return (false); $size = getimagesize ("$source"); $lmod = date("Ymd", filemtime ($source)); $lmodt = date("Ymd", filemtime ($img)); $mime = $size["mime"]; $mime = split("/", $mime); $fm = "imagecreatefrom".$mime[1]; $fi = "image".$mime[1]; if (($lmod > $lmodt)|| $ignora){ $im = $fm($source); $small = imagecreatetruecolor($wmax, $hmax); if ($ritaglio == FALSE) { $offs_w = (($wmax - $d[1]) / 2) + ceil($marg/2); $offs_h = (($hmax - $d[0]) / 2) + ceil($marg/2); } else { $offs_w = 0; $offs_h = 0; $h_tmp = $size[1]; $w_tmp = $size[0]; if (($wmax/$hmax) >= ($size[0]/$size[1])) { $size[1] = $size[0]/$wmax*$hmax; $diff = $h_tmp - $size[1]; $srcY = ceil($diff / 2); } else { $size[0] = $size[1]*$wmax/$hmax; $diff = $w_tmp - $size[0]; $srcX = ceil($diff / 2); } $d[1]=$wmax; $d[0]=$hmax; } $back = imagecolorallocate($small, $rgb[0], $rgb[1], $rgb[2]); imagefilledrectangle($small, 0, 0, $wmax, $hmax, $back); imagecopyresampled($small, $im, $offs_w, $offs_h, $srcX, $srcY, $d[1], $d[0], $size[0], $size[1]); $fi ($small, $img); } } else $img = false; return ($img); } ?>