protected function getCropEditImageUrlAndSize($path, $cropSessionKey, $params = null)
    {
        $sessionDirectoryPath = $this->getCropSessionDirPath($cropSessionKey);
        $fullSessionDirectoryPath = temp_path($sessionDirectoryPath);
        $sessionDirectoryCreated = false;

        if (!File::isDirectory($fullSessionDirectoryPath)) {
            File::makeDirectory($fullSessionDirectoryPath, 0777, true, true);
            $sessionDirectoryCreated = true;
        }

        $tempFilePath = null;

        try {
            $extension = pathinfo($path, PATHINFO_EXTENSION);
            $library = MediaLibrary::instance();
            $originalThumbFileName = 'original.'.$extension;

            /*
             * If the target dimensions are not provided, save the original image to the
             * crop session directory and return its URL.
             */
            if (!$params) {
                $tempFilePath = $fullSessionDirectoryPath.'/'.$originalThumbFileName;

                if (!@File::put($tempFilePath, $library->get($path))) {
                    throw new SystemException('Error saving remote file to a temporary location.');
                }

                $url = $this->getThumbnailImageUrl($sessionDirectoryPath.'/'.$originalThumbFileName);
                $dimensions = getimagesize($tempFilePath);

                return [
                    'url' => $url,
                    'dimensions' => $dimensions
                ];
            }
            /*
             * If the target dimensions are provided, resize the original image and
             * return its URL and dimensions.
             */

            $originalFilePath = $fullSessionDirectoryPath.'/'.$originalThumbFileName;
            if (!File::isFile($originalFilePath)) {
                throw new SystemException('The original image is not found in the cropping session directory.');
            }

            $resizedThumbFileName = 'resized-'.$params['width'].'-'.$params['height'].'.'.$extension;
            $tempFilePath = $fullSessionDirectoryPath.'/'.$resizedThumbFileName;

            Resizer::open($originalFilePath)
                ->resize($params['width'], $params['height'], [
                    'mode' => 'exact'
                ])
                ->save($tempFilePath)
            ;

            $url = $this->getThumbnailImageUrl($sessionDirectoryPath.'/'.$resizedThumbFileName);
            $dimensions = getimagesize($tempFilePath);

            return [
                'url' => $url,
                'dimensions' => $dimensions
            ];
        }
        catch (Exception $ex) {
            if ($sessionDirectoryCreated) {
                @File::deleteDirectory($fullSessionDirectoryPath);
            }

            if ($tempFilePath) {
                File::delete($tempFilePath);
            }

            throw $ex;
        }
    }
protected function getCropEditImageUrlAndSize($path, $cropSessionKey, $params = null)
    {
        $sessionDirectoryPath = $this->getCropSessionDirPath($cropSessionKey);
        $fullSessionDirectoryPath = temp_path($sessionDirectoryPath);
        $sessionDirectoryCreated = false;

        if (!File::isDirectory($fullSessionDirectoryPath)) {
            File::makeDirectory($fullSessionDirectoryPath, 0777, true, true);
            $sessionDirectoryCreated = true;
        }

        $tempFilePath = null;

        try {
            $extension = pathinfo($path, PATHINFO_EXTENSION);
            $library = MediaLibrary::instance();
            $originalThumbFileName = 'original.'.$extension;

            /*
             * If the target dimensions are not provided, save the original image to the
             * crop session directory and return its URL.
             */
            if (!$params) {
                $tempFilePath = $fullSessionDirectoryPath.'/'.$originalThumbFileName;

                if (!@File::put($tempFilePath, $library->get($path))) {
                    throw new SystemException('Error saving remote file to a temporary location.');
                }

                $url = $this->getThumbnailImageUrl($sessionDirectoryPath.'/'.$originalThumbFileName);
                $dimensions = getimagesize($tempFilePath);

                return [
                    'url' => $url,
                    'dimensions' => $dimensions
                ];
            }
            /*
             * If the target dimensions are provided, resize the original image and
             * return its URL and dimensions.
             */

            $originalFilePath = $fullSessionDirectoryPath.'/'.$originalThumbFileName;
            if (!File::isFile($originalFilePath)) {
                throw new SystemException('The original image is not found in the cropping session directory.');
            }

            $resizedThumbFileName = 'resized-'.$params['width'].'-'.$params['height'].'.'.$extension;
            $tempFilePath = $fullSessionDirectoryPath.'/'.$resizedThumbFileName;

            Resizer::open($originalFilePath)
                ->resize($params['width'], $params['height'], [
                    'mode' => 'exact'
                ])
                ->save($tempFilePath)
            ;

            $url = $this->getThumbnailImageUrl($sessionDirectoryPath.'/'.$resizedThumbFileName);
            $dimensions = getimagesize($tempFilePath);

            return [
                'url' => $url,
                'dimensions' => $dimensions
            ];
        }
        catch (Exception $ex) {
            if ($sessionDirectoryCreated) {
                @File::deleteDirectory($fullSessionDirectoryPath);
            }

            if ($tempFilePath) {
                File::delete($tempFilePath);
            }

            throw $ex;
        }
    }
protected function getCropEditImageUrlAndSize ( $ path , $ cropSessionKey , $ params = null ) { $ sessionDirectoryPath = $ this -> getCropSessionDirPath ( $ cropSessionKey ) ; $ fullSessionDirectoryPath = temp_path ( $ sessionDirectoryPath ) ; $ sessionDirectoryCreated = false ; if ( ! File :: isDirectory ( $ fullSessionDirectoryPath ) ) { File :: makeDirectory ( $ fullSessionDirectoryPath , 0777 , true , true ) ; $ sessionDirectoryCreated = true ; } $ tempFilePath = null ; try { $ extension = pathinfo ( $ path , PATHINFO_EXTENSION ) ; $ library = MediaLibrary :: instance ( ) ; $ originalThumbFileName = 'original.' . $ extension ; /*
             * If the target dimensions are not provided, save the original image to the
             * crop session directory and return its URL.
             */ if ( ! $ params ) { $ tempFilePath = $ fullSessionDirectoryPath . '/' . $ originalThumbFileName ; if ( ! @ File :: put ( $ tempFilePath , $ library -> get ( $ path ) ) ) { throw new SystemException ( 'Error saving remote file to a temporary location.' ) ; } $ url = $ this -> getThumbnailImageUrl ( $ sessionDirectoryPath . '/' . $ originalThumbFileName ) ; $ dimensions = getimagesize ( $ tempFilePath ) ; return [ 'url' => $ url , 'dimensions' => $ dimensions ] ; } /*
             * If the target dimensions are provided, resize the original image and
             * return its URL and dimensions.
             */ $ originalFilePath = $ fullSessionDirectoryPath . '/' . $ originalThumbFileName ; if ( ! File :: isFile ( $ originalFilePath ) ) { throw new SystemException ( 'The original image is not found in the cropping session directory.' ) ; } $ resizedThumbFileName = 'resized-' . $ params [ 'width' ] . '-' . $ params [ 'height' ] . '.' . $ extension ; $ tempFilePath = $ fullSessionDirectoryPath . '/' . $ resizedThumbFileName ; Resizer :: open ( $ originalFilePath ) -> resize ( $ params [ 'width' ] , $ params [ 'height' ] , [ 'mode' => 'exact' ] ) -> save ( $ tempFilePath ) ; $ url = $ this -> getThumbnailImageUrl ( $ sessionDirectoryPath . '/' . $ resizedThumbFileName ) ; $ dimensions = getimagesize ( $ tempFilePath ) ; return [ 'url' => $ url , 'dimensions' => $ dimensions ] ; } catch ( Exception $ ex ) { if ( $ sessionDirectoryCreated ) { @ File :: deleteDirectory ( $ fullSessionDirectoryPath ) ; } if ( $ tempFilePath ) { File :: delete ( $ tempFilePath ) ; } throw $ ex ; } }
Prepares an image for cropping and returns payload containing a URL
@param string $path
@param string $cropSessionKey
@param array $params
@return array
Prepares an image for cropping and returns payload containing a URL