EWIKI_IMAGE_MAXSIZE)) { if ($filename == $tmp_rescale) { $tmp_rescale = tempnam(EWIKI_TMP, "ewiki.img_resize_gd.tmp."); } #-- sizes $new_x = (int) ($orig_x * $r); $new_y = (int) ($orig_y * $r); #-- new gd image $tc = function_exists("imageistruecolor") && imageistruecolor($orig_image); if (!$tc || ($type == "gif")) { $new_image = imagecreate($new_x, $new_y); imagepalettecopy($new_image, $orig_image); } else { $new_image = imagecreatetruecolor($new_x, $new_y); } #-- resize action imagecopyresized($new_image, $orig_image, 0,0, 0,0, $new_x,$new_y, $orig_x,$orig_y); #-- special things if ( ($type == "png") && function_exists("imagesavealpha") ) { imagesavealpha($new_image, 1); } #-- save if (function_exists($pf = "image$type")) { $pf($new_image, $tmp_rescale); } else { return(false); # cannot save in orig format (.gif) } #-- prepare next run imagedestroy($new_image); clearstatcache(); $r *= 0.95; } #-- stop imagedestroy($orig_image); #-- security check filesizes, abort if (!filesize($filename) || !filesize($tmp_rescale) || (filesize($tmp_rescale) > EWIKI_IMAGE_MAXSIZE)) { unlink($tmp_rescale); return($false); } #-- set $mime, as it may have changed (.gif) $mime = strtok($mime, "/") . "/" . $type; if (!strstr($filename, ".$type")) { unlink($filename); $filename .= ".$type"; } #-- move tmp file to old name copy($tmp_rescale, $filename); unlink($tmp_rescale); return(true); } ?>