cdn/controllers/Crop.php
private function resize(
        $filePath,
        $phpCropMethod
    ) {
        //  Set some PHPThumb options
        $_options                = [];
        $_options['resizeUp']    = true;
        $_options['jpegQuality'] = 80;

        // --------------------------------------------------------------------------

        /**
         * Perform the resize
         * Turn errors off, if something bad happens we want to
         * output the serveBadSrc image and log the issue.
         */

        $oldErrorReporting = error_reporting();
        error_reporting(0);

        $width  = $this->width * $this->retinaMultiplier;
        $height = $this->height * $this->retinaMultiplier;
        $ext    = strtoupper(substr($this->extension, 1));

        if ($ext === 'JPEG') {
            $ext = 'jpg';
        }

        try {

            /**
             * Catch any output, don't want anything going to the browser unless
             * we're sure it's ok
             */

            ob_start();

            $PHPThumb = new \PHPThumb\GD($filePath, $_options);

            //  Prepare the parameters and call the method
            $aParams = [
                $width,
                $height,
                $this->cropQuadrant,
            ];

            call_user_func_array([$PHPThumb, $phpCropMethod], $aParams);

            //  Save cache version
            $PHPThumb->save($this->cdnCacheDir . $this->cdnCacheFile, $ext);

            //  Flush the buffer
            ob_end_clean();

        } catch (Exception $e) {

            //  Log the error
            Factory::service('Logger')->line('CDN: ' . $phpCropMethod . ': ' . $e->getMessage());

            //  Switch error reporting back how it was
            error_reporting($oldErrorReporting);

            //  Flush the buffer
            ob_end_clean();

            //  Bad SRC
            $this->serveBadSrc([
                'width'  => $width,
                'height' => $height,
            ]);
        }

        $this->serveFromCache($this->cdnCacheFile, false);

        //  Switch error reporting back how it was
        error_reporting($oldErrorReporting);
    }
private function resize(
        $filePath,
        $phpCropMethod
    ) {
        //  Set some PHPThumb options
        $_options                = [];
        $_options['resizeUp']    = true;
        $_options['jpegQuality'] = 80;

        // --------------------------------------------------------------------------

        /**
         * Perform the resize
         * Turn errors off, if something bad happens we want to
         * output the serveBadSrc image and log the issue.
         */

        $oldErrorReporting = error_reporting();
        error_reporting(0);

        $width  = $this->width * $this->retinaMultiplier;
        $height = $this->height * $this->retinaMultiplier;
        $ext    = strtoupper(substr($this->extension, 1));

        if ($ext === 'JPEG') {
            $ext = 'jpg';
        }

        try {

            /**
             * Catch any output, don't want anything going to the browser unless
             * we're sure it's ok
             */

            ob_start();

            $PHPThumb = new \PHPThumb\GD($filePath, $_options);

            //  Prepare the parameters and call the method
            $aParams = [
                $width,
                $height,
                $this->cropQuadrant,
            ];

            call_user_func_array([$PHPThumb, $phpCropMethod], $aParams);

            //  Save cache version
            $PHPThumb->save($this->cdnCacheDir . $this->cdnCacheFile, $ext);

            //  Flush the buffer
            ob_end_clean();

        } catch (Exception $e) {

            //  Log the error
            Factory::service('Logger')->line('CDN: ' . $phpCropMethod . ': ' . $e->getMessage());

            //  Switch error reporting back how it was
            error_reporting($oldErrorReporting);

            //  Flush the buffer
            ob_end_clean();

            //  Bad SRC
            $this->serveBadSrc([
                'width'  => $width,
                'height' => $height,
            ]);
        }

        $this->serveFromCache($this->cdnCacheFile, false);

        //  Switch error reporting back how it was
        error_reporting($oldErrorReporting);
    }
private function resize ( $ filePath , $ phpCropMethod ) { //  Set some PHPThumb options $ _options = [ ] ; $ _options [ 'resizeUp' ] = true ; $ _options [ 'jpegQuality' ] = 80 ; // -------------------------------------------------------------------------- /**
         * Perform the resize
         * Turn errors off, if something bad happens we want to
         * output the serveBadSrc image and log the issue.
         */ $ oldErrorReporting = error_reporting ( ) ; error_reporting ( 0 ) ; $ width = $ this -> width * $ this -> retinaMultiplier ; $ height = $ this -> height * $ this -> retinaMultiplier ; $ ext = strtoupper ( substr ( $ this -> extension , 1 ) ) ; if ( $ ext === 'JPEG' ) { $ ext = 'jpg' ; } try { /**
             * Catch any output, don't want anything going to the browser unless
             * we're sure it's ok
             */ ob_start ( ) ; $ PHPThumb = new \ PHPThumb \ GD ( $ filePath , $ _options ) ; //  Prepare the parameters and call the method $ aParams = [ $ width , $ height , $ this -> cropQuadrant , ] ; call_user_func_array ( [ $ PHPThumb , $ phpCropMethod ] , $ aParams ) ; //  Save cache version $ PHPThumb -> save ( $ this -> cdnCacheDir . $ this -> cdnCacheFile , $ ext ) ; //  Flush the buffer ob_end_clean ( ) ; } catch ( Exception $ e ) { //  Log the error Factory :: service ( 'Logger' ) -> line ( 'CDN: ' . $ phpCropMethod . ': ' . $ e -> getMessage ( ) ) ; //  Switch error reporting back how it was error_reporting ( $ oldErrorReporting ) ; //  Flush the buffer ob_end_clean ( ) ; //  Bad SRC $ this -> serveBadSrc ( [ 'width' => $ width , 'height' => $ height , ] ) ; } $ this -> serveFromCache ( $ this -> cdnCacheFile , false ) ; //  Switch error reporting back how it was error_reporting ( $ oldErrorReporting ) ; }
Resize a static image

@param  string $filePath      The file to resize
@param  string $phpCropMethod The PHPThumb method to use for resizing

@return void
Resize a static image