示例#1
0
 /**
  * @param string $file
  * @param int $width
  * @param int $height
  * @param int $method
  * @return string
  */
 public function mask($file, $width, $height, $method)
 {
     $pathinfo = pathinfo($file);
     $ext = isset($pathinfo['extension']) ? $pathinfo['extension'] : 'img';
     $replacements = [intval($width), intval($height), $pathinfo['filename'], $ext, Helpers::method2name($method), date('d'), date('m'), date('Y'), date('dmy'), time(), microtime()];
     return str_replace($this->placeholders, $replacements, $this->mask);
 }
示例#2
0
 /**
  * @param Service $thumbator
  * @param string $original
  * @param string $thumb
  * @param int $width
  * @param int $height
  * @param int $method
  * @return void
  */
 public function resize($thumbator, $original, $thumb, $width, $height, $method)
 {
     try {
         $image = Image::fromFile($original);
     } catch (UnknownImageFileException $e) {
         throw new InvalidStateException("Image: loading image error!");
     }
     // Create dirs
     Helpers::mkdir(dirname($thumb));
     // Resize image
     $image->resize($width, $height, $method);
     // Save thumb
     $image->save($thumb);
 }
示例#3
0
 /**
  * @param Service $thumbator
  * @param string $original
  * @param string $filename
  * @param int $width
  * @param int $height
  * @param int $method
  * @return string
  */
 public function placehold($thumbator, $original, $filename, $width, $height, $method)
 {
     try {
         $data = @file_get_contents(sprintf($this->placeholder, $width, $height));
         if ($data) {
             $image = Image::fromString($data);
             Helpers::mkdir(dirname($thumbator->config->getStorageDir() . DIRECTORY_SEPARATOR . $original));
             $image->save($thumbator->config->getStorageDir() . DIRECTORY_SEPARATOR . $original);
             return $thumbator->create($original, $width, $height, $method);
         }
     } catch (\Exception $e) {
         // Silent..
     }
     return sprintf($this->placeholder, $width, $height);
 }