Jump to content
php.lv forumi

thumb bildes


wormy

Recommended Posts

Ok Kods gatavs..

 

Pārbaudei

Attēls: http://www.teiksmina.lv/start.PNG

Thumbs: www.teiksmina.lv/tumbs.php?pik4ers=start.PNG

 

<?php
if ($pik4ers) { 
thumb($pik4ers, 100, 100);

}
else{
echo "Soo.. where the bilde? :D";
}

function thumb($img, $w, $h, $fill = true) {
if (!extension_loaded('gd') && !extension_loaded('gd2')) {
	trigger_error("Iesledziet GD/gd2.", E_USER_WARNING);
	return false;
}
$imgInfo = getimagesize($img);
switch ($imgInfo[2]) {
case 1: $im = imagecreatefromgif($img); break;
case 2: $im = imagecreatefromjpeg($img); break;
case 3: $im = imagecreatefrompng($img); break;
default: trigger_error('Nepareizs tips.', E_USER_WARNING); break;
}

if ($imgInfo[0] <= $w && $imgInfo[1] <= $h && !$fill) {
$nHeight = $imgInfo[1];
$nWidth = $imgInfo[0];
}else{
if ($w/$imgInfo[0] < $h/$imgInfo[1]) {
	$nWidth = $w;
	$nHeight = $imgInfo[1]*($w/$imgInfo[0]);
}else{
	$nWidth = $imgInfo[0]*($h/$imgInfo[1]);
	$nHeight = $h;
}
}
$nWidth = round($nWidth);
$nHeight = round($nHeight);
$newImg = imagecreatetruecolor($nWidth, $nHeight);
imagecopyresampled($newImg, $im, 0, 0, 0, 0, $nWidth, $nHeight, $imgInfo[0], $imgInfo[1]);
header("Content-type: ". $imgInfo['mime']);
switch ($imgInfo[2]) {
case 1: imagegif($newImg); break;
case 2: imagejpeg($newImg); break;
case 3: imagepng($newImg); break;
default: trigger_error('Neiespejami.', E_USER_WARNING); break;
}

imagedestroy($newImg);
}
?>

Edited by Mikijs
Link to comment
Share on other sites

Patiesībā risinājums nav no labakajiem, vieglāk/ātrāk/ērtāk būtu thrumbu pieglabāt serverī jau pie upload!

Mikijam ieteiktu labāk neizmantot globaļus, tb $_GET['pik4ers'] nevis $pik4ers. Šeit jau itkā pofig bet dzīvē tas mēdz sagādāt ne mazums problemas, vnk nav labs stils.

Link to comment
Share on other sites

×
×
  • Create New...