/**
  * @param User $model
  *
  * @return bool|null
  */
 private function deleteOldImages(User $model)
 {
     $image = $model->avatar;
     if (is_string($image)) {
         return true;
     }
     return file_exists_on_server($image) ? delete_file($image) : true;
 }
 /**
  * @param Product $model
  *
  * @return bool|null
  */
 private function deleteProductImages(Product $model)
 {
     $images = [$model->image, $model->image_large];
     $result = null;
     foreach ($images as $image) {
         if (file_exists_on_server($image)) {
             $result = delete_file($image);
         }
     }
     return $result;
 }
Example #3
0
 /**
  * Attempts to scale down an image, by finding the best fit
  *
  * @param $image
  * @param $times
  *
  * @return null|string
  */
 public function reduceImage($image, $times)
 {
     // first we check if the image exists, so that we work on it
     $result = file_exists_on_server($image);
     if ($result) {
         // create image from data provided. in this case, the data provided is the path to the image
         $oldImage = Image::make(public_path() . $image);
         // get dimensions
         $width = ceil($oldImage->getWidth() / $times);
         $height = ceil($oldImage->getHeight() / $times);
         // resize the image
         if ($this->fit) {
             $oldImage->fit($width, $height);
         } else {
             $oldImage->resize($width, $height);
         }
         // image name
         $name = str_replace($oldImage->extension, '', $this->uniqueName . '-small' . '.' . $oldImage->extension) . $oldImage->extension;
         // path variable
         $path = base_path() . $this->storageLocation . '/' . $name;
         // save new image in filesystem
         $newImage = $oldImage->save($path);
         if (empty($newImage)) {
             // failure in processing the image. nothing much we can do
             return null;
         }
         // return the path to the reduced image
         return $this->processImagePath($newImage->basePath());
     } else {
         return null;
     }
 }
 /**
  * @param Brand $model
  *
  * @return bool
  */
 public function deleting(Brand $model)
 {
     // find the image on disk and delete it
     $current_image = $model->logo;
     return file_exists_on_server($current_image) ? delete_file($current_image) : true;
 }
Example #5
0
 /**
  * Allows us to display a picture/image of a model. if it has one already
  *
  * @param Model $model
  * @param bool $fromUrl
  * @param string $image
  * @param bool $mustExistOnServer
  * @return string
  */
 function display_img($model, $fromUrl = false, $image = 'image', $mustExistOnServer = true)
 {
     if (is_null($model)) {
         // display from url
         if (file_exists_on_server($fromUrl)) {
             return asset($fromUrl);
         }
         return asset(error_image());
     }
     // if the image is not on our server, then we just skip the checks
     if ($mustExistOnServer) {
         if (file_exists_on_server($model->{$image})) {
             return asset($model->{$image});
         }
         return asset(error_image());
     }
     if (!is_null(asset($model->{$image}))) {
         return asset($model->{$image});
     }
     return asset(error_image());
 }