squeezr/lib/Tollwerk/Squeezr/Image.php
/**
     * Send the cached and possibly downsampled image
     *
     * @return void
     */
Send the cached and possibly downsampled image
@return void
Send the cached and possibly downsampled image @return void
public function send()
    {
        $extension = null;
        $returnImage = $this->_absoluteImagePath;
        if (!extension_loaded('gd') && (!function_exists('dl') || !dl('gd.so'))) {
            $this->_addErrorHeader(\Tollwerk\Squeezr\Exception::GD_UNAVAILABLE_MSG,
                \Tollwerk\Squeezr\Exception::GD_UNAVAILABLE);
        } elseif ((!@is_dir($this->_absoluteCacheImageDir) && !@mkdir($this->_absoluteCacheImageDir, 0777,
                    true)) || !@is_writable($this->_absoluteCacheImageDir)
        ) {
            $this->_addErrorHeader(\Tollwerk\Squeezr\Exception::INVALID_TARGET_CACHE_DIRECTORY_MSG,
                \Tollwerk\Squeezr\Exception::INVALID_TARGET_CACHE_DIRECTORY);
        } elseif (empty($_COOKIE['squeezr_screen']) || !preg_match("%^(\d+)x(\d+)\@(\d+(?:\.\d+)?)$%",
                $_COOKIE['squeezr_screen'], $squeezr)
        ) {
            $this->_addErrorHeader(\Tollwerk\Squeezr\Exception::MISSING_METRICS_COOKIE_MSG,
                \Tollwerk\Squeezr\Exception::MISSING_METRICS_COOKIE);
        } else {
            $errors = array();
            $returnImage = $this->squeeze($this->_absoluteImagePath, $this->_absoluteCacheImagePath, SQUEEZR_BREAKPOINT,
                $errors);
            foreach ($errors as $errNo => $errMsg) {
                $this->_addErrorHeader(sprintf($errMsg, $this->_relativeImagePath), $errNo);
            }
        }
        $extension = ($extension === null) ? pathinfo($returnImage, PATHINFO_EXTENSION) : $extension;
        $this->_sendFile($returnImage, 'image/'.((strtolower($extension) == 'jpg') ? 'jpeg' : strtolower($extension)),
            true);
        exit;
    }
public function send ( ) { $ extension = null ; $ returnImage = $ this -> _absoluteImagePath ; if ( ! extension_loaded ( 'gd' ) && ( ! function_exists ( 'dl' ) || ! dl ( 'gd.so' ) ) ) { $ this -> _addErrorHeader ( \ Tollwerk \ Squeezr \ Exception :: GD_UNAVAILABLE_MSG , \ Tollwerk \ Squeezr \ Exception :: GD_UNAVAILABLE ) ; } elseif ( ( ! @ is_dir ( $ this -> _absoluteCacheImageDir ) && ! @ mkdir ( $ this -> _absoluteCacheImageDir , 0777 , true ) ) || ! @ is_writable ( $ this -> _absoluteCacheImageDir ) ) { $ this -> _addErrorHeader ( \ Tollwerk \ Squeezr \ Exception :: INVALID_TARGET_CACHE_DIRECTORY_MSG , \ Tollwerk \ Squeezr \ Exception :: INVALID_TARGET_CACHE_DIRECTORY ) ; } elseif ( empty ( $ _COOKIE [ 'squeezr_screen' ] ) || ! preg_match ( " %^(\d+)x(\d+)\@(\d+(?:\.\d+)?)$% " , $ _COOKIE [ 'squeezr_screen' ] , $ squeezr ) ) { $ this -> _addErrorHeader ( \ Tollwerk \ Squeezr \ Exception :: MISSING_METRICS_COOKIE_MSG , \ Tollwerk \ Squeezr \ Exception :: MISSING_METRICS_COOKIE ) ; } else { $ errors = array ( ) ; $ returnImage = $ this -> squeeze ( $ this -> _absoluteImagePath , $ this -> _absoluteCacheImagePath , SQUEEZR_BREAKPOINT , $ errors ) ; foreach ( $ errors as $ errNo => $ errMsg ) { $ this -> _addErrorHeader ( sprintf ( $ errMsg , $ this -> _relativeImagePath ) , $ errNo ) ; } } $ extension = ( $ extension === null ) ? pathinfo ( $ returnImage , PATHINFO_EXTENSION ) : $ extension ; $ this -> _sendFile ( $ returnImage , 'image/' . ( ( strtolower ( $ extension ) == 'jpg' ) ? 'jpeg' : strtolower ( $ extension ) ) , true ) ; exit ; }
Send the cached and possibly downsampled image
 @return void
Send the cached and possibly downsampled image @return void
// Set some defaults // If the GD extension is not available // If the cache directory doesn't exist or is not writable: Error // If the squeezr screen cookie is not available or invalid // Copy & resample original image // Send the image along with it's HTTP headers