示例#1
0
 public function get($source, $options)
 {
     if (!$source) {
         return;
     }
     $this->setOptions($options);
     $source = "/" . ltrim($source, "/");
     $sourceArray = pathinfo($source);
     //create variables $dirname , $basename, $extension, $filename
     extract($sourceArray);
     $this->nameFile = $filename . "_" . $this->quality . "." . $extension;
     $this->pathFolder = $dirname . "/" . $this->size;
     $this->picturePath = $this->pathFolder . "/" . $this->nameFile;
     if (self::checkExistPicture()) {
         return $this->picturePath;
     }
     try {
         $img = Image::make(public_path() . $source);
         $this->createRatioImg($img, $options);
         @mkdir(public_path() . $this->pathFolder);
         $pathSmallImg = public_path() . "/" . $this->picturePath;
         $img->save($pathSmallImg, $this->quality);
         OptmizationImg::run($this->picturePath);
         return $this->picturePath;
     } catch (\Exception $e) {
         return $e->getMessage();
     }
 }
示例#2
0
 public function doUpload($file)
 {
     $this->checkSizeFile($file);
     $extension = $file->guessExtension();
     $rawFileName = md5_file($file->getRealPath()) . '_' . time();
     $fileName = $rawFileName . '.' . $extension;
     $definitionName = $this->getOption('def_name');
     $prefixPath = 'storage/tb-' . $definitionName . '/';
     // FIXME: generate path by hash
     $postfixPath = date('Y') . '/' . date('m') . '/' . date('d') . '/';
     $destinationPath = $prefixPath . $postfixPath;
     $status = $file->move($destinationPath, $fileName);
     $data = array();
     $data['sizes']['original'] = $destinationPath . $fileName;
     $variations = $this->getAttribute('variations', array());
     foreach ($variations as $type => $methods) {
         $img = Image::make($data['sizes']['original']);
         foreach ($methods as $method => $args) {
             call_user_func_array(array($img, $method), $args);
         }
         $path = $destinationPath . $rawFileName . '_' . $type . '.' . $extension;
         $quality = $this->getAttribute('quality', 100);
         $img->save(public_path() . '/' . $path, $quality);
         $data['sizes'][$type] = $path;
     }
     $width = $this->getAttribute('img_width') ? $this->getAttribute('img_width') : 200;
     $height = $this->getAttribute('img_height') ? $this->getAttribute('img_height') : 200;
     OptmizationImg::run("/" . $destinationPath . $fileName);
     $response = array('data' => $data, 'status' => $status, 'link' => glide($destinationPath . $fileName, ['w' => $width, 'h' => $height]), 'short_link' => $destinationPath . $fileName, 'delimiter' => ',');
     return $response;
 }