public static function save($image, $path, $format)
    {
        switch ($format) {
            case IMAGETYPE_JPEG:
                $result = imagejpeg($image, $path, 100);
                break;
            case IMAGETYPE_PNG:
                $result = imagepng($image, $path, 9);
                break;
            case IMAGETYPE_GIF:
                $result = imagegif($image, $path);
                break;
        }

        if (!$result) {
            throw new \Exception("Failed to save image (" . $path . ")");
        }
    }