public function save($path, $format = null, $quality = null)
{
$format = strtolower($format);
if (!$format || $format == "png32") {
$format = "png";
}
if (!$this->reinitializing && $this->getUseContentOptimizedFormat()) {
$format = "pjpeg";
if ($this->hasAlphaChannel()) {
$format = "png";
}
}
// progressive jpeg
if ($format == "pjpeg") {
imageinterlace($this->resource, true);
$format = "jpeg";
}
if ($format == "jpg") {
$format = "jpeg";
}
$functionName = 'image' . $format;
if (!function_exists($functionName)) {
$functionName = "imagepng";
}
// always create a PNG24
if ($format == "png") {
imagesavealpha($this->resource, true);
}
switch ($format) {
case 'jpeg':
$functionName($this->resource, $path, $quality);
break;
default:
$functionName($this->resource, $path);
}
return $this;
}