Beispiel #1
0
 public function postAction()
 {
     $image = new Image();
     $params = $this->get("request")->get("post");
     if (!is_array($params) || !array_key_exists("name", $params)) {
         throw new RequestException("wrong file upload request");
     }
     $image->set("path", $params["name"]);
     $image->save($this->get("connection"));
     return $this->allAction();
 }
Beispiel #2
0
 public function makeSmallerSize($format)
 {
     if (!$this->isImage()) {
         return false;
     }
     $resizedPathname = $this->getPathname($format);
     $img = \Image::make($this->getPathname(self::FORMAT_ORIGINAL));
     // Thumbnails.
     if ($format === self::FORMAT_THUMB) {
         $img->resize(200, 200, function ($constraint) {
             $constraint->upsize();
         });
     }
     // Display size.
     if ($format === self::FORMAT_DISPLAY) {
         $img->resize(null, 600, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
     }
     // Save the image.
     if (!is_dir(dirname($resizedPathname))) {
         mkdir(dirname($resizedPathname), null, true);
     }
     $img->save($resizedPathname);
 }
 function deleteUnusedImage()
 {
     $images = Image::where('travel', -1)->get();
     foreach ($images as $key => $image) {
         $filename = public_path() . '/uploads/' . $image->name;
         File::delete($filename);
         $image->delete();
     }
 }