Autor | Zpráva | ||
---|---|---|---|
fridgei Profil |
#1 · Zasláno: 25. 1. 2012, 21:40:16
Potřebuji vytvořit miniatury obrázků. Mám problém s obrázky ve formátu gif, pokud obsahují průhlednost a zmenším je, místo průhledné se vykreslí černá barva. Měl jsem podobný problém s PNG obrázky, ale ten se dal snadno vyřešit. Nevíte někdo jak na to?
pro jistotu celý kód: if(isset($_GET['name'])) { $way = dirname(__FILE__) . "/photos/" . $_GET['name']; if(file_exists($way)) { $imgInfo = getimagesize($way); switch($imgInfo[2]) { case(1): $main = imagecreatefromgif($way); break; case(2): $main = imagecreatefromjpeg($way); break; case(3): $main = imagecreatefrompng($way); break; default: header('Location: ' . dirname(__FILE__) . "/photos/galaxije.jpg"); exit(); break; } if(!isset($_GET['w'])) { list($width, $height) = $imgInfo; /*image resize*/ $originalWidth = $width; $originalHeight = $height; $ratio = $width / $height; $height = 112; $width = $height * $ratio; if($width > 150) { $ratio = $height / $width; $width = 150; $height = $width * $ratio; } $newImg = imagecreatetruecolor($width, $height); /*saved alpha in image*/ if(($imgInfo[2] == 1) || ($imgInfo[2] == 3)) { imagealphablending($newImg, false); imagesavealpha($newImg, true); $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127); imagefilledrectangle($newImg, 0, 0, $width, $height, $transparent); } imagecopyresampled($newImg, $main, 0, 0, 0, 0, $width, $height, $originalWidth, $originalHeight); /*image output*/ header('Content-type: ' . $imgInfo['mime']); switch($imgInfo[2]) { case(1): imagegif($newImg, ""); break; case(2): imagejpeg($newImg, "", 100); break; case(3): imagepng($newImg, "", 9); break; default: trigger_error('resizování obrázku se nezdařilo', E_USER_WARNING); break; } imagedestroy($main); imagedestroy($newImg); } else { $watermark = imagecreatefromgif(dirname(__FILE__) . "/thumbs/watermark.gif"); list($width, $height) = getimagesize(dirname(__FILE__) . "/thumbs/watermark.gif"); list($mainWidth, $mainHeight) = getimagesize($way); $x = ($mainWidth / 2) - ($width / 2); $y = ($mainHeight / 2) - ($height / 2); if(($imgInfo[2] == 1) || ($imgInfo[2] == 3)) { imagealphablending($main, false); imagesavealpha($main, true); } imagecopymerge($main, $watermark, $x, $y, 0, 0, $width, $height, 30); header('Content-type: ' . $imgInfo['mime']); switch($imgInfo[2]) { case(1): imagegif($main, ""); break; case(2): imagejpeg($main, "", 100); break; case(3): imagepng($main, "", 9); break; default: trigger_error('resizování obrázku se nezdařilo', E_USER_WARNING); break; } imagedestroy($main); imagedestroy($logo); } } else { echo "error- file is not exist"; } } else { echo "error - undefined get"; } odkaz na výsledek |
||
joe Profil |
Hledat jsi asi moc nezkoušel, protože je jednodušší se zeptat.
|
||
Časová prodleva: 14 let
|
0