function SaveImage($im, $filename)
{
$res = null;
// ImageGIF is not included into some GD2 releases, so it might not work
// output png if gifs are not supported
if ($this->image_type == 1 && !function_exists('imagegif')) {
$this->image_type = 3;
}
switch ($this->image_type) {
case 1:
if ($this->save_to_file) {
//$res = ImageGIF($im,$filename);
$res = ImageGIF($im, NULL);
} else {
header("Content-type: image/gif");
$res = ImageGIF($im);
}
break;
case 2:
if ($this->save_to_file) {
$res = ImageJPEG($im, NULL, $this->quality);
} else {
header("Content-type: image/jpeg");
$res = ImageJPEG($im, NULL, $this->quality);
}
break;
case 3:
if (PHP_VERSION >= '5.1.2') {
// Convert to PNG quality.
// PNG quality: 0 (best quality, bigger file) to 9 (worst quality, smaller file)
$quality = 9 - min(round($this->quality / 10), 9);
if ($this->save_to_file) {
//$res = ImagePNG($im, $filename, $quality);
$res = ImagePNG($im, NULL, $quality);
} else {
header("Content-type: image/png");
$res = ImagePNG($im, NULL, $quality);
}
} else {
if ($this->save_to_file) {
$res = ImagePNG($im, $filename);
} else {
header("Content-type: image/png");
$res = ImagePNG($im);
}
}
break;
}
return $res;
}