示例#1
0
 /**
  * Load a resource, could be a Stream, a URL or a file
  *
  * @param $resource
  * @return bool
  */
 public function load($resource)
 {
     if (is_string($resource)) {
         if (filter_var($resource, FILTER_VALIDATE_URL) !== false) {
             $resource = $this->loadUrl($resource);
         } elseif (file_exists($resource)) {
             $file = fopen($resource, 'r');
             $resource = new Stream($file);
         }
     }
     if ($resource instanceof ResponseInterface) {
         $content_type = $resource->getHeader('Content-type');
         $this->type = str_replace('image/', '', explode(';', $content_type)[0]);
         $resource = $resource->getBody();
     }
     if ($resource instanceof StreamInterface) {
         $this->stream = new StreamWalker($resource);
         return true;
     }
     return false;
 }