Autor Zpráva
Johnycek
Profil
Mám problém s týmto kódom. Obrázok síce zmenší aj uloží tam kam má ale je čierny. S grafikou pracujem v php prvý krát tak ocením každú pomoc.
function resize_img($name,$path,$maxwidth,$maxheight)
  {
      list($width,$height)=getimagesize($name);
      $p_width=$width/$maxwidth;
      $p_height=$height/$maxheight;
      $new_width=(int)$width/$p_width;
      $new_height=(int)$height/$p_height;
      $new_img=imagecreatetruecolor($new_width,$new_height);
      $img=imagecreatefromjpeg($name);
      imagecopyresampled($new_img,$img,0,0,0,0,$new_width,$new_hight,$width,$height);
      imagejpeg($new_img,$path,100);
  }
fopen
Profil *
Chyba môže byť v riadku 9 , treba overiť
if(file_exists($name)) {
	if($img=imagecreatefromjpeg($name)) {
		//imagecopyresampled...
	}
}
Johnycek
Profil
podmienka sa splní ale aj tak to ukladá čierny obrázok
fopen
Profil *
Tak potom môže byť problém už len samotnom výpočte veľkosti, ja osobne použivam takyto postup:
if($width > $height) {
	$coeficient = $maxwidth / $width;
} else {
	$coeficient = $maxheight / $height;
}
$new_width = round($width * $coeficient);
$new_height = round($height * $coeficient);

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0