public function cropImage(Request $request)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Media', 'update')) {
            return $this->noPermission();
        }
        // get all inputs
        $inputs = $request->all();
        // Where is this file beeing croped
        $app = $inputs[4];

        // extension of the current image that is in crop process
        $mediaID = $inputs[0]['mediaID'];

        // check if user has permissions to access this link
        if(!User::hasAccess('Media', 'update', $mediaID, true)) {
            return $this->noPermission();
        }

        $media = Media::find($mediaID);
        // extension of the current image that is in crop process
        $extension = $inputs[0]['extension'];
        // destination folder
        $destinationPath = $inputs[0]['fileDirectory'];
        // width and heigth that appear in frontend
        $imageApperanceWidth = $inputs[2];
        $imageApperanceHeight = $inputs[3];
        // original image
        $url = strpos($inputs[0]['url'], '?');
        if($url == false) {
            $url = $inputs[0]['url'];
        }else{
            $url = explode('?', $inputs[0]['url'])[0];
        }
        $img = Image::make($url);
        // $croppedWidth = the width of the cropped window
        $croppedWidth = $inputs[1]['width'];
        // $newWidth = the new width calculated for the original dimensions of the image
        $newWidth = round($img->width() / ($imageApperanceWidth/$croppedWidth));

        // $croppedHeight = the height of the cropped window
        $croppedHeight = $inputs[1]['height'];
        // $newHeight = the new height calculated for the original dimensions of the image
        $newHeight = round($img->height() / ($imageApperanceHeight/$croppedHeight));

        // X and Y of the crop window
        $croppedX = $request->all()[1]['x'];
        $croppedY = $request->all()[1]['y'];
        // new X and Y calculated for the original dimensions of the image
        $newX = round(($img->width() / $imageApperanceWidth) * $croppedX);
        $newY = round(($img->height() / $imageApperanceHeight) * $croppedY);

        // crop image and save the new image
        $img->crop($newWidth, $newHeight, $newX, $newY);
        $img->save($url, 100);
        $media->touch();

        $media->deleteThumbs();
        $media->createDefaultThumbs(null, $app);

        return "OK";
    }
public function cropImage(Request $request)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Media', 'update')) {
            return $this->noPermission();
        }
        // get all inputs
        $inputs = $request->all();
        // Where is this file beeing croped
        $app = $inputs[4];

        // extension of the current image that is in crop process
        $mediaID = $inputs[0]['mediaID'];

        // check if user has permissions to access this link
        if(!User::hasAccess('Media', 'update', $mediaID, true)) {
            return $this->noPermission();
        }

        $media = Media::find($mediaID);
        // extension of the current image that is in crop process
        $extension = $inputs[0]['extension'];
        // destination folder
        $destinationPath = $inputs[0]['fileDirectory'];
        // width and heigth that appear in frontend
        $imageApperanceWidth = $inputs[2];
        $imageApperanceHeight = $inputs[3];
        // original image
        $url = strpos($inputs[0]['url'], '?');
        if($url == false) {
            $url = $inputs[0]['url'];
        }else{
            $url = explode('?', $inputs[0]['url'])[0];
        }
        $img = Image::make($url);
        // $croppedWidth = the width of the cropped window
        $croppedWidth = $inputs[1]['width'];
        // $newWidth = the new width calculated for the original dimensions of the image
        $newWidth = round($img->width() / ($imageApperanceWidth/$croppedWidth));

        // $croppedHeight = the height of the cropped window
        $croppedHeight = $inputs[1]['height'];
        // $newHeight = the new height calculated for the original dimensions of the image
        $newHeight = round($img->height() / ($imageApperanceHeight/$croppedHeight));

        // X and Y of the crop window
        $croppedX = $request->all()[1]['x'];
        $croppedY = $request->all()[1]['y'];
        // new X and Y calculated for the original dimensions of the image
        $newX = round(($img->width() / $imageApperanceWidth) * $croppedX);
        $newY = round(($img->height() / $imageApperanceHeight) * $croppedY);

        // crop image and save the new image
        $img->crop($newWidth, $newHeight, $newX, $newY);
        $img->save($url, 100);
        $media->touch();

        $media->deleteThumbs();
        $media->createDefaultThumbs(null, $app);

        return "OK";
    }
public function cropImage ( Request $ request ) { // check if user has permissions to access this link if ( ! User :: hasAccess ( 'Media' , 'update' ) ) { return $ this -> noPermission ( ) ; } // get all inputs $ inputs = $ request -> all ( ) ; // Where is this file beeing croped $ app = $ inputs [ 4 ] ; // extension of the current image that is in crop process $ mediaID = $ inputs [ 0 ] [ 'mediaID' ] ; // check if user has permissions to access this link if ( ! User :: hasAccess ( 'Media' , 'update' , $ mediaID , true ) ) { return $ this -> noPermission ( ) ; } $ media = Media :: find ( $ mediaID ) ; // extension of the current image that is in crop process $ extension = $ inputs [ 0 ] [ 'extension' ] ; // destination folder $ destinationPath = $ inputs [ 0 ] [ 'fileDirectory' ] ; // width and heigth that appear in frontend $ imageApperanceWidth = $ inputs [ 2 ] ; $ imageApperanceHeight = $ inputs [ 3 ] ; // original image $ url = strpos ( $ inputs [ 0 ] [ 'url' ] , '?' ) ; if ( $ url == false ) { $ url = $ inputs [ 0 ] [ 'url' ] ; } else { $ url = explode ( '?' , $ inputs [ 0 ] [ 'url' ] ) [ 0 ] ; } $ img = Image :: make ( $ url ) ; // $croppedWidth = the width of the cropped window $ croppedWidth = $ inputs [ 1 ] [ 'width' ] ; // $newWidth = the new width calculated for the original dimensions of the image $ newWidth = round ( $ img -> width ( ) / ( $ imageApperanceWidth / $ croppedWidth ) ) ; // $croppedHeight = the height of the cropped window $ croppedHeight = $ inputs [ 1 ] [ 'height' ] ; // $newHeight = the new height calculated for the original dimensions of the image $ newHeight = round ( $ img -> height ( ) / ( $ imageApperanceHeight / $ croppedHeight ) ) ; // X and Y of the crop window $ croppedX = $ request -> all ( ) [ 1 ] [ 'x' ] ; $ croppedY = $ request -> all ( ) [ 1 ] [ 'y' ] ; // new X and Y calculated for the original dimensions of the image $ newX = round ( ( $ img -> width ( ) / $ imageApperanceWidth ) * $ croppedX ) ; $ newY = round ( ( $ img -> height ( ) / $ imageApperanceHeight ) * $ croppedY ) ; // crop image and save the new image $ img -> crop ( $ newWidth , $ newHeight , $ newX , $ newY ) ; $ img -> save ( $ url , 100 ) ; $ media -> touch ( ) ; $ media -> deleteThumbs ( ) ; $ media -> createDefaultThumbs ( null , $ app ) ; return "OK" ; }
Crop the image with the specific dimensions.

@param  Request $request
@return string
Crop the image with the specific dimensions .