type = $imgtype; } function make_copy($src, $dest) { $info = getimagesize($src); if(!is_array($info) || $info[2] != $this->type) { trigger_error("Illegal argument: src is either not an image or incorrect image type", E_USER_WARNING); return FALSE; } $src_img = $this->create_image_from_file($src); # cant true color for gifs! if($this->type == IMAGE_COPIER_GIF) { # cannot call imagecreatetruecolor for GIF images $dest_img = imagecreate($info[0], $info[1]); } else { $dest_img = imagecreatetruecolor($info[0], $info[1]); } if(!$src_img || !$dest_img ) { trigger_error("Unable to allocate image resources"); return FALSE; } $res = imagecopy($dest_img, $src_img, 0, 0, 0, 0, $info[0], $info[1]); if($res === FALSE) { trigger_error("Unable to copy image", E_USER_WARNING); return FALSE; } switch( $this->type) { case IMAGE_COPIER_GIF: $res = imagegif($dest_img, $dest); break; case IMAGE_COPIER_JPG: $res = imagejpeg($dest_img, $dest); break; case IMAGE_COPIER_PNG: $res = imagepng($dest_img, $dest); break; default: break; } @imagedestroy($src_img); @imagedestroy($dest_img); return ($res !== FALSE); } /** * @access private * @return GD handle * @param string $file */ function create_image_from_file($file) { $info = getimagesize($file); if($info[2] == 1) { return imagecreatefromgif($file); } if($info[2] == 2) { return imagecreatefromjpeg($file); } if($info[2] == 3) { return imagecreatefrompng($file); } } } ?>