// FUNKCJA SPRAWDZAJACA WYMIARY PLIKU
// JAK ROZDZIELCZOSC PLIKU JEST ZA DUZA WYSKAKUJE BLAD
// TA FUNKCJA PRZERWIE PRACE W TAKIM WYPADKU
function SprawdzWymiary($img_path)
{
$mw=2000; // MAXYMALNY WYMIAR SZEROKOSCI OBRAZKA
$mh=2000; // MAXYMALNY WYMIAR WYSOKOSCI OBRAZKA
{
// $img_attr[0] - szerokosc, $img_attr[1] - wysoko��
if($img_attr[0] > $mw or $img_attr[0] > $mh)
{
echo '<div style="font-weight:bold; color:red;">Wyst�pi� b��d podczas dodawania obrazka ,zbyt du�a rozdzielczo�� !!!</div> Nazwa pliku: '.$img_path.'
Rozdzielczo�� obrazka - szeroko�� : <b>'.$w.'</b> , wysoko�� <b> '.$h.'</b> <br />
Maksymalna rozdzielczo�� obrazka - szeroko�� : <b>'.$mw.'</b> , wysoko�� <b>'.$mh.'</b> <br />';
return false;
}
}
return true;
}
function MakeMinImg($img_path,$thumb_path,$max_width=100,$max_height=100)
{
if(!SprawdzWymiary($img_path)) return false;
//Sprawdzamy czy obraz istnieje
if(!file_exists($img_path))die('<p>Plik '.$img_path.' nie istnieje!!</p>');
//Pobieramy informacjie o obrazie
//Sprawdzamy czy obraz jest wiekszy na szeroko�� czy na wysoko��
// i zmniejszamy odpowiednio rozmiar
// $img_attr[0] - szerokosc, $img_attr[1] - wysoko��
if($img_attr[0]>$img_attr[1]){
$scale = $img_attr[0] / $max_width;
}else{
$scale = $img_attr[1] / $max_height;
}
//Tworzymy obraz miniaturki
$w = floor($img_attr[0
]/$scale); $h = floor($img_attr[1
]/$scale); $thumb = imagecreatetruecolor($w,$h);
//Kopiujemy obraz pomniejszajac go,
imagecopyresampled($thumb, imagecreatefromjpeg($img_path), 0, 0, 0, 0, $w, $h, $img_attr[0], $img_attr[1]);
//Zapisujemy do pliku (jako�� 100)
imagejpeg($thumb,$thumb_path,100);
};
function miniaturka($o_file, $t_file, $t_wd = 100, $t_ht = 100, $prop= true)
{
if(!SprawdzWymiary($t_file)) return false;
$image_info = getImageSize($o_file) ; // let's get MIME Type
switch ($image_info['mime']) {
case 'image/gif':
if (imagetypes() & IMG_GIF) {
$o_im = @imageCreateFromGIF($o_file);
imagecolortransparent($o_im, imagecolorallocate ($o_im, 255, 255, 255));
}
else
$ermsg = 'GIF images are not supported<br />';
break;
case 'image/jpeg':
if (imagetypes() & IMG_JPG)
$o_im = @imageCreateFromJPEG($o_file);
else
$ermsg = 'JPEG images are not supported<br />';
break;
default:
$ermsg = $image_info['mime'].' images are not supported<br />';
break;
}
$o_wd = imagesx($o_im);
$o_ht = imagesy($o_im);
if ($t_wd > $o_wd) $t_wd = $o_wd;
if ($t_ht > $o_ht) $t_ht = $o_ht;
if ($prop == true) {
//check sizes if the width was deciding...
// then thumbnail width = target * original width / original height
$t_wd_n = floor($o_wd * $t_ht / $o_ht) ; //check sizes if the height was deciding...
// then thumbnail height = target * original width / original height
$t_ht_n = floor($o_ht * $t_wd / $o_wd) ;
// if calculated width is ok, we set it as target width
if ($t_wd_n < $t_wd) {
$t_wd = $t_wd_n;
}
// else check if calculated height is ok...
else if ($t_ht_n < $t_ht) {
$t_ht = $t_ht_n;
}
}
$t_im = imageCreateTrueColor($t_wd,$t_ht);
$x=imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
$y=imageJPEG($t_im,$t_file);
imageDestroy($o_im);
imageDestroy($t_im);
}
return isset($ermsg)?
$ermsg:NULL; }
function Kadruj($o_file, $t_file, $t_wd = 100, $t_ht = 100, $prop= true)
{
if(!SprawdzWymiary($t_file)) return false;
$image_info = getImageSize($o_file) ; // let's get MIME Type
switch ($image_info['mime']) {
case 'image/gif':
if (imagetypes() & IMG_GIF) {
$o_im = @imageCreateFromGIF($o_file);
imagecolortransparent($o_im, imagecolorallocate ($o_im, 0xff, 0xff, 0xff));
}
else
$ermsg = 'GIF images are not supported<br />';
break;
case 'image/jpeg':
if (imagetypes() & IMG_JPG)
$o_im = @imageCreateFromJPEG($o_file);
else
$ermsg = 'JPEG images are not supported<br />';
break;
default:
$ermsg = $image_info['mime'].' images are not supported<br />';
break;
}
$o_wd = imagesx($o_im);
$o_ht = imagesy($o_im);
/*if ($prop == true) {
//check sizes if the width was deciding...
// then thumbnail width = target * original width / original height
$t_wd_n = floor($o_wd * $t_ht / $o_ht) ;
//check sizes if the height was deciding...
// then thumbnail height = target * original width / original height
$t_ht_n = floor($o_ht * $t_wd / $o_wd) ;
// if calculated width is ok, we set it as target width
if ($t_wd_n < $t_wd) {
$t_wd = $t_wd_n;
}
// else check if calculated height is ok...
else if ($t_ht_n < $t_ht) {
$t_ht = $t_ht_n;
}
}*/
//$x=imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
$w = $t_wd;
$h = $t_ht;
$orig_w = $o_wd;
$orig_h = $o_ht;
$ratio = $w/$h;
//$ratio = 500/375; //na sztywno proporcje ;)
//$h = round($w/$ratio);//na sztywno proporcje ;)
$orig_ratio = $orig_w/$orig_h;
//echo "ratio=$ratio, orig_ratio=$orig_ratio <br>";
if($orig_ratio>$ratio) {
$neww = $w;
$newh = $h;
$yp = 0;
$xp = round( $orig_w*($orig_ratio-$ratio)/2
); //echo "xp=$xp yp=$yp";
$copyw = $orig_w-($orig_w*($orig_ratio-$ratio));
$copyh = $orig_h;
}
else {
$neww = $w;
$newh = $h;
$xp = 0;
$yp = round(($orig_h*(1
/$orig_ratio-1
/$ratio))/2
); $copyh = $orig_h-($orig_h*(1/$orig_ratio-1/$ratio));
$copyw = $orig_w;
}
$t_im = imageCreateTrueColor($w,$h);
imagecopyresampled($t_im, $o_im, 0, 0, $xp, $yp, $neww, $newh, $copyw, $copyh);
$y=imageJPEG($t_im,$t_file);
imageDestroy($o_im);
imageDestroy($t_im);
}
return isset($ermsg)?
$ermsg:NULL; }
function SkalujKadruj($img_path,$thumb_path,$max_width=100,$max_height=100)
{
if(!SprawdzWymiary($img_path)) return false;
$X = $max_width;
$Y = $max_height;
$s = imagecreatefromjpeg($img_path);
if ( !$s ) die ("imagecreatefromjpeg");
$sx = imagesx($s);
$sy = imagesy($s);
if($X > $sx) $X = $sx;
if ($Y > $sy) $Y = $sy;
$d = imagecreatetruecolor($X, $Y);
$xy = $X / (float) $Y;
if ( $sx/ (float) $sy > $xy)
{
$nx = $xy * $sy;
$ny = $sy;
$px = ($sx - $nx) /2;
$py = 0;
}
else
{
$ny = $sx / $xy;
$nx = $sx;
$py = ($sy - $ny) /2;
$px = 0;
}
imagecopyresampled ( $d, $s, 0, 0, $px, $py, $X, $Y, $nx, $ny );
imagedestroy($s);
imagejpeg($d,$thumb_path);
imagedestroy($d);
}