示例#1
0
文件: Server.php 项目: mambax7/glide
 /**
  * Generate manipulated image.
  * @param  string                $path   Image path.
  * @param  array                 $params Image manipulation params.
  * @return string                Cache path.
  * @throws FileNotFoundException
  * @throws FilesystemException
  */
 public function makeImage($path, array $params)
 {
     $sourcePath = $this->getSourcePath($path);
     $cachedPath = $this->getCachePath($path, $params);
     if ($this->cacheFileExists($path, $params) === true) {
         return $cachedPath;
     }
     if ($this->sourceFileExists($path) === false) {
         throw new FileNotFoundException('Could not find the image `' . $sourcePath . '`.');
     }
     $source = $this->source->read($sourcePath);
     if ($source === false) {
         throw new FilesystemException('Could not read the image `' . $sourcePath . '`.');
     }
     // We need to write the image to the local disk before
     // doing any manipulations. This is because EXIF data
     // can only be read from an actual file.
     $tmp = tempnam(sys_get_temp_dir(), 'Glide');
     if (file_put_contents($tmp, $source) === false) {
         throw new FilesystemException('Unable to write temp file for `' . $sourcePath . '`.');
     }
     try {
         $write = $this->cache->write($cachedPath, $this->api->run($tmp, $this->getAllParams($params)));
         if ($write === false) {
             throw new FilesystemException('Could not write the image `' . $cachedPath . '`.');
         }
     } catch (FileExistsException $exception) {
         // This edge case occurs when the target already exists
         // because it's currently be written to disk in another
         // request. It's best to just fail silently.
     }
     unlink($tmp);
     return $cachedPath;
 }
示例#2
0
文件: Server.php 项目: awebc/web_xbf
 /**
  * Generate manipulated image.
  * @return Request           The request object.
  * @throws NotFoundException
  */
 public function makeImage()
 {
     $request = $this->resolveRequestObject(func_get_args());
     if ($this->cacheFileExists($request) === true) {
         return $request;
     }
     if ($this->sourceFileExists($request) === false) {
         throw new NotFoundException('Could not find the image `' . $this->getSourcePath($request) . '`.');
     }
     $source = $this->source->read($this->getSourcePath($request));
     if ($source === false) {
         throw new FilesystemException('Could not read the image `' . $this->getSourcePath($request) . '`.');
     }
     try {
         $write = $this->cache->write($this->getCachePath($request), $this->api->run($request, $source));
     } catch (FileExistsException $exception) {
         // Cache file failed to write. Fail silently.
         return $request;
     }
     if ($write === false) {
         throw new FilesystemException('Could not write the image `' . $this->getCachePath($request) . '`.');
     }
     return $request;
 }