php(pagina thumbnail.php)<?
class thumbnail {
var $file;
var $bgColorSr;
var $imD;
function thumbnail( $file, $newWidth, $newHeight, $bgColor = "#FFFFFF", $fixed = false ) {
$this->file = $file;
if ($this->file) {
$sorgente = $_SERVER['DOCUMENT_ROOT'].$this->file;
$imS = @ImageCreateFromJPEG($sorgente);
$sX = ImagesX($imS); $sY = ImagesY($imS);
if (($sX > $newWidth) || ($sY > $newHeight)) {
if ($sX > $sY ) {
$cfg[height] = $newHeight;
$cfg[width] = round($cfg[height] * $sX / $sY);
$psX = 0;
$psY = 0;
} else {
$cfg[width] = $newWidth;
$cfg[height] = round($cfg[width] * $sY / $sX);
$psX = 0;
$psY = 0;
}
} else {
$cfg[height] = $sY;
$cfg[width] = $sX;
$psX = 0;
$psY = 0;
}
$realWidth = $cfg[width];
$realHeight = $cfg[height];
if ($fixed) {
if ($cfg[height]>$newHeight) {
$cfg[width] = round($cfg[width] * $newHeight / $cfg[height]);
$cfg[height] = $newHeight;
$psX = 0;
$psY = 0;
}
if ($cfg[width]>$newWidth) {
$cfg[height] = round($cfg[height] * $newWidth / $cfg[width]);
$cfg[width] = $newWidth;
$psY = 0;
$psX = 0;
}
$realWidth = $cfg[width];
$realHeight = $cfg[height];
}
if ($this->gd_version()>=2) $this->imD = @ImageCreateTrueColor($realWidth, $realHeight);
else $this->imD = @ImageCreate($realWidth, $realHeight);
@ImageCopyResized($this->imD, $imS, $psX, $psY, 0, 0, $cfg[width], $cfg[height], $sX, $sY);
return true;
} else return false;
}
/*
Analisi Versione Librerie GD
*/
function gd_version() {
static $gd_version_number = null;
if ($gd_version_number === null) {
ob_start();
phpinfo(8);
$module_info = ob_get_contents();
ob_end_clean();
if (preg_match("/bgds+versionb[^d\n\r]+?([d.]+)/i",$module_info,$matches)) $gd_version_number = $matches[1];
else $gd_version_number = 0;
}
return $gd_version_number;
}
/*
Funzione per Conversione da Esadecimale a Decimale
*/
function HexToDec( $Hex ) {
if (strlen($Hex)==7) {
$Hex = strtoupper(str_replace("#","",$Hex));
$this->bgColorSr = ImageColorAllocate($this->imD, hexdec(substr($Hex,0,2)), hexdec(substr($Hex,2,2)), hexdec(substr($Hex,4,2)));
return true;
} else return false;
}
}
$Thumb = new thumbnail( $_GET[f], 640, 480, "#FFFFFF", true );
header("Expires: ".gmdate("D, d M Y H:i:s")."GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: image/jpeg");
@ImageJPEG($Thumb->imD, "", 100);
@ImageDestroy($Thumb->imD);
?>