One Hat Cyber Team
Your IP:
216.73.216.215
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
/
proc
/
thread-self
/
cwd
/
Edit File:
Manipulators.tar
Brightness.php 0000644 00000001634 15110322264 0007365 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; } } Orientation.php 0000644 00000001523 15110322264 0007545 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'; } } Flip.php 0000644 00000001456 15110322265 0006152 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; } } } Gamma.php 0000644 00000001553 15110322265 0006300 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; } } Background.php 0000644 00000001425 15110322265 0007333 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; } } Filter.php 0000644 00000002406 15110322265 0006501 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; } } Watermark.php 0000644 00000014611 15110322265 0007212 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; } } Helpers/Dimension.php 0000644 00000002245 15110322265 0010604 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); } } } Helpers/Color.php 0000644 00000020051 15110322265 0007730 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]; } } } Crop.php 0000644 00000004624 15110322265 0006163 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; } } Border.php 0000644 00000011447 15110322265 0006476 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 ); } } Blur.php 0000644 00000001466 15110322265 0006165 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; } } Encode.php 0000644 00000004041 15110322265 0006446 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; } } BaseManipulator.php 0000644 00000001711 15110322265 0010340 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); } Size.php 0000644 00000030356 15110322265 0006173 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]; } } Contrast.php 0000644 00000001610 15110322265 0007045 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; } } Sharpen.php 0000644 00000001531 15110322265 0006652 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; } } ManipulatorInterface.php 0000644 00000000723 15110322265 0011370 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); } Pixelate.php 0000644 00000001544 15110322265 0007031 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; } }
Simpan