Пример #1
0
 public function getAvatar(array $imgParam)
 {
     if ($this->image) {
         $image = $this->image;
     } else {
         $image = "/packages/vis/builder/img/blank_avatar.gif";
     }
     return glide($image, $imgParam);
 }
Пример #2
0
 public function getOtherImg($nameField = "additional_pictures", $paramImg = "")
 {
     if (!$this->{$nameField}) {
         return;
     }
     $images = json_decode($this->{$nameField});
     $imagesRes = [];
     foreach ($images as $imgOne) {
         if ($paramImg) {
             $imagesRes[] = glide($imgOne, $paramImg);
         } else {
             $imagesRes[] = "/" . $imgOne;
         }
     }
     return $imagesRes;
 }
Пример #3
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;
 }