コード例 #1
0
 /**
  * Reads and returns the type of the image
  *
  * @return bool|string
  */
 public function parseType()
 {
     if (!$this->type) {
         $this->stream->resetPointer();
         switch ($this->stream->read(2)) {
             case "BM":
                 return $this->type = 'bmp';
             case "GI":
                 return $this->type = 'gif';
             case chr(0xff) . chr(0xd8):
                 return $this->type = 'jpeg';
             case "":
                 switch ($this->readByte($this->stream->peek(1))) {
                     case 1:
                         return $this->type = 'ico';
                     case 2:
                         return $this->type = 'cur';
                 }
                 return false;
             case chr(0x89) . 'P':
                 return $this->type = 'png';
             case "RI":
                 if (substr($this->stream->read(10), 6, 4) == 'WEBP') {
                     return $this->type = 'webp';
                 }
                 return false;
             case '8B':
                 return $this->type = 'psd';
             case "II":
             case "MM":
                 return $this->type = 'tiff';
             default:
                 return false;
         }
     }
     return $this->type;
 }