function saveGIF($input, $output, $w=NULL, $h=NULL, $trans=NULL, $delete_input=0) { if(!$in = imagecreatefromjpeg($input)) { exit("Unable to create jpg image from [$input]!"); } $inw = imagesx($in); $inh = imagesy($in); if($delete_input) { if(!unlink($input)) { exit("Unable to delete input image: [$input]!"); } } if(!$w || !$h) { $w = $inw; $h = $inh; } $out = imagecreatetruecolor($w,$h); if($trans) { $trans = explode('-', $trans); $trans = imagecolorallocate( $out, 0xff, 0xff, 0xff); imagefill($out,0,0,$trans); imagecolortransparent($out, $trans); } // promena velicine fajla $inx = $iny = 0; if($w>$h) { $in_w = $inw; $in_h = ceil($inw*$h/$w); $iny = ceil(($inh-$in_h)/2); } else { $in_h = $inh; $in_w = ceil($inh*$w/$h); $inx = ceil(($inw-$in_w)/2); } imagecopyresampled($out, $in, 0,0, $inx, $iny, min($w,$in_w), min($h,$in_h), $in_w, $in_h); imagetruecolortopalette($out,1,256); if(!imagegif($out, $output)) { exit("Unable to save output image: [$output]!"); } } # #