apache - Php GD Library PNG display issue -
apache - Php GD Library PNG display issue -
i've got gd library upload script processing , resizes images. after uploading pngs getting rendering different image, stock-looking image, on browser side, yet when opened on disk correct. i've re-saved affected pngs via photoshop , uploaded directly, fixes display issue, when upload image via script display issue returns, script encoding seems cause issue browser display, why know not.
hosting environment hetzner server. upload sample:
//resize images protected function resize($img, $w, $h, $newfilename) { //check if gd extension loaded if (!extension_loaded('gd') && !extension_loaded('gd2')) { trigger_error("gd not loaded", e_user_warning); homecoming false; } //get image size info $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('unsupported filetype!', e_user_warning); break; } //if image dimension smaller, not resize if ($imginfo[0] <= $w && $imginfo[1] <= $h) { $nheight = $imginfo[1]; $nwidth = $imginfo[0]; } else{ // yeah, resize it, maintain proportional if ($w/$imginfo[0] > $h/$imginfo[1]) { $nwidth = $imginfo[0]*($h/$imginfo[1]); $nheight = $h; } else{ $nwidth = $w; $nheight = $imginfo[1]*($w/$imginfo[0]); } } $nwidth = round($nwidth); $nheight = round($nheight); $newimg = imagecreatetruecolor($nwidth, $nheight); /* check if image png or gif, set if transparent*/ if(($imginfo[2] == 1) or ($imginfo[2]==3)){ imagealphablending($newimg, false); imagesavealpha($newimg,true); $transparent = imagecolorallocatealpha($newimg, 255, 255, 255, 127); imagefilledrectangle($newimg, 0, 0, $nwidth, $nheight, $transparent); } imagecopyresampled($newimg, $im, 0, 0, 0, 0, $nwidth, $nheight, $imginfo[0], $imginfo[1]); //generate file, , rename $newfilename switch ($imginfo[2]) { case 1: imagegif($newimg,$newfilename); break; case 2: imagejpeg($newimg,$newfilename,100); break; case 3: imagepng($newimg,$newfilename,0); break; default: trigger_error('failed resize image!', e_user_warning); break; } homecoming $newfilename; }
can give me insight this. provide more info if necessary. ty
edit: browser display disk display
i have no clue image coming from, it's on multiple uploads, when browsing total path image on browser same image comes it's not pathing issue.
php apache browser png gd
Comments
Post a Comment