function save($filename = null, $quality = null)
{
// Determine quality, filename, and format
$quality = $quality ?: $this->quality;
$filename = $filename ?: $this->filename;
$format = $this->file_ext($filename) ?: $this->original_info['format'];
// Create the image
switch (strtolower($format)) {
case 'gif':
$result = imagegif($this->image, $filename);
break;
case 'jpg':
case 'jpeg':
imageinterlace($this->image, true);
$result = imagejpeg($this->image, $filename, round($quality));
break;
case 'png':
$result = imagepng($this->image, $filename, round(9 * $quality / 100));
break;
default:
throw new Exception('Unsupported format');
}
if (!$result) {
throw new Exception('Unable to save image: ' . $filename);
}
return $this;
}