Example #1
0
File: Gd.php Project: slkxmail/App
 public function save($to, $quality = 90)
 {
     if (!$this->im) {
         return false;
     }
     $ext = pathinfo($to, PATHINFO_EXTENSION);
     if (!$ext) {
         $ext = $this->baseExt;
         $to .= '.' . $ext;
     }
     File::createDirForFileRecursive($to);
     $result = false;
     switch ($ext) {
         case self::EXT_GIF:
             $result = imagegif($this->im, $to);
             break;
         case self::EXT_JPG:
         case "jpeg":
             $result = imagejpeg($this->im, $to, $quality);
             break;
         case self::EXT_PNG:
             $result = imagepng($this->im, $to);
             break;
         default:
             throw new \Exception('Wrong extension ' . print_r($ext, true));
     }
     if (!$result) {
         throw new \Exception('Error while saving to "' . $to . '"');
     }
     return $to;
 }