One Hat Cyber Team
Your IP:
216.73.216.161
Server IP:
198.54.114.155
Server:
Linux server71.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
Server Software:
LiteSpeed
PHP Version:
5.6.40
Create File
|
Create Folder
Execute
Dir :
~
/
proc
/
self
/
root
/
home
/
fluxyjvi
/
www
/
assets
/
images
/
Edit File:
glide.tar
src/Signatures/Signature.php 0000644 00000003451 15107517131 0012135 0 ustar 00 <?php namespace League\Glide\Signatures; class Signature implements SignatureInterface { /** * Secret key used to generate signature. * * @var string */ protected $signKey; /** * Create Signature instance. * * @param string $signKey Secret key used to generate signature. */ public function __construct($signKey) { $this->signKey = $signKey; } /** * Add an HTTP signature to manipulation parameters. * * @param string $path The resource path. * @param array $params The manipulation parameters. * * @return array The updated manipulation parameters. */ public function addSignature($path, array $params) { return array_merge($params, ['s' => $this->generateSignature($path, $params)]); } /** * Validate a request signature. * * @param string $path The resource path. * @param array $params The manipulation params. * * @throws SignatureException * * @return void */ 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.'); } } /** * Generate an HTTP signature. * * @param string $path The resource path. * @param array $params The manipulation parameters. * * @return string The generated HTTP signature. */ public function generateSignature($path, array $params) { unset($params['s']); ksort($params); return md5($this->signKey.':'.ltrim($path, '/').'?'.http_build_query($params)); } } src/Signatures/SignatureException.php 0000644 00000000152 15107517131 0014007 0 ustar 00 <?php namespace League\Glide\Signatures; use Exception; class SignatureException extends Exception { } src/Signatures/SignatureFactory.php 0000644 00000000544 15107517131 0013465 0 ustar 00 <?php namespace League\Glide\Signatures; class SignatureFactory { /** * Create HttpSignature instance. * * @param string $signKey Secret key used to generate signature. * * @return Signature The HttpSignature instance. */ public static function create($signKey) { return new Signature($signKey); } } src/Signatures/SignatureInterface.php 0000644 00000001172 15107517131 0013754 0 ustar 00 <?php namespace League\Glide\Signatures; interface SignatureInterface { /** * Add an HTTP signature to manipulation params. * * @param string $path The resource path. * @param array $params The manipulation params. * * @return array The updated manipulation params. */ public function addSignature($path, array $params); /** * Validate a request signature. * * @param string $path The resource path. * @param array $params The manipulation params. * * @throws SignatureException */ public function validateRequest($path, array $params); } src/Manipulators/Brightness.php 0000644 00000001634 15107517131 0012637 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string|null $bri */ class Brightness extends BaseManipulator { /** * Perform brightness image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { $brightness = $this->getBrightness(); if (null !== $brightness) { $image->brightness($brightness); } return $image; } /** * Resolve brightness amount. * * @return int|null The resolved brightness amount. */ public function getBrightness() { if (null === $this->bri || !preg_match('/^-*[0-9]+$/', $this->bri)) { return; } if ($this->bri < -100 or $this->bri > 100) { return; } return (int) $this->bri; } } src/Manipulators/Orientation.php 0000644 00000001523 15107517131 0013017 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string $or */ class Orientation extends BaseManipulator { /** * Perform orientation image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { $orientation = $this->getOrientation(); if ('auto' === $orientation) { return $image->orientate(); } return $image->rotate((float) $orientation); } /** * Resolve orientation. * * @return string The resolved orientation. */ public function getOrientation() { if (in_array($this->or, ['auto', '0', '90', '180', '270'], true)) { return $this->or; } return 'auto'; } } src/Manipulators/Flip.php 0000644 00000001456 15107517132 0011424 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string $flip */ class Flip extends BaseManipulator { /** * Perform flip image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { if ($flip = $this->getFlip()) { if ('both' === $flip) { return $image->flip('h')->flip('v'); } return $image->flip($flip); } return $image; } /** * Resolve flip. * * @return string|null The resolved flip. */ public function getFlip() { if (in_array($this->flip, ['h', 'v', 'both'], true)) { return $this->flip; } } } src/Manipulators/Gamma.php 0000644 00000001553 15107517132 0011552 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string|null $gam */ class Gamma extends BaseManipulator { /** * Perform gamma image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { $gamma = $this->getGamma(); if ($gamma) { $image->gamma($gamma); } return $image; } /** * Resolve gamma amount. * * @return float|null The resolved gamma amount. */ public function getGamma() { if (null === $this->gam || !preg_match('/^[0-9]\.*[0-9]*$/', $this->gam)) { return; } if ($this->gam < 0.1 or $this->gam > 9.99) { return; } return (float) $this->gam; } } src/Manipulators/Background.php 0000644 00000001425 15107517132 0012605 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; use League\Glide\Manipulators\Helpers\Color; /** * @property string $bg */ class Background extends BaseManipulator { /** * Perform background image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { if (is_null($this->bg)) { return $image; } $color = (new Color($this->bg))->formatted(); if ($color) { $new = $image->getDriver()->newImage($image->width(), $image->height(), $color); $new->mime = $image->mime; $image = $new->insert($image, 'top-left', 0, 0); } return $image; } } src/Manipulators/Filter.php 0000644 00000002406 15107517132 0011753 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string $filt */ class Filter extends BaseManipulator { /** * Perform filter image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { if ('greyscale' === $this->filt) { return $this->runGreyscaleFilter($image); } if ('sepia' === $this->filt) { return $this->runSepiaFilter($image); } return $image; } /** * Perform greyscale manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function runGreyscaleFilter(Image $image) { return $image->greyscale(); } /** * Perform sepia manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function runSepiaFilter(Image $image) { $image->greyscale(); $image->brightness(-10); $image->contrast(10); $image->colorize(38, 27, 12); $image->brightness(-10); $image->contrast(10); return $image; } } src/Manipulators/Watermark.php 0000644 00000014611 15107517132 0012464 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; use League\Flysystem\FilesystemException as FilesystemV2Exception; use League\Flysystem\FilesystemOperator; use League\Glide\Filesystem\FilesystemException; use League\Glide\Manipulators\Helpers\Dimension; /** * @property string $dpr * @property string $mark * @property string $markfit * @property string $markh * @property string $markpad * @property string $markpos * @property string $markw * @property string $markx * @property string $marky * @property string $markalpha */ class Watermark extends BaseManipulator { /** * The watermarks file system. * * @var FilesystemOperator|null */ protected $watermarks; /** * The watermarks path prefix. * * @var string */ protected $watermarksPathPrefix; /** * Create Watermark instance. * * @param FilesystemOperator $watermarks The watermarks file system. */ public function __construct(FilesystemOperator $watermarks = null, $watermarksPathPrefix = '') { $this->setWatermarks($watermarks); $this->setWatermarksPathPrefix($watermarksPathPrefix); } /** * Set the watermarks file system. * * @param FilesystemOperator $watermarks The watermarks file system. * * @return void */ public function setWatermarks(FilesystemOperator $watermarks = null) { $this->watermarks = $watermarks; } /** * Get the watermarks file system. * * @return FilesystemOperator|null The watermarks file system. */ public function getWatermarks() { return $this->watermarks; } /** * Set the watermarks path prefix. * * @param string $watermarksPathPrefix The watermarks path prefix. * * @return void */ public function setWatermarksPathPrefix($watermarksPathPrefix = '') { $this->watermarksPathPrefix = trim($watermarksPathPrefix, '/'); } /** * Get the watermarks path prefix. * * @return string The watermarks path prefix. */ public function getWatermarksPathPrefix() { return $this->watermarksPathPrefix; } /** * Perform watermark image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { if ($watermark = $this->getImage($image)) { $markw = $this->getDimension($image, 'markw'); $markh = $this->getDimension($image, 'markh'); $markx = $this->getDimension($image, 'markx'); $marky = $this->getDimension($image, 'marky'); $markpad = $this->getDimension($image, 'markpad'); $markfit = $this->getFit(); $markpos = $this->getPosition(); $markalpha = $this->getAlpha(); if ($markpad) { $markx = $marky = $markpad; } $size = new Size(); $size->setParams([ 'w' => $markw, 'h' => $markh, 'fit' => $markfit, ]); $watermark = $size->run($watermark); if ($markalpha < 100) { $watermark->opacity($markalpha); } $image->insert($watermark, $markpos, intval($markx), intval($marky)); } return $image; } /** * Get the watermark image. * * @param Image $image The source image. * * @return Image|null The watermark image. */ public function getImage(Image $image) { if (is_null($this->watermarks)) { return; } if (!is_string($this->mark)) { return; } if ('' === $this->mark) { return; } $path = $this->mark; if ($this->watermarksPathPrefix) { $path = $this->watermarksPathPrefix.'/'.$path; } try { if ($this->watermarks->fileExists($path)) { $source = $this->watermarks->read($path); return $image->getDriver()->init($source); } } catch (FilesystemV2Exception $exception) { throw new FilesystemException('Could not read the image `'.$path.'`.'); } } /** * Get a dimension. * * @param Image $image The source image. * @param string $field The requested field. * * @return float|null The dimension. */ public function getDimension(Image $image, $field) { if ($this->{$field}) { return (new Dimension($image, $this->getDpr()))->get($this->{$field}); } } /** * Resolve the device pixel ratio. * * @return float The device pixel ratio. */ public function getDpr() { if (!is_numeric($this->dpr)) { return 1.0; } if ($this->dpr < 0 or $this->dpr > 8) { return 1.0; } return (float) $this->dpr; } /** * Get the fit. * * @return string|null The fit. */ public function getFit() { $fitMethods = [ 'contain', 'max', 'stretch', 'crop', 'crop-top-left', 'crop-top', 'crop-top-right', 'crop-left', 'crop-center', 'crop-right', 'crop-bottom-left', 'crop-bottom', 'crop-bottom-right', ]; if (in_array($this->markfit, $fitMethods, true)) { return $this->markfit; } } /** * Get the position. * * @return string The position. */ public function getPosition() { $positions = [ 'top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right', ]; if (in_array($this->markpos, $positions, true)) { return $this->markpos; } return 'bottom-right'; } /** * Get the alpha channel. * * @return int The alpha. */ public function getAlpha() { if (!is_numeric($this->markalpha)) { return 100; } if ($this->markalpha < 0 or $this->markalpha > 100) { return 100; } return (int) $this->markalpha; } } src/Manipulators/Helpers/Dimension.php 0000644 00000002245 15107517132 0014056 0 ustar 00 <?php namespace League\Glide\Manipulators\Helpers; use Intervention\Image\Image; class Dimension { /** * The source image. * * @var Image */ protected $image; /** * The device pixel ratio. * * @var float */ protected $dpr; /** * Create dimension helper instance. * * @param Image $image The source image. * @param float $dpr The device pixel ratio. */ public function __construct(Image $image, $dpr = 1) { $this->image = $image; $this->dpr = $dpr; } /** * Resolve the dimension. * * @param string $value The dimension value. * * @return float|null The resolved dimension. */ public function get($value) { if (is_numeric($value) and $value > 0) { return (float) $value * $this->dpr; } if (preg_match('/^(\d{1,2}(?!\d)|100)(w|h)$/', $value, $matches)) { if ('h' === $matches[2]) { return (float) $this->image->height() * ((float) $matches[1] / 100); } return (float) $this->image->width() * ((float) $matches[1] / 100); } } } src/Manipulators/Helpers/Color.php 0000644 00000020051 15107517132 0013202 0 ustar 00 <?php namespace League\Glide\Manipulators\Helpers; class Color { /** * 3 digit color code expression. */ const SHORT_RGB = '/^[0-9a-f]{3}$/i'; /** * 4 digit color code expression. */ const SHORT_ARGB = '/^[0-9]{1}[0-9a-f]{3}$/i'; /** * 6 digit color code expression. */ const LONG_RGB = '/^[0-9a-f]{6}$/i'; /** * 8 digit color code expression. */ const LONG_ARGB = '/^[0-9]{2}[0-9a-f]{6}$/i'; /** * The red value. * * @var int */ protected $red; /** * The green value. * * @var int */ protected $green; /** * The blue value. * * @var int */ protected $blue; /** * The alpha value. * * @var int|float */ protected $alpha; /** * Create color helper instance. * * @param string $value The color value. */ public function __construct($value) { do { if ($hex = $this->getHexFromColorName($value)) { $rgba = $this->parseHex($hex); $alpha = 1; break; } if (preg_match(self::SHORT_RGB, $value)) { $rgba = $this->parseHex($value.$value); $alpha = 1; break; } if (preg_match(self::SHORT_ARGB, $value)) { $rgba = $this->parseHex(substr($value, 1).substr($value, 1)); $alpha = (float) substr($value, 0, 1) / 10; break; } if (preg_match(self::LONG_RGB, $value)) { $rgba = $this->parseHex($value); $alpha = 1; break; } if (preg_match(self::LONG_ARGB, $value)) { $rgba = $this->parseHex(substr($value, 2)); $alpha = (float) substr($value, 0, 2) / 100; break; } $rgba = [255, 255, 255]; $alpha = 0; } while (false); $this->red = $rgba[0]; $this->green = $rgba[1]; $this->blue = $rgba[2]; $this->alpha = $alpha; } /** * Parse hex color to RGB values. * * @param string $hex The hex value. * * @return array The RGB values. */ public function parseHex($hex) { return array_map('hexdec', str_split($hex, 2)); } /** * Format color for consumption. * * @return string The formatted color. */ public function formatted() { return 'rgba('.$this->red.', '.$this->green.', '.$this->blue.', '.$this->alpha.')'; } /** * Get hex code by color name. * * @param string $name The color name. * * @return string|null The hex code. */ public function getHexFromColorName($name) { $colors = [ 'aliceblue' => 'F0F8FF', 'antiquewhite' => 'FAEBD7', 'aqua' => '00FFFF', 'aquamarine' => '7FFFD4', 'azure' => 'F0FFFF', 'beige' => 'F5F5DC', 'bisque' => 'FFE4C4', 'black' => '000000', 'blanchedalmond' => 'FFEBCD', 'blue' => '0000FF', 'blueviolet' => '8A2BE2', 'brown' => 'A52A2A', 'burlywood' => 'DEB887', 'cadetblue' => '5F9EA0', 'chartreuse' => '7FFF00', 'chocolate' => 'D2691E', 'coral' => 'FF7F50', 'cornflowerblue' => '6495ED', 'cornsilk' => 'FFF8DC', 'crimson' => 'DC143C', 'cyan' => '00FFFF', 'darkblue' => '00008B', 'darkcyan' => '008B8B', 'darkgoldenrod' => 'B8860B', 'darkgray' => 'A9A9A9', 'darkgreen' => '006400', 'darkkhaki' => 'BDB76B', 'darkmagenta' => '8B008B', 'darkolivegreen' => '556B2F', 'darkorange' => 'FF8C00', 'darkorchid' => '9932CC', 'darkred' => '8B0000', 'darksalmon' => 'E9967A', 'darkseagreen' => '8FBC8F', 'darkslateblue' => '483D8B', 'darkslategray' => '2F4F4F', 'darkturquoise' => '00CED1', 'darkviolet' => '9400D3', 'deeppink' => 'FF1493', 'deepskyblue' => '00BFFF', 'dimgray' => '696969', 'dodgerblue' => '1E90FF', 'firebrick' => 'B22222', 'floralwhite' => 'FFFAF0', 'forestgreen' => '228B22', 'fuchsia' => 'FF00FF', 'gainsboro' => 'DCDCDC', 'ghostwhite' => 'F8F8FF', 'gold' => 'FFD700', 'goldenrod' => 'DAA520', 'gray' => '808080', 'green' => '008000', 'greenyellow' => 'ADFF2F', 'honeydew' => 'F0FFF0', 'hotpink' => 'FF69B4', 'indianred' => 'CD5C5C', 'indigo' => '4B0082', 'ivory' => 'FFFFF0', 'khaki' => 'F0E68C', 'lavender' => 'E6E6FA', 'lavenderblush' => 'FFF0F5', 'lawngreen' => '7CFC00', 'lemonchiffon' => 'FFFACD', 'lightblue' => 'ADD8E6', 'lightcoral' => 'F08080', 'lightcyan' => 'E0FFFF', 'lightgoldenrodyellow' => 'FAFAD2', 'lightgray' => 'D3D3D3', 'lightgreen' => '90EE90', 'lightpink' => 'FFB6C1', 'lightsalmon' => 'FFA07A', 'lightseagreen' => '20B2AA', 'lightskyblue' => '87CEFA', 'lightslategray' => '778899', 'lightsteelblue' => 'B0C4DE', 'lightyellow' => 'FFFFE0', 'lime' => '00FF00', 'limegreen' => '32CD32', 'linen' => 'FAF0E6', 'magenta' => 'FF00FF', 'maroon' => '800000', 'mediumaquamarine' => '66CDAA', 'mediumblue' => '0000CD', 'mediumorchid' => 'BA55D3', 'mediumpurple' => '9370DB', 'mediumseagreen' => '3CB371', 'mediumslateblue' => '7B68EE', 'mediumspringgreen' => '00FA9A', 'mediumturquoise' => '48D1CC', 'mediumvioletred' => 'C71585', 'midnightblue' => '191970', 'mintcream' => 'F5FFFA', 'mistyrose' => 'FFE4E1', 'moccasin' => 'FFE4B5', 'navajowhite' => 'FFDEAD', 'navy' => '000080', 'oldlace' => 'FDF5E6', 'olive' => '808000', 'olivedrab' => '6B8E23', 'orange' => 'FFA500', 'orangered' => 'FF4500', 'orchid' => 'DA70D6', 'palegoldenrod' => 'EEE8AA', 'palegreen' => '98FB98', 'paleturquoise' => 'AFEEEE', 'palevioletred' => 'DB7093', 'papayawhip' => 'FFEFD5', 'peachpuff' => 'FFDAB9', 'peru' => 'CD853F', 'pink' => 'FFC0CB', 'plum' => 'DDA0DD', 'powderblue' => 'B0E0E6', 'purple' => '800080', 'rebeccapurple' => '663399', 'red' => 'FF0000', 'rosybrown' => 'BC8F8F', 'royalblue' => '4169E1', 'saddlebrown' => '8B4513', 'salmon' => 'FA8072', 'sandybrown' => 'F4A460', 'seagreen' => '2E8B57', 'seashell' => 'FFF5EE', 'sienna' => 'A0522D', 'silver' => 'C0C0C0', 'skyblue' => '87CEEB', 'slateblue' => '6A5ACD', 'slategray' => '708090', 'snow' => 'FFFAFA', 'springgreen' => '00FF7F', 'steelblue' => '4682B4', 'tan' => 'D2B48C', 'teal' => '008080', 'thistle' => 'D8BFD8', 'tomato' => 'FF6347', 'turquoise' => '40E0D0', 'violet' => 'EE82EE', 'wheat' => 'F5DEB3', 'white' => 'FFFFFF', 'whitesmoke' => 'F5F5F5', 'yellow' => 'FFFF00', 'yellowgreen' => '9ACD32', ]; $name = strtolower($name); if (array_key_exists($name, $colors)) { return $colors[$name]; } } } src/Manipulators/Crop.php 0000644 00000004624 15107517132 0011435 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string|null $crop */ class Crop extends BaseManipulator { /** * Perform crop image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { $coordinates = $this->getCoordinates($image); if ($coordinates) { $coordinates = $this->limitToImageBoundaries($image, $coordinates); $image->crop( $coordinates[0], $coordinates[1], $coordinates[2], $coordinates[3] ); } return $image; } /** * Resolve coordinates. * * @param Image $image The source image. * * @return int[]|null The resolved coordinates. * * @psalm-return array{0: int, 1: int, 2: int, 3: int}|null */ public function getCoordinates(Image $image) { if (null === $this->crop) { return; } $coordinates = explode(',', $this->crop); if (4 !== count($coordinates) or (!is_numeric($coordinates[0])) or (!is_numeric($coordinates[1])) or (!is_numeric($coordinates[2])) or (!is_numeric($coordinates[3])) or ($coordinates[0] <= 0) or ($coordinates[1] <= 0) or ($coordinates[2] < 0) or ($coordinates[3] < 0) or ($coordinates[2] >= $image->width()) or ($coordinates[3] >= $image->height())) { return; } return [ (int) $coordinates[0], (int) $coordinates[1], (int) $coordinates[2], (int) $coordinates[3], ]; } /** * Limit coordinates to image boundaries. * * @param Image $image The source image. * @param int[] $coordinates The coordinates. * * @return int[] The limited coordinates. */ public function limitToImageBoundaries(Image $image, array $coordinates) { if ($coordinates[0] > ($image->width() - $coordinates[2])) { $coordinates[0] = $image->width() - $coordinates[2]; } if ($coordinates[1] > ($image->height() - $coordinates[3])) { $coordinates[1] = $image->height() - $coordinates[3]; } return $coordinates; } } src/Manipulators/Border.php 0000644 00000011447 15107517132 0011750 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; use League\Glide\Manipulators\Helpers\Color; use League\Glide\Manipulators\Helpers\Dimension; /** * @property string $border * @property string $dpr */ class Border extends BaseManipulator { /** * Perform border image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { if ($border = $this->getBorder($image)) { list($width, $color, $method) = $border; if ('overlay' === $method) { return $this->runOverlay($image, $width, $color); } if ('shrink' === $method) { return $this->runShrink($image, $width, $color); } if ('expand' === $method) { return $this->runExpand($image, $width, $color); } } return $image; } /** * Resolve border amount. * * @param Image $image The source image. * * @return (float|string)[]|null The resolved border amount. * * @psalm-return array{0: float, 1: string, 2: string}|null */ public function getBorder(Image $image) { if (!$this->border) { return; } $values = explode(',', $this->border); $width = $this->getWidth($image, $this->getDpr(), isset($values[0]) ? $values[0] : null); $color = $this->getColor(isset($values[1]) ? $values[1] : null); $method = $this->getMethod(isset($values[2]) ? $values[2] : null); if ($width) { return [$width, $color, $method]; } } /** * Get border width. * * @param Image $image The source image. * @param float $dpr The device pixel ratio. * @param string $width The border width. * * @return float|null The resolved border width. */ public function getWidth(Image $image, $dpr, $width) { return (new Dimension($image, $dpr))->get($width); } /** * Get formatted color. * * @param string $color The color. * * @return string The formatted color. */ public function getColor($color) { return (new Color($color))->formatted(); } /** * Resolve the border method. * * @param string $method The raw border method. * * @return string The resolved border method. */ public function getMethod($method) { if (!in_array($method, ['expand', 'shrink', 'overlay'], true)) { return 'overlay'; } return $method; } /** * Resolve the device pixel ratio. * * @return float The device pixel ratio. */ public function getDpr() { if (!is_numeric($this->dpr)) { return 1.0; } if ($this->dpr < 0 or $this->dpr > 8) { return 1.0; } return (float) $this->dpr; } /** * Run the overlay border method. * * @param Image $image The source image. * @param float $width The border width. * @param string $color The border color. * * @return Image The manipulated image. */ public function runOverlay(Image $image, $width, $color) { return $image->rectangle( (int) round($width / 2), (int) round($width / 2), (int) round($image->width() - ($width / 2)), (int) round($image->height() - ($width / 2)), function ($draw) use ($width, $color) { $draw->border($width, $color); } ); } /** * Run the shrink border method. * * @param Image $image The source image. * @param float $width The border width. * @param string $color The border color. * * @return Image The manipulated image. */ public function runShrink(Image $image, $width, $color) { return $image ->resize( (int) round($image->width() - ($width * 2)), (int) round($image->height() - ($width * 2)) ) ->resizeCanvas( (int) round($width * 2), (int) round($width * 2), 'center', true, $color ); } /** * Run the expand border method. * * @param Image $image The source image. * @param float $width The border width. * @param string $color The border color. * * @return Image The manipulated image. */ public function runExpand(Image $image, $width, $color) { return $image->resizeCanvas( (int) round($width * 2), (int) round($width * 2), 'center', true, $color ); } } src/Manipulators/Blur.php 0000644 00000001466 15107517133 0011440 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string $blur */ class Blur extends BaseManipulator { /** * Perform blur image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { $blur = $this->getBlur(); if (null !== $blur) { $image->blur($blur); } return $image; } /** * Resolve blur amount. * * @return int|null The resolved blur amount. */ public function getBlur() { if (!is_numeric($this->blur)) { return; } if ($this->blur < 0 or $this->blur > 100) { return; } return (int) $this->blur; } } src/Manipulators/Encode.php 0000644 00000004041 15107517133 0011721 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string $fm * @property string $q */ class Encode extends BaseManipulator { /** * Perform output image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { $format = $this->getFormat($image); $quality = $this->getQuality(); if (in_array($format, ['jpg', 'pjpg'], true)) { $image = $image->getDriver() ->newImage($image->width(), $image->height(), '#fff') ->insert($image, 'top-left', 0, 0); } if ('pjpg' === $format) { $image->interlace(); $format = 'jpg'; } return $image->encode($format, $quality); } /** * Resolve format. * * @param Image $image The source image. * * @return string The resolved format. */ public function getFormat(Image $image) { if (array_key_exists($this->fm, static::supportedFormats())) { return $this->fm; } return array_search($image->mime(), static::supportedFormats(), true) ?: 'jpg'; } /** * Get a list of supported image formats and MIME types. * * @return array<string,string> */ public static function supportedFormats() { return [ 'avif' => 'image/avif', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'pjpg' => 'image/jpeg', 'png' => 'image/png', 'webp' => 'image/webp', 'tiff' => 'image/tiff', ]; } /** * Resolve quality. * * @return int The resolved quality. */ public function getQuality() { $default = 90; if (!is_numeric($this->q)) { return $default; } if ($this->q < 0 or $this->q > 100) { return $default; } return (int) $this->q; } } src/Manipulators/BaseManipulator.php 0000644 00000001711 15107517133 0013613 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; abstract class BaseManipulator implements ManipulatorInterface { /** * The manipulation params. * * @var array */ public $params = []; /** * Set the manipulation params. * * @param array $params The manipulation params. * * @return $this */ public function setParams(array $params) { $this->params = $params; return $this; } /** * Get a specific manipulation param. * * @param string $name The manipulation name. * * @return string The manipulation value. */ public function __get($name) { if (array_key_exists($name, $this->params)) { return $this->params[$name]; } } /** * Perform the image manipulation. * * @return Image The manipulated image. */ abstract public function run(Image $image); } src/Manipulators/Size.php 0000644 00000030356 15107517133 0011446 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string $dpr * @property string|null $fit * @property string $h * @property string $w */ class Size extends BaseManipulator { /** * Maximum image size in pixels. * * @var int|null */ protected $maxImageSize; /** * Create Size instance. * * @param int|null $maxImageSize Maximum image size in pixels. */ public function __construct($maxImageSize = null) { $this->maxImageSize = $maxImageSize; } /** * Set the maximum image size. * * @param int|null Maximum image size in pixels. * * @return void */ public function setMaxImageSize($maxImageSize) { $this->maxImageSize = $maxImageSize; } /** * Get the maximum image size. * * @return int|null Maximum image size in pixels. */ public function getMaxImageSize() { return $this->maxImageSize; } /** * Perform size image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { $width = $this->getWidth(); $height = $this->getHeight(); $fit = $this->getFit(); $dpr = $this->getDpr(); list($width, $height) = $this->resolveMissingDimensions($image, $width, $height); list($width, $height) = $this->applyDpr($width, $height, $dpr); list($width, $height) = $this->limitImageSize($width, $height); if ((int) $width !== (int) $image->width() || (int) $height !== (int) $image->height() || 1.0 !== $this->getCrop()[2]) { $image = $this->runResize($image, $fit, (int) $width, (int) $height); } return $image; } /** * Resolve width. * * @return int|null The resolved width. */ public function getWidth() { if (!is_numeric($this->w)) { return; } if ($this->w <= 0) { return; } return (int) $this->w; } /** * Resolve height. * * @return int|null The resolved height. */ public function getHeight() { if (!is_numeric($this->h)) { return; } if ($this->h <= 0) { return; } return (int) $this->h; } /** * Resolve fit. * * @return string The resolved fit. */ public function getFit() { if (null === $this->fit) { return 'contain'; } if (in_array($this->fit, ['contain', 'fill', 'max', 'stretch', 'fill-max'], true)) { return $this->fit; } if (preg_match('/^(crop)(-top-left|-top|-top-right|-left|-center|-right|-bottom-left|-bottom|-bottom-right|-[\d]{1,3}-[\d]{1,3}(?:-[\d]{1,3}(?:\.\d+)?)?)*$/', $this->fit)) { return 'crop'; } return 'contain'; } /** * Resolve the device pixel ratio. * * @return float The device pixel ratio. */ public function getDpr() { if (!is_numeric($this->dpr)) { return 1.0; } if ($this->dpr < 0 or $this->dpr > 8) { return 1.0; } return (float) $this->dpr; } /** * Resolve missing image dimensions. * * @param Image $image The source image. * @param int|null $width The image width. * @param int|null $height The image height. * * @return int[] The resolved width and height. */ public function resolveMissingDimensions(Image $image, $width, $height) { if (is_null($width) and is_null($height)) { $width = $image->width(); $height = $image->height(); } if (is_null($width) || is_null($height)) { $size = (new \Intervention\Image\Size($image->width(), $image->height())) ->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); $width = $size->getWidth(); $height = $size->getHeight(); } return [ (int) $width, (int) $height, ]; } /** * Apply the device pixel ratio. * * @param int $width The target image width. * @param int $height The target image height. * @param float $dpr The device pixel ratio. * * @return int[] The modified width and height. */ public function applyDpr($width, $height, $dpr) { $width = $width * $dpr; $height = $height * $dpr; return [ (int) round($width), (int) round($height), ]; } /** * Limit image size to maximum allowed image size. * * @param int $width The image width. * @param int $height The image height. * * @return int[] The limited width and height. */ public function limitImageSize($width, $height) { if (null !== $this->maxImageSize) { $imageSize = $width * $height; if ($imageSize > $this->maxImageSize) { $width = $width / sqrt($imageSize / $this->maxImageSize); $height = $height / sqrt($imageSize / $this->maxImageSize); } } return [ (int) $width, (int) $height, ]; } /** * Perform resize image manipulation. * * @param Image $image The source image. * @param string $fit The fit. * @param int $width The width. * @param int $height The height. * * @return Image The manipulated image. */ public function runResize(Image $image, $fit, $width, $height) { if ('contain' === $fit) { return $this->runContainResize($image, $width, $height); } if ('fill' === $fit) { return $this->runFillResize($image, $width, $height); } if ('fill-max' === $fit) { return $this->runFillMaxResize($image, $width, $height); } if ('max' === $fit) { return $this->runMaxResize($image, $width, $height); } if ('stretch' === $fit) { return $this->runStretchResize($image, $width, $height); } if ('crop' === $fit) { return $this->runCropResize($image, $width, $height); } return $image; } /** * Perform contain resize image manipulation. * * @param Image $image The source image. * @param int $width The width. * @param int $height The height. * * @return Image The manipulated image. */ public function runContainResize(Image $image, $width, $height) { return $image->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); } /** * Perform max resize image manipulation. * * @param Image $image The source image. * @param int $width The width. * @param int $height The height. * * @return Image The manipulated image. */ public function runMaxResize(Image $image, $width, $height) { return $image->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); } /** * Perform fill resize image manipulation. * * @param Image $image The source image. * @param int $width The width. * @param int $height The height. * * @return Image The manipulated image. */ public function runFillResize($image, $width, $height) { $image = $this->runMaxResize($image, $width, $height); return $image->resizeCanvas($width, $height, 'center'); } /** * Perform fill-max resize image manipulation. * * @param Image $image The source image. * @param int $width The width. * @param int $height The height. * * @return Image The manipulated image. */ public function runFillMaxResize(Image $image, $width, $height) { $image = $image->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); return $image->resizeCanvas($width, $height, 'center'); } /** * Perform stretch resize image manipulation. * * @param Image $image The source image. * @param int $width The width. * @param int $height The height. * * @return Image The manipulated image. */ public function runStretchResize(Image $image, $width, $height) { return $image->resize($width, $height); } /** * Perform crop resize image manipulation. * * @param Image $image The source image. * @param int $width The width. * @param int $height The height. * * @return Image The manipulated image. */ public function runCropResize(Image $image, $width, $height) { list($resize_width, $resize_height) = $this->resolveCropResizeDimensions($image, $width, $height); $zoom = $this->getCrop()[2]; $image->resize($resize_width * $zoom, $resize_height * $zoom, function ($constraint) { $constraint->aspectRatio(); }); list($offset_x, $offset_y) = $this->resolveCropOffset($image, $width, $height); return $image->crop($width, $height, $offset_x, $offset_y); } /** * Resolve the crop resize dimensions. * * @param Image $image The source image. * @param int $width The width. * @param int $height The height. * * @return array The resize dimensions. */ public function resolveCropResizeDimensions(Image $image, $width, $height) { if ($height > $width * ($image->height() / $image->width())) { return [$height * ($image->width() / $image->height()), $height]; } return [$width, $width * ($image->height() / $image->width())]; } /** * Resolve the crop offset. * * @param Image $image The source image. * @param int $width The width. * @param int $height The height. * * @return array The crop offset. */ public function resolveCropOffset(Image $image, $width, $height) { list($offset_percentage_x, $offset_percentage_y) = $this->getCrop(); $offset_x = (int) (($image->width() * $offset_percentage_x / 100) - ($width / 2)); $offset_y = (int) (($image->height() * $offset_percentage_y / 100) - ($height / 2)); $max_offset_x = $image->width() - $width; $max_offset_y = $image->height() - $height; if ($offset_x < 0) { $offset_x = 0; } if ($offset_y < 0) { $offset_y = 0; } if ($offset_x > $max_offset_x) { $offset_x = $max_offset_x; } if ($offset_y > $max_offset_y) { $offset_y = $max_offset_y; } return [$offset_x, $offset_y]; } /** * Resolve crop with zoom. * * @return (float|int)[] The resolved crop. * * @psalm-return array{0: int, 1: int, 2: float} */ public function getCrop() { $cropMethods = [ 'crop-top-left' => [0, 0, 1.0], 'crop-top' => [50, 0, 1.0], 'crop-top-right' => [100, 0, 1.0], 'crop-left' => [0, 50, 1.0], 'crop-center' => [50, 50, 1.0], 'crop-right' => [100, 50, 1.0], 'crop-bottom-left' => [0, 100, 1.0], 'crop-bottom' => [50, 100, 1.0], 'crop-bottom-right' => [100, 100, 1.0], ]; if (null === $this->fit) { return [50, 50, 1.0]; } if (array_key_exists($this->fit, $cropMethods)) { return $cropMethods[$this->fit]; } if (preg_match('/^crop-([\d]{1,3})-([\d]{1,3})(?:-([\d]{1,3}(?:\.\d+)?))*$/', $this->fit, $matches)) { $matches[3] = isset($matches[3]) ? $matches[3] : 1; if ($matches[1] > 100 or $matches[2] > 100 or $matches[3] > 100) { return [50, 50, 1.0]; } return [ (int) $matches[1], (int) $matches[2], (float) $matches[3], ]; } return [50, 50, 1.0]; } } src/Manipulators/Contrast.php 0000644 00000001610 15107517133 0012320 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string|null $con */ class Contrast extends BaseManipulator { /** * Perform contrast image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { $contrast = $this->getContrast(); if (null !== $contrast) { $image->contrast($contrast); } return $image; } /** * Resolve contrast amount. * * @return int|null The resolved contrast amount. */ public function getContrast() { if (null === $this->con || !preg_match('/^-*[0-9]+$/', $this->con)) { return; } if ($this->con < -100 or $this->con > 100) { return; } return (int) $this->con; } } src/Manipulators/Sharpen.php 0000644 00000001531 15107517133 0012125 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string $sharp */ class Sharpen extends BaseManipulator { /** * Perform sharpen image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { $sharpen = $this->getSharpen(); if (null !== $sharpen) { $image->sharpen($sharpen); } return $image; } /** * Resolve sharpen amount. * * @return int|null The resolved sharpen amount. */ public function getSharpen() { if (!is_numeric($this->sharp)) { return; } if ($this->sharp < 0 or $this->sharp > 100) { return; } return (int) $this->sharp; } } src/Manipulators/ManipulatorInterface.php 0000644 00000000723 15107517133 0014643 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; interface ManipulatorInterface { /** * Set the manipulation params. * * @param array $params The manipulation params. */ public function setParams(array $params); /** * Perform the image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image); } src/Manipulators/Pixelate.php 0000644 00000001544 15107517133 0012304 0 ustar 00 <?php namespace League\Glide\Manipulators; use Intervention\Image\Image; /** * @property string $pixel */ class Pixelate extends BaseManipulator { /** * Perform pixelate image manipulation. * * @param Image $image The source image. * * @return Image The manipulated image. */ public function run(Image $image) { $pixelate = $this->getPixelate(); if (null !== $pixelate) { $image->pixelate($pixelate); } return $image; } /** * Resolve pixelate amount. * * @return int|null The resolved pixelate amount. */ public function getPixelate() { if (!is_numeric($this->pixel)) { return; } if ($this->pixel < 0 or $this->pixel > 1000) { return; } return (int) $this->pixel; } } src/Api/ApiInterface.php 0000644 00000000524 15107517134 0011114 0 ustar 00 <?php namespace League\Glide\Api; interface ApiInterface { /** * Perform image manipulations. * * @param string $source Source image binary data. * @param array $params The manipulation params. * * @return string Manipulated image binary data. */ public function run($source, array $params); } src/Api/Api.php 0000644 00000004640 15107517134 0007276 0 ustar 00 <?php namespace League\Glide\Api; use Intervention\Image\ImageManager; use InvalidArgumentException; use League\Glide\Manipulators\ManipulatorInterface; class Api implements ApiInterface { /** * Intervention image manager. * * @var ImageManager */ protected $imageManager; /** * Collection of manipulators. * * @var array */ protected $manipulators; /** * Create API instance. * * @param ImageManager $imageManager Intervention image manager. * @param array $manipulators Collection of manipulators. */ public function __construct(ImageManager $imageManager, array $manipulators) { $this->setImageManager($imageManager); $this->setManipulators($manipulators); } /** * Set the image manager. * * @param ImageManager $imageManager Intervention image manager. * * @return void */ public function setImageManager(ImageManager $imageManager) { $this->imageManager = $imageManager; } /** * Get the image manager. * * @return ImageManager Intervention image manager. */ public function getImageManager() { return $this->imageManager; } /** * Set the manipulators. * * @param array $manipulators Collection of manipulators. * * @return void */ public function setManipulators(array $manipulators) { foreach ($manipulators as $manipulator) { if (!($manipulator instanceof ManipulatorInterface)) { throw new InvalidArgumentException('Not a valid manipulator.'); } } $this->manipulators = $manipulators; } /** * Get the manipulators. * * @return array Collection of manipulators. */ public function getManipulators() { return $this->manipulators; } /** * Perform image manipulations. * * @param string $source Source image binary data. * @param array $params The manipulation params. * * @return string Manipulated image binary data. */ public function run($source, array $params) { $image = $this->imageManager->make($source); foreach ($this->manipulators as $manipulator) { $manipulator->setParams($params); $image = $manipulator->run($image); } return $image->getEncoded(); } } src/ServerFactory.php 0000644 00000020673 15107517134 0010656 0 ustar 00 <?php namespace League\Glide; use Intervention\Image\ImageManager; use InvalidArgumentException; use League\Flysystem\Filesystem; use League\Flysystem\FilesystemOperator; use League\Flysystem\Local\LocalFilesystemAdapter; use League\Glide\Api\Api; use League\Glide\Manipulators\Background; use League\Glide\Manipulators\Blur; use League\Glide\Manipulators\Border; use League\Glide\Manipulators\Brightness; use League\Glide\Manipulators\Contrast; use League\Glide\Manipulators\Crop; use League\Glide\Manipulators\Encode; use League\Glide\Manipulators\Filter; use League\Glide\Manipulators\Flip; use League\Glide\Manipulators\Gamma; use League\Glide\Manipulators\Orientation; use League\Glide\Manipulators\Pixelate; use League\Glide\Manipulators\Sharpen; use League\Glide\Manipulators\Size; use League\Glide\Manipulators\Watermark; use League\Glide\Responses\ResponseFactoryInterface; class ServerFactory { /** * Configuration parameters. * * @var array */ protected $config; /** * Create ServerFactory instance. * * @param array $config Configuration parameters. */ public function __construct(array $config = []) { $this->config = $config; } /** * Get configured server. * * @return Server Configured Glide server. */ public function getServer() { $server = new Server( $this->getSource(), $this->getCache(), $this->getApi() ); $server->setSourcePathPrefix($this->getSourcePathPrefix() ?: ''); $server->setCachePathPrefix($this->getCachePathPrefix() ?: ''); $server->setGroupCacheInFolders($this->getGroupCacheInFolders()); $server->setCacheWithFileExtensions($this->getCacheWithFileExtensions()); $server->setDefaults($this->getDefaults()); $server->setPresets($this->getPresets()); $server->setBaseUrl($this->getBaseUrl() ?: ''); $server->setResponseFactory($this->getResponseFactory()); $server->setCachePathCallable($this->getCachePathCallable()); if ($this->getTempDir()) { $server->setTempDir($this->getTempDir()); } return $server; } /** * Get source file system. * * @return FilesystemOperator Source file system. */ public function getSource() { if (!isset($this->config['source'])) { throw new InvalidArgumentException('A "source" file system must be set.'); } if (is_string($this->config['source'])) { return new Filesystem( new LocalFilesystemAdapter($this->config['source']) ); } return $this->config['source']; } /** * Get source path prefix. * * @return string|null Source path prefix. */ public function getSourcePathPrefix() { if (isset($this->config['source_path_prefix'])) { return $this->config['source_path_prefix']; } } /** * Get cache file system. * * @return FilesystemOperator Cache file system. */ public function getCache() { if (!isset($this->config['cache'])) { throw new InvalidArgumentException('A "cache" file system must be set.'); } if (is_string($this->config['cache'])) { return new Filesystem( new LocalFilesystemAdapter($this->config['cache']) ); } return $this->config['cache']; } /** * Get cache path prefix. * * @return string|null Cache path prefix. */ public function getCachePathPrefix() { if (isset($this->config['cache_path_prefix'])) { return $this->config['cache_path_prefix']; } } /** * Get temporary EXIF data directory. * * @return string */ public function getTempDir() { if (isset($this->config['temp_dir'])) { return $this->config['temp_dir']; } } /** * Get cache path callable. * * @return \Closure|null Cache path callable. */ public function getCachePathCallable() { return $this->config['cache_path_callable'] ?? null; } /** * Get the group cache in folders setting. * * @return bool Whether to group cache in folders. */ public function getGroupCacheInFolders() { if (isset($this->config['group_cache_in_folders'])) { return $this->config['group_cache_in_folders']; } return true; } /** * Get the cache with file extensions setting. * * @return bool Whether to cache with file extensions. */ public function getCacheWithFileExtensions() { if (isset($this->config['cache_with_file_extensions'])) { return $this->config['cache_with_file_extensions']; } return false; } /** * Get watermarks file system. * * @return FilesystemOperator|null Watermarks file system. */ public function getWatermarks() { if (!isset($this->config['watermarks'])) { return; } if (is_string($this->config['watermarks'])) { return new Filesystem( new LocalFilesystemAdapter($this->config['watermarks']) ); } return $this->config['watermarks']; } /** * Get watermarks path prefix. * * @return string|null Watermarks path prefix. */ public function getWatermarksPathPrefix() { if (isset($this->config['watermarks_path_prefix'])) { return $this->config['watermarks_path_prefix']; } } /** * Get image manipulation API. * * @return Api Image manipulation API. */ public function getApi() { return new Api( $this->getImageManager(), $this->getManipulators() ); } /** * Get Intervention image manager. * * @return ImageManager Intervention image manager. */ public function getImageManager() { $driver = 'gd'; if (isset($this->config['driver'])) { $driver = $this->config['driver']; } return new ImageManager([ 'driver' => $driver, ]); } /** * Get image manipulators. * * @return array Image manipulators. */ public function getManipulators() { return [ new Orientation(), new Crop(), new Size($this->getMaxImageSize()), new Brightness(), new Contrast(), new Gamma(), new Sharpen(), new Filter(), new Flip(), new Blur(), new Pixelate(), new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix() ?: ''), new Background(), new Border(), new Encode(), ]; } /** * Get maximum image size. * * @return int|null Maximum image size. */ public function getMaxImageSize() { if (isset($this->config['max_image_size'])) { return $this->config['max_image_size']; } } /** * Get default image manipulations. * * @return array Default image manipulations. */ public function getDefaults() { if (isset($this->config['defaults'])) { return $this->config['defaults']; } return []; } /** * Get preset image manipulations. * * @return array Preset image manipulations. */ public function getPresets() { if (isset($this->config['presets'])) { return $this->config['presets']; } return []; } /** * Get base URL. * * @return string|null Base URL. */ public function getBaseUrl() { if (isset($this->config['base_url'])) { return $this->config['base_url']; } } /** * Get response factory. * * @return ResponseFactoryInterface|null Response factory. */ public function getResponseFactory() { if (isset($this->config['response'])) { return $this->config['response']; } } /** * Create configured server. * * @param array $config Configuration parameters. * * @return Server Configured server. */ public static function create(array $config = []) { return (new self($config))->getServer(); } } src/Server.php 0000644 00000041052 15107517134 0007320 0 ustar 00 <?php namespace League\Glide; use Closure; use InvalidArgumentException; use League\Flysystem\FilesystemException as FilesystemV2Exception; use League\Flysystem\FilesystemOperator; use League\Glide\Api\ApiInterface; use League\Glide\Filesystem\FileNotFoundException; use League\Glide\Filesystem\FilesystemException; use League\Glide\Responses\ResponseFactoryInterface; class Server { /** * Source file system. * * @var FilesystemOperator */ protected $source; /** * Source path prefix. * * @var string */ protected $sourcePathPrefix; /** * Cache file system. * * @var FilesystemOperator */ protected $cache; /** * Cache path prefix. * * @var string */ protected $cachePathPrefix; /** * Temporary EXIF data directory. * * @var string */ protected $tempDir; /** * Whether to group cache in folders. * * @var bool */ protected $groupCacheInFolders = true; /** * Whether to cache with file extensions. * * @var bool */ protected $cacheWithFileExtensions = false; /** * Image manipulation API. * * @var ApiInterface */ protected $api; /** * Response factory. * * @var ResponseFactoryInterface|null */ protected $responseFactory; /** * Base URL. * * @var string */ protected $baseUrl; /** * Default image manipulations. * * @var array */ protected $defaults = []; /** * Preset image manipulations. * * @var array */ protected $presets = []; /** * Custom cache path callable. * * @var \Closure|null */ protected $cachePathCallable; /** * Create Server instance. * * @param FilesystemOperator $source Source file system. * @param FilesystemOperator $cache Cache file system. * @param ApiInterface $api Image manipulation API. */ public function __construct(FilesystemOperator $source, FilesystemOperator $cache, ApiInterface $api) { $this->setSource($source); $this->setCache($cache); $this->setApi($api); $this->tempDir = sys_get_temp_dir(); } /** * Set source file system. * * @param FilesystemOperator $source Source file system. * * @return void */ public function setSource(FilesystemOperator $source) { $this->source = $source; } /** * Get source file system. * * @return FilesystemOperator Source file system. */ public function getSource() { return $this->source; } /** * Set source path prefix. * * @param string $sourcePathPrefix Source path prefix. * * @return void */ public function setSourcePathPrefix($sourcePathPrefix) { $this->sourcePathPrefix = trim($sourcePathPrefix, '/'); } /** * Get source path prefix. * * @return string Source path prefix. */ public function getSourcePathPrefix() { return $this->sourcePathPrefix; } /** * Get source path. * * @param string $path Image path. * * @return string The source path. * * @throws FileNotFoundException */ public function getSourcePath($path) { $path = trim($path, '/'); $baseUrl = $this->baseUrl.'/'; if (substr($path, 0, strlen($baseUrl)) === $baseUrl) { $path = trim(substr($path, strlen($baseUrl)), '/'); } if ('' === $path) { throw new FileNotFoundException('Image path missing.'); } if ($this->sourcePathPrefix) { $path = $this->sourcePathPrefix.'/'.$path; } return rawurldecode($path); } /** * Check if a source file exists. * * @param string $path Image path. * * @return bool Whether the source file exists. */ public function sourceFileExists($path) { try { return $this->source->fileExists($this->getSourcePath($path)); } catch (FilesystemV2Exception $exception) { return false; } } /** * Set base URL. * * @param string $baseUrl Base URL. * * @return void */ public function setBaseUrl($baseUrl) { $this->baseUrl = trim($baseUrl, '/'); } /** * Get base URL. * * @return string Base URL. */ public function getBaseUrl() { return $this->baseUrl; } /** * Set cache file system. * * @param FilesystemOperator $cache Cache file system. * * @return void */ public function setCache(FilesystemOperator $cache) { $this->cache = $cache; } /** * Get cache file system. * * @return FilesystemOperator Cache file system. */ public function getCache() { return $this->cache; } /** * Set cache path prefix. * * @param string $cachePathPrefix Cache path prefix. * * @return void */ public function setCachePathPrefix($cachePathPrefix) { $this->cachePathPrefix = trim($cachePathPrefix, '/'); } /** * Get cache path prefix. * * @return string Cache path prefix. */ public function getCachePathPrefix() { return $this->cachePathPrefix; } /** * Get temporary EXIF data directory. * * @return string */ public function getTempDir() { return $this->tempDir; } /** * Set temporary EXIF data directory. This directory must be a local path and exists on the filesystem. * * @param string $tempDir * * @return void * * @throws InvalidArgumentException */ public function setTempDir($tempDir) { if (!$tempDir || !is_dir($tempDir)) { throw new InvalidArgumentException(sprintf('Invalid temp dir provided: "%s" does not exist.', $tempDir)); } $this->tempDir = rtrim($tempDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; } /** * Set the group cache in folders setting. * * @param bool $groupCacheInFolders Whether to group cache in folders. * * @return void */ public function setGroupCacheInFolders($groupCacheInFolders) { $this->groupCacheInFolders = $groupCacheInFolders; } /** * Get the group cache in folders setting. * * @return bool Whether to group cache in folders. */ public function getGroupCacheInFolders() { return $this->groupCacheInFolders; } /** * Set the cache with file extensions setting. * * @param bool $cacheWithFileExtensions Whether to cache with file extensions. * * @return void */ public function setCacheWithFileExtensions($cacheWithFileExtensions) { $this->cacheWithFileExtensions = $cacheWithFileExtensions; } /** * Get the cache with file extensions setting. * * @return bool Whether to cache with file extensions. */ public function getCacheWithFileExtensions() { return $this->cacheWithFileExtensions; } /** * Set a custom cachePathCallable. * * @param \Closure|null $cachePathCallable The custom cache path callable. It receives the same arguments as @see getCachePath */ public function setCachePathCallable(?Closure $cachePathCallable) { $this->cachePathCallable = $cachePathCallable; } /** * Gets the custom cachePathCallable. * * @return \Closure|null The custom cache path callable. It receives the same arguments as @see getCachePath */ public function getCachePathCallable() { return $this->cachePathCallable; } /** * Get cache path. * * @param string $path Image path. * @param array $params Image manipulation params. * * @return string Cache path. */ public function getCachePath($path, array $params = []) { $customCallable = $this->getCachePathCallable(); if (null !== $customCallable) { $boundCallable = Closure::bind($customCallable, $this, static::class); return $boundCallable($path, $params); } $sourcePath = $this->getSourcePath($path); if ($this->sourcePathPrefix) { $sourcePath = substr($sourcePath, strlen($this->sourcePathPrefix) + 1); } $params = $this->getAllParams($params); unset($params['s'], $params['p']); ksort($params); $cachedPath = md5($sourcePath.'?'.http_build_query($params)); if ($this->groupCacheInFolders) { $cachedPath = $sourcePath.'/'.$cachedPath; } if ($this->cachePathPrefix) { $cachedPath = $this->cachePathPrefix.'/'.$cachedPath; } if ($this->cacheWithFileExtensions) { $ext = (isset($params['fm']) ? $params['fm'] : pathinfo($path)['extension']); $ext = ('pjpg' === $ext) ? 'jpg' : $ext; $cachedPath .= '.'.$ext; } return $cachedPath; } /** * Check if a cache file exists. * * @param string $path Image path. * @param array $params Image manipulation params. * * @return bool Whether the cache file exists. */ public function cacheFileExists($path, array $params) { try { return $this->cache->fileExists( $this->getCachePath($path, $params) ); } catch (FilesystemV2Exception $exception) { return false; } } /** * Delete cached manipulations for an image. * * @param string $path Image path. * * @return bool Whether the delete succeeded. */ public function deleteCache($path) { if (!$this->groupCacheInFolders) { throw new InvalidArgumentException('Deleting cached image manipulations is not possible when grouping cache into folders is disabled.'); } try { $this->cache->deleteDirectory( dirname($this->getCachePath($path)) ); return true; } catch (FilesystemV2Exception $exception) { return false; } } /** * Set image manipulation API. * * @param ApiInterface $api Image manipulation API. * * @return void */ public function setApi(ApiInterface $api) { $this->api = $api; } /** * Get image manipulation API. * * @return ApiInterface Image manipulation API. */ public function getApi() { return $this->api; } /** * Set default image manipulations. * * @param array $defaults Default image manipulations. * * @return void */ public function setDefaults(array $defaults) { $this->defaults = $defaults; } /** * Get default image manipulations. * * @return array Default image manipulations. */ public function getDefaults() { return $this->defaults; } /** * Set preset image manipulations. * * @param array $presets Preset image manipulations. * * @return void */ public function setPresets(array $presets) { $this->presets = $presets; } /** * Get preset image manipulations. * * @return array Preset image manipulations. */ public function getPresets() { return $this->presets; } /** * Get all image manipulations params, including defaults and presets. * * @param array $params Image manipulation params. * * @return array All image manipulation params. */ public function getAllParams(array $params) { $all = $this->defaults; if (isset($params['p'])) { foreach (explode(',', $params['p']) as $preset) { if (isset($this->presets[$preset])) { $all = array_merge($all, $this->presets[$preset]); } } } return array_merge($all, $params); } /** * Set response factory. * * @param ResponseFactoryInterface|null $responseFactory Response factory. * * @return void */ public function setResponseFactory(ResponseFactoryInterface $responseFactory = null) { $this->responseFactory = $responseFactory; } /** * Get response factory. * * @return ResponseFactoryInterface|null Response factory. */ public function getResponseFactory() { return $this->responseFactory; } /** * Generate and return image response. * * @param string $path Image path. * @param array $params Image manipulation params. * * @return mixed Image response. * * @throws InvalidArgumentException */ public function getImageResponse($path, array $params) { if (is_null($this->responseFactory)) { throw new InvalidArgumentException('Unable to get image response, no response factory defined.'); } $path = $this->makeImage($path, $params); return $this->responseFactory->create($this->cache, $path); } /** * Generate and return Base64 encoded image. * * @param string $path Image path. * @param array $params Image manipulation params. * * @return string Base64 encoded image. * * @throws FilesystemException */ public function getImageAsBase64($path, array $params) { $path = $this->makeImage($path, $params); try { $source = $this->cache->read($path); return 'data:'.$this->cache->mimeType($path).';base64,'.base64_encode($source); } catch (FilesystemV2Exception $exception) { throw new FilesystemException('Could not read the image `'.$path.'`.'); } } /** * Generate and output image. * * @param string $path Image path. * @param array $params Image manipulation params. * * @throws InvalidArgumentException * * @return void */ public function outputImage($path, array $params) { $path = $this->makeImage($path, $params); try { header('Content-Type:'.$this->cache->mimeType($path)); header('Content-Length:'.$this->cache->fileSize($path)); header('Cache-Control:'.'max-age=31536000, public'); header('Expires:'.date_create('+1 years')->format('D, d M Y H:i:s').' GMT'); $stream = $this->cache->readStream($path); if (0 !== ftell($stream)) { rewind($stream); } fpassthru($stream); fclose($stream); } catch (FilesystemV2Exception $exception) { throw new FilesystemException('Could not read the image `'.$path.'`.'); } } /** * Generate manipulated image. * * @param string $path Image path. * @param array $params Image manipulation params. * * @return string Cache path. * * @throws FileNotFoundException * @throws FilesystemException */ public function makeImage($path, array $params) { $sourcePath = $this->getSourcePath($path); $cachedPath = $this->getCachePath($path, $params); if (true === $this->cacheFileExists($path, $params)) { return $cachedPath; } if (false === $this->sourceFileExists($path)) { throw new FileNotFoundException('Could not find the image `'.$sourcePath.'`.'); } try { $source = $this->source->read( $sourcePath ); } catch (FilesystemV2Exception $exception) { throw new FilesystemException('Could not read the image `'.$sourcePath.'`.'); } // We need to write the image to the local disk before // doing any manipulations. This is because EXIF data // can only be read from an actual file. $tmp = tempnam($this->tempDir, 'Glide'); if (false === file_put_contents($tmp, $source)) { throw new FilesystemException('Unable to write temp file for `'.$sourcePath.'`.'); } try { $this->cache->write( $cachedPath, $this->api->run($tmp, $this->getAllParams($params)) ); } catch (FilesystemV2Exception $exception) { throw new FilesystemException('Could not write the image `'.$cachedPath.'`.'); } finally { unlink($tmp); } return $cachedPath; } } src/Responses/ResponseFactoryInterface.php 0000644 00000000616 15107517134 0015003 0 ustar 00 <?php namespace League\Glide\Responses; use League\Flysystem\FilesystemOperator; interface ResponseFactoryInterface { /** * Create response. * * @param FilesystemOperator $cache Cache file system. * @param string $path Cached file path. * * @return mixed The response object. */ public function create(FilesystemOperator $cache, $path); } src/Responses/PsrResponseFactory.php 0000644 00000003263 15107517134 0013650 0 ustar 00 <?php namespace League\Glide\Responses; use Closure; use League\Flysystem\FilesystemOperator; use Psr\Http\Message\ResponseInterface; class PsrResponseFactory implements ResponseFactoryInterface { /** * Base response object. * * @var ResponseInterface */ protected $response; /** * Callback to create stream. * * @var Closure */ protected $streamCallback; /** * Create PsrResponseFactory instance. * * @param ResponseInterface $response Base response object. * @param Closure $streamCallback Callback to create stream. */ public function __construct(ResponseInterface $response, Closure $streamCallback) { $this->response = $response; $this->streamCallback = $streamCallback; } /** * Create response. * * @param FilesystemOperator $cache Cache file system. * @param string $path Cached file path. * * @return ResponseInterface Response object. */ public function create(FilesystemOperator $cache, $path) { $stream = $this->streamCallback->__invoke( $cache->readStream($path) ); $contentType = $cache->mimeType($path); $contentLength = (string) $cache->fileSize($path); $cacheControl = 'max-age=31536000, public'; $expires = date_create('+1 years')->format('D, d M Y H:i:s').' GMT'; return $this->response->withBody($stream) ->withHeader('Content-Type', $contentType) ->withHeader('Content-Length', $contentLength) ->withHeader('Cache-Control', $cacheControl) ->withHeader('Expires', $expires); } } src/Filesystem/FilesystemException.php 0000644 00000000153 15107517134 0014176 0 ustar 00 <?php namespace League\Glide\Filesystem; use Exception; class FilesystemException extends Exception { } src/Filesystem/FileNotFoundException.php 0000644 00000000155 15107517135 0014411 0 ustar 00 <?php namespace League\Glide\Filesystem; use Exception; class FileNotFoundException extends Exception { } src/Urls/UrlBuilderFactory.php 0000644 00000001171 15107517135 0012377 0 ustar 00 <?php namespace League\Glide\Urls; use League\Glide\Signatures\SignatureFactory; class UrlBuilderFactory { /** * Create UrlBuilder instance. * * @param string $baseUrl URL prefixed to generated URL. * @param string|null $signKey Secret key used to secure URLs. * * @return UrlBuilder The UrlBuilder instance. */ public static function create($baseUrl, $signKey = null) { $httpSignature = null; if (!is_null($signKey)) { $httpSignature = SignatureFactory::create($signKey); } return new UrlBuilder($baseUrl, $httpSignature); } } src/Urls/UrlBuilder.php 0000644 00000005563 15107517135 0011060 0 ustar 00 <?php namespace League\Glide\Urls; use InvalidArgumentException; use League\Glide\Signatures\SignatureInterface; class UrlBuilder { /** * The base URL. * * @var string */ protected $baseUrl; /** * Whether the base URL is a relative domain. * * @var bool */ protected $isRelativeDomain = false; /** * The HTTP signature used to sign URLs. * * @var SignatureInterface */ protected $signature; /** * Create UrlBuilder instance. * * @param string $baseUrl The base URL. * @param SignatureInterface|null $signature The HTTP signature used to sign URLs. */ public function __construct($baseUrl = '', SignatureInterface $signature = null) { $this->setBaseUrl($baseUrl); $this->setSignature($signature); } /** * Set the base URL. * * @param string $baseUrl The base URL. * * @return void */ public function setBaseUrl($baseUrl) { if ('//' === substr($baseUrl, 0, 2)) { $baseUrl = 'http:'.$baseUrl; $this->isRelativeDomain = true; } $this->baseUrl = rtrim($baseUrl, '/'); } /** * Set the HTTP signature. * * @param SignatureInterface|null $signature The HTTP signature used to sign URLs. * * @return void */ public function setSignature(SignatureInterface $signature = null) { $this->signature = $signature; } /** * Get the URL. * * @param string $path The resource path. * @param array $params The manipulation parameters. * * @return string The URL. */ public function getUrl($path, array $params = []) { $parts = parse_url($this->baseUrl.'/'.trim($path, '/')); if (false === $parts) { throw new InvalidArgumentException('Not a valid path.'); } $parts['path'] = '/'.trim($parts['path'], '/'); if ($this->signature) { $params = $this->signature->addSignature($parts['path'], $params); } return $this->buildUrl($parts, $params); } /** * Build the URL. * * @param array $parts The URL parts. * @param array $params The manipulation parameters. * * @return string The built URL. */ protected function buildUrl($parts, $params) { $url = ''; if (isset($parts['host'])) { if ($this->isRelativeDomain) { $url .= '//'.$parts['host']; } else { $url .= $parts['scheme'].'://'.$parts['host']; } if (isset($parts['port'])) { $url .= ':'.$parts['port']; } } $url .= $parts['path']; if (count($params)) { $url .= '?'.http_build_query($params); } return $url; } } README.md 0000644 00000007066 15107517135 0006041 0 ustar 00 # Glide [](https://github.com/thephpleague/glide/releases) [](https://github.com/thephpleague/glide/blob/master/LICENSE) [](https://github.com/thephpleague/glide/actions/workflows/test.yaml?query=branch%3Amaster++) [](https://app.codecov.io/gh/thephpleague/glide/) [](https://packagist.org/packages/league/glide) [](https://github.com/thephpleague/glide) [](https://twitter.com/reinink) [](https://twitter.com/titouangalopin) Glide is a wonderfully easy on-demand image manipulation library written in PHP. Its straightforward API is exposed via HTTP, similar to cloud image processing services like [Imgix](http://www.imgix.com/) and [Cloudinary](http://cloudinary.com/). Glide leverages powerful libraries like [Intervention Image](http://image.intervention.io/) (for image handling and manipulation) and [Flysystem](http://flysystem.thephpleague.com/) (for file system abstraction). [](https://glide.herokuapp.com/1.0/kayaks.jpg?w=1000) > © Photo Joel Reynolds ## Highlights - Adjust, resize and add effects to images using a simple HTTP based API. - Manipulated images are automatically cached and served with far-future expires headers. - Create your own image processing server or integrate Glide directly into your app. - Supports both the [GD](http://php.net/manual/en/book.image.php) library and the [Imagick](http://php.net/manual/en/book.imagick.php) PHP extension. - Supports many response methods, including PSR-7, HttpFoundation and more. - Ability to secure image URLs using HTTP signatures. - Works with many different file systems, thanks to the [Flysystem](http://flysystem.thephpleague.com/) library. - Powered by the battle tested [Intervention Image](http://image.intervention.io/) image handling and manipulation library. - Framework-agnostic, will work with any project. - Composer ready and PSR-2 compliant. ## Documentation Full documentation can be found at [glide.thephpleague.com](http://glide.thephpleague.com). ## Installation Glide is available via Composer: ```bash $ composer require league/glide ``` ## Testing Glide has a [PHPUnit](https://phpunit.de/) test suite. To run the tests, run the following command from the project folder: ```bash $ phpunit ``` ## Contributing Contributions are welcome and will be fully credited. Please see [CONTRIBUTING](https://github.com/thephpleague/glide/blob/master/CONTRIBUTING.md) for details. ## Security If you discover any security related issues, please email jonathan@reinink.ca instead of using the issue tracker. ## Credits - [Jonathan Reinink](https://github.com/reinink) - [All Contributors](https://github.com/thephpleague/glide/contributors) ## License The MIT License (MIT). Please see [LICENSE](https://github.com/thephpleague/glide/blob/master/LICENSE) for more information. LICENSE 0000644 00000002120 15107517135 0005551 0 ustar 00 The MIT License (MIT) Copyright (c) 2015 Jonathan Reinink <jonathan@reinink.ca> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. composer.json 0000644 00000002154 15107517135 0007275 0 ustar 00 { "name": "league/glide", "description": "Wonderfully easy on-demand image manipulation library with an HTTP based API.", "keywords": [ "league", "image", "processing", "manipulation", "editing", "gd", "imagemagick", "imagick" ], "homepage": "http://glide.thephpleague.com", "license": "MIT", "authors": [ { "name": "Jonathan Reinink", "email": "jonathan@reinink.ca", "homepage": "http://reinink.ca" }, { "name": "Titouan Galopin", "email": "galopintitouan@gmail.com", "homepage": "https://titouangalopin.com" } ], "require": { "php": "^7.2|^8.0", "intervention/image": "^2.7", "league/flysystem": "^2.0|^3.0", "psr/http-message": "^1.0|^2.0" }, "require-dev": { "mockery/mockery": "^1.3.3", "phpunit/phpunit": "^8.5|^9.0", "phpunit/php-token-stream": "^3.1|^4.0" }, "autoload": { "psr-4": { "League\\Glide\\": "src/" } } } psalm-baseline.xml 0000644 00000000430 15107517135 0010164 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <files psalm-version="dev-master@"> <file src="src/ServerFactory.php"> <UndefinedClass occurrences="3"> <code>Filesystem</code> <code>Filesystem</code> <code>Filesystem</code> </UndefinedClass> </file> </files>
Simpan