src/Image/Server.php
private function serveImage(): void
    {
        if (empty($this->uriParams)) {
            \header($this->serverProtocol.' 500 Internal Server Error', true, 500);
            die();
        }

        $requestFilePath = \sprintf(
            '%s%s%s.%s',
            $this->uriParams['path'],
            $this->uriParams['file'],
            $this->getResizeParamsString(),
            $this->uriParams['extension']
        );
        $originalFilePath = \sprintf(
            '%s%s.%s',
            $this->uriParams['path'],
            $this->uriParams['file'],
            $this->uriParams['extension']
        );

        if (File::exists($requestFilePath)) {
            $this->outputImage($requestFilePath);
        }
        if (File::exists($originalFilePath)) {
            if ($this->baseClass->Image->Server->checkRefererBeforeResize === true) {
                if (!\preg_match('|^'.$this->baseClass->getServerName().'|i', $this->baseClass->getReferer())) {
                    \header($this->serverProtocol.' 403 Forbidden', true, 403);
                    die();
                }
            }

            $options = $this->uriParams['resize-params'];
            $options['quality'] = $this->baseClass->Image->Resizer->defaultQuality;

            try {
                Resizer::resize($originalFilePath, $requestFilePath, $options);
            } catch (\Exception $e) {
                \header($this->serverProtocol.' 500 Internal Server Error', true, 500);
                die();
            }
            $this->outputImage($requestFilePath);
        }

        \header($this->serverProtocol.' 404 Not Found', true, 404);
        die();
    }
private function serveImage(): void
    {
        if (empty($this->uriParams)) {
            \header($this->serverProtocol.' 500 Internal Server Error', true, 500);
            die();
        }

        $requestFilePath = \sprintf(
            '%s%s%s.%s',
            $this->uriParams['path'],
            $this->uriParams['file'],
            $this->getResizeParamsString(),
            $this->uriParams['extension']
        );
        $originalFilePath = \sprintf(
            '%s%s.%s',
            $this->uriParams['path'],
            $this->uriParams['file'],
            $this->uriParams['extension']
        );

        if (File::exists($requestFilePath)) {
            $this->outputImage($requestFilePath);
        }
        if (File::exists($originalFilePath)) {
            if ($this->baseClass->Image->Server->checkRefererBeforeResize === true) {
                if (!\preg_match('|^'.$this->baseClass->getServerName().'|i', $this->baseClass->getReferer())) {
                    \header($this->serverProtocol.' 403 Forbidden', true, 403);
                    die();
                }
            }

            $options = $this->uriParams['resize-params'];
            $options['quality'] = $this->baseClass->Image->Resizer->defaultQuality;

            try {
                Resizer::resize($originalFilePath, $requestFilePath, $options);
            } catch (\Exception $e) {
                \header($this->serverProtocol.' 500 Internal Server Error', true, 500);
                die();
            }
            $this->outputImage($requestFilePath);
        }

        \header($this->serverProtocol.' 404 Not Found', true, 404);
        die();
    }
private function serveImage ( ) : void { if ( empty ( $ this -> uriParams ) ) { \ header ( $ this -> serverProtocol . ' 500 Internal Server Error' , true , 500 ) ; die ( ) ; } $ requestFilePath = \ sprintf ( '%s%s%s.%s' , $ this -> uriParams [ 'path' ] , $ this -> uriParams [ 'file' ] , $ this -> getResizeParamsString ( ) , $ this -> uriParams [ 'extension' ] ) ; $ originalFilePath = \ sprintf ( '%s%s.%s' , $ this -> uriParams [ 'path' ] , $ this -> uriParams [ 'file' ] , $ this -> uriParams [ 'extension' ] ) ; if ( File :: exists ( $ requestFilePath ) ) { $ this -> outputImage ( $ requestFilePath ) ; } if ( File :: exists ( $ originalFilePath ) ) { if ( $ this -> baseClass -> Image -> Server -> checkRefererBeforeResize === true ) { if ( ! \ preg_match ( '|^' . $ this -> baseClass -> getServerName ( ) . '|i' , $ this -> baseClass -> getReferer ( ) ) ) { \ header ( $ this -> serverProtocol . ' 403 Forbidden' , true , 403 ) ; die ( ) ; } } $ options = $ this -> uriParams [ 'resize-params' ] ; $ options [ 'quality' ] = $ this -> baseClass -> Image -> Resizer -> defaultQuality ; try { Resizer :: resize ( $ originalFilePath , $ requestFilePath , $ options ) ; } catch ( \ Exception $ e ) { \ header ( $ this -> serverProtocol . ' 500 Internal Server Error' , true , 500 ) ; die ( ) ; } $ this -> outputImage ( $ requestFilePath ) ; } \ header ( $ this -> serverProtocol . ' 404 Not Found' , true , 404 ) ; die ( ) ; }
Serves image.
If no REQUEST_URI found sends 500 Internal Server Error header. If no image is found sends 404 Not found header.
If image needs resizing or grayscale converting - it applies transformations and returns it,
otherwise returns original one.

@return void
Serves image . If no REQUEST_URI found sends 500 Internal Server Error header . If no image is found sends 404 Not found header . If image needs resizing or grayscale converting - it applies transformations and returns it otherwise returns original one .