Eventviva\ImageResize::scale PHP Method

scale() public method

Resizes image according to given scale (proportionally)
public scale ( integer | float $scale ) : static
$scale integer | float
return static
    public function scale($scale)
    {
        $width = $this->getSourceWidth() * $scale / 100;
        $height = $this->getSourceHeight() * $scale / 100;
        $this->resize($width, $height, true);
        return $this;
    }

Usage Example

 public function upload(Request $request)
 {
     $path = $request->path();
     $galleryName = str_replace("%20", " ", explode('/', $path));
     $input = Input::all();
     $rules = array('file' => 'image');
     $validation = Validator::make($input, $rules);
     if ($validation->fails()) {
         return Response::make($validation->errors->first(), 400);
     }
     $destinationPath = 'gallery/' . $galleryName[1];
     // upload path
     if (!file_exists("gallery/")) {
         mkdir("gallery/", 0700);
         if (!file_exists($destinationPath)) {
             mkdir($destinationPath, 0700);
         }
     }
     $extension = Input::file('file')->getClientOriginalExtension();
     // getting file extension
     $originalName = Input::file('file')->getClientOriginalName();
     $alt = substr($originalName, 0, strpos($originalName, "."));
     $fileName = rand(1111111, 9999999) . '.' . $extension;
     // renameing image
     $upload_success = Input::file('file')->move($destinationPath, $fileName);
     // uploading file to given path
     $pathAndFile = "/" . $destinationPath . "/" . $fileName;
     $thumbnailPath = "/" . $destinationPath . "/thumbs/" . $fileName;
     $thumbDir = $destinationPath . "/thumbs";
     if (!file_exists($thumbDir)) {
         mkdir($thumbDir, 0700);
     }
     $image = new ImageResize($destinationPath . "/" . $fileName);
     $image->scale(50);
     $image->save($destinationPath . "/thumbs/" . $fileName);
     $size = getimagesize(ltrim($pathAndFile, '/'));
     $lastPosition = DB::table('images')->where('category', $galleryName[1])->max('position');
     if ($lastPosition == null) {
         $lastPosition = 0;
     }
     $nextPosition = $lastPosition + 1;
     DB::table('images')->insert(['category' => $galleryName[1], 'path' => $pathAndFile, 'thumbnail' => $thumbnailPath, 'alt_tag' => $alt, 'width' => $size[0], 'height' => $size[1], 'main_gallery' => 0, 'position' => $nextPosition]);
 }
All Usage Examples Of Eventviva\ImageResize::scale