Generate and return image response.

@param  string  $path
@param  array   $params
@param  bool    $skipValidation
@return mixed
559910
public function imageResponse($path, array $params = [], $skipValidation = false)
    {
        $this->validateRequest($path, $params, $skipValidation);

        return $this->getLeagueGlideServer()->getImageResponse($path, $params);
    }
1267048
public static function cleanPath($path, $params = ['checkDir' => false, 'checkFile' => false])
    {

        $params = Arr::mergeWithDefaultParams($params);

        if ($params['checkDir']) {
            if (!is_dir($path)) {
                Throw new Exception('Path is not a dir');
            }
        }

        if ($params['checkFile']) {
            if (!is_file($path)) {
                Throw new Exception('Path is not a file');
            }
        }

        return str_replace(array('//'), array('/'), $path);
    }
804675
public function xpath($path, $skipNsSanitizing = false)
    {
        try {
            if (!$skipNsSanitizing) {
                // XPath has some trouble with unqualified node names when
                // default xmlns is set.
                // try to find out if namespaces should be registered and
                // if the xpath must be sanitized (i.E. default xmlns)
                foreach ($this->getNamespaces() as $prefix => $ns) {
                    if ($prefix == '') {
                        $prefix = 'ns';
                        $path = $this->injectNsToXpathQuery($path, $prefix);
                    }

                    $this->registerXPathNamespace($prefix, $ns);
                }
            }

            $result = @parent::xpath($path);
            if ($result === false) {
                $last = error_get_last();
                $error = (isset($last['message']))? "\n" . $last['message'] : '';
                $code  = (isset($last['type']))? $last['type'] : 0;
                $xmlErrors = '';

                foreach (libxml_get_errors() as $err) {
                    $xmlErrors .= "\n" . $err->message;
                }

                $message = sprintf(
                    "Failed to process xpath \"%s\"%s%s",
                    $path, $error, $xmlErrors
                );

                throw new exception\RuntimeException($message);
            }
        } catch (exception\RuntimeException $e) {
            // Don't convert to runtime exception again
            throw $e;
        } catch (\Exception $e) {
            throw new exception\RuntimeException($e);
        }

        if (!is_array($result)) {
            $result = array();
        }

        $result = new ArrayIterator($result);
        return $result;
    }
169702
public function put($path, $params)
    {
        $response = $this->http_client->request('PUT', $path, $params);
        $this->handleErrors($response);
        return $response;
    }
370540
public function get($path, $params = array())
    {
        if (is_array($params) && array_key_exists("query", $params)) {
            $params["query"] = $this->castBooleanValuesToStrings($params["query"]);
        }

        $response = $this->http_client->request('GET', $path, $params);
        $this->handleErrors($response);
        return $response;
    }
378051
public function render($path, $params, $mustClean = false)
    {
        if (!isset($params['content'])) {
            $params['content'] = $this->_view->getContent();
        }
        foreach ($params as $key => $value) {
            $this->smarty->assign($key, $value);
        }
        $content = $this->smarty->fetch($path);
        if ($mustClean) {
            $this->_view->setContent($content);
        } else {
            echo $content;
        }
    }
1092679
public function getImageAsBase64($path, array $params)
    {
        $path = $this->makeImage($path, $params);

        $source = $this->cache->read($path);

        if ($source === false) {
            throw new FilesystemException(
                'Could not read the image `'.$path.'`.'
            );
        }

        return 'data:'.$this->cache->getMimetype($path).';base64,'.base64_encode($source);
    }
263996
public function insert_many($data, $skip_validation = FALSE)
    {
        $ids = array();

        foreach ($data as $key => $row)
        {
            $ids[] = $this->insert($row, $skip_validation, ($key == count($data) - 1));
        }

        return $ids;
    }
1178958
public function post($path, $params)
    {
        $idempotencyKey = uniqid("", true);
        $paramsWithHeaders = array("headers" => array("Idempotency-Key" => $idempotencyKey));
        $params = array_replace_recursive($paramsWithHeaders, $params);

        $response = $this->http_client->request('POST', $path, $params);

        $this->handleErrors($response);
        return $response;
    }
1291221
public function outputImage($params = array())
    {
        $param_defaults = array(
            'width' => 120,
            'height' => 40,
            // 'length' => 6
        );
        $params = \array_merge($param_defaults, $params);
        $code = $this->generateCode($this->length);
        $font_size = $params['height'] * $this->font_scale;
        $image = @\imagecreate($params['width'], $params['height']) or die('Cannot initialize new GD image stream');
        // set the colors
        $color_bkg = \imagecolorallocate($image, 0, 0, 0);
        // $color_text = imagecolorallocate($image, 20, 40, 100);
        $color_text = \imagecolorallocate($image, 200, 200, 200);
        $color_noise = \imagecolorallocate($image, 150, 150, 150);
        // generate random dots in background
        for ($i=0; $i<($params['width']*$params['height'])/$this->dot_divisor; $i++) {
            \imagefilledellipse($image, \mt_rand(0, $params['width']), \mt_rand(0, $params['height']), 1, 1, $color_noise);
        }
        // generate random lines in background
        for ($i=0; $i<($params['width']*$params['height'])/$this->line_divisor; $i++) {
            \imageline($image, \mt_rand(0, $params['width']), \mt_rand(0, $params['height']), \mt_rand(0, $params['width']), \mt_rand(0, $params['height']), $color_noise);
        }
        // create textbox and add text
        $textbox = \imagettfbbox($font_size, 0, $this->font, $code); // or die('Error in imagettfbbox function');
        $x = ($params['width'] - $textbox[4])/2;
        $y = ($params['height'] - $textbox[5])/2;
        \imagettftext($image, $font_size, 0, $x, $y, $color_text, $this->font, $code); // or die('Error in imagettftext function');
        // output captcha image to browser
        \header('Last-Modified: '.\date('r'));
        \header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
        \header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
        \header('Content-Type: image/jpeg');
        \header('Pragma: no-cache');
        \imagejpeg($image);
        \imagedestroy($image);
    }
693009
private function get($path, array $params = [])
    {
        $request = $this->createHttpGetRequest($this->buildUrl($path), $params);

        $response = $this->httpClient->sendRequest($request);

        return $this->parseResponse($response, $request);
    }
1211069
protected function requestToken($path = '', $body = array())
    {

        $headers = array(
            'Authorization' => 'Basic ' . $this->apiKey(),
            'Content-Type'  => 'application/x-www-form-urlencoded'
        );

        $request = $this->_client->createRequest('POST', $path, null, $body, $headers);

        return $this->sendRequest($request, array('skipAuthCheck' => true));

    }
174910
protected function doGet($path, array $params = null, array $data = null)
    {
        return $this->getResult('GET', $path, $params, $data);
    }
103141
public function validateDynamicPattern($path, &$debugInformation)
    {
        if (empty($this->pattern)) {
            return false;
        }

        $value = $this->pattern->testPattern($path, $this->parameters, $debugInformation);

        $this->validatedData = $this->pattern->getValidatedData();

        return $value;
    }
451258
public function getUrl(string $path = null, array $params = []): Uri
    {
        $pathParams = $this->getPathParams($params);
        # get the path parameters
        $queryParams = $this->getQueryParams($params);
        # get the query parameters
        $path .= !empty($pathParams) ? '/' . $pathParams : '';
        # append the rest of the path
        if (!empty($path) && $path[0] !== '/') {
            $path = '/' . $path;
        }
        return $this->uri->withPath($path)->withQuery($queryParams);
    }
323519
public function validateRequest($path, array $params)
    {
        if (!isset($params['s'])) {
            throw new SignatureException('Signature is missing.');
        }

        if ($params['s'] !== $this->generateSignature($path, $params)) {
            throw new SignatureException('Signature is not valid.');
        }
    }
196536
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;
        }
    }