Autor | Zpráva | ||
---|---|---|---|
Johnycek Profil |
#1 · Zasláno: 11. 9. 2009, 11:30:03
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 * |
#2 · Zasláno: 11. 9. 2009, 17:18:29
Chyba môže byť v riadku 9 , treba overiť
if(file_exists($name)) { if($img=imagecreatefromjpeg($name)) { //imagecopyresampled... } } |
||
Johnycek Profil |
#3 · Zasláno: 12. 9. 2009, 15:13:35
podmienka sa splní ale aj tak to ukladá čierny obrázok
|
||
fopen Profil * |
#4 · Zasláno: 12. 9. 2009, 20:00:23
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); |
||
Časová prodleva: 15 let
|
0