PK!}ȉ8 .gitignorenu[.idea vendor composer.lockPK!g" composer.jsonnu[{ "name": "gumlet/php-image-resize", "description": "PHP class to re-size and scale images", "keywords": ["php", "image", "resize", "scale"], "type": "library", "homepage": "https://github.com/gumlet/php-image-resize", "license": "MIT", "authors": [ { "name": "Aditya Patadia", "homepage": "http://aditya.patadia.org/" }], "require": { "php": ">=5.6.0", "ext-gd": "*", "ext-fileinfo": "*" }, "suggest": { "ext-exif": "Auto-rotate jpeg files" }, "autoload": { "psr-4": { "Gumlet\\": "lib/" } }, "autoload-dev": { "psr-4": { "Gumlet\\": "test/" } }, "require-dev": { "phpunit/phpunit": "^8.5", "apigen/apigen": "^4.1", "php-coveralls/php-coveralls": "^2.1", "ext-exif": "*", "ext-gd": "*" } } PK!g=[[lib/ImageResize.phpnu[filters[] = $filter; return $this; } /** * Apply filters. * * @param $image resource an image resource identifier * @param $filterType filter type and default value is IMG_FILTER_NEGATE */ protected function applyFilter($image, $filterType = IMG_FILTER_NEGATE) { foreach ($this->filters as $function) { $function($image, $filterType); } } /** * Loads image source and its properties to the instanciated object * * @param string $filename * @return ImageResize * @throws ImageResizeException */ public function __construct($filename) { if (!defined('IMAGETYPE_WEBP')) { define('IMAGETYPE_WEBP', 18); } if (!defined('IMAGETYPE_BMP')) { define('IMAGETYPE_BMP', 6); } if ($filename === null || empty($filename) || (substr($filename, 0, 5) !== 'data:' && !is_file($filename))) { throw new ImageResizeException('File does not exist'); } $finfo = finfo_open(FILEINFO_MIME_TYPE); $checkWebp = false; if (strstr(finfo_file($finfo, $filename), 'image') === false) { if (version_compare(PHP_VERSION, '7.0.0', '<=') && strstr(file_get_contents($filename), 'WEBPVP8') !== false) { $checkWebp = true; $this->source_type = IMAGETYPE_WEBP; } else { throw new ImageResizeException('Unsupported file type'); } } elseif(strstr(finfo_file($finfo, $filename), 'image/webp') !== false) { $checkWebp = true; $this->source_type = IMAGETYPE_WEBP; } if (!$image_info = getimagesize($filename, $this->source_info)) { $image_info = getimagesize($filename); } if (!$checkWebp) { if (!$image_info) { if (strstr(finfo_file($finfo, $filename), 'image') !== false) { throw new ImageResizeException('Unsupported image type'); } throw new ImageResizeException('Could not read file'); } $this->original_w = $image_info[0]; $this->original_h = $image_info[1]; $this->source_type = $image_info[2]; } switch ($this->source_type) { case IMAGETYPE_GIF: $this->source_image = imagecreatefromgif($filename); break; case IMAGETYPE_JPEG: $this->source_image = $this->imageCreateJpegfromExif($filename); // set new width and height for image, maybe it has changed $this->original_w = imagesx($this->source_image); $this->original_h = imagesy($this->source_image); break; case IMAGETYPE_PNG: $this->source_image = imagecreatefrompng($filename); break; case IMAGETYPE_WEBP: $this->source_image = imagecreatefromwebp($filename); $this->original_w = imagesx($this->source_image); $this->original_h = imagesy($this->source_image); break; case IMAGETYPE_BMP: if (version_compare(PHP_VERSION, '7.2.0', '<')) { throw new ImageResizeException('For bmp support PHP >= 7.2.0 is required'); } $this->source_image = imagecreatefrombmp($filename); break; default: throw new ImageResizeException('Unsupported image type'); } if (!$this->source_image) { throw new ImageResizeException('Could not load image'); } finfo_close($finfo); return $this->resize($this->getSourceWidth(), $this->getSourceHeight()); } // http://stackoverflow.com/a/28819866 public function imageCreateJpegfromExif($filename) { $img = imagecreatefromjpeg($filename); if (!function_exists('exif_read_data') || !isset($this->source_info['APP1']) || strpos($this->source_info['APP1'], 'Exif') !== 0) { return $img; } try { $exif = @exif_read_data($filename); } catch (Exception $e) { $exif = null; } if (!$exif || !isset($exif['Orientation'])) { return $img; } $orientation = $exif['Orientation']; if ($orientation === 6 || $orientation === 5) { $img = imagerotate($img, 270, 0); } elseif ($orientation === 3 || $orientation === 4) { $img = imagerotate($img, 180, 0); } elseif ($orientation === 8 || $orientation === 7) { $img = imagerotate($img, 90, 0); } if ($orientation === 5 || $orientation === 4 || $orientation === 7) { imageflip($img, IMG_FLIP_HORIZONTAL); } return $img; } /** * Saves new image * * @param string $filename * @param integer $image_type * @param integer $quality * @param integer $permissions * @param boolean $exact_size * @return static */ public function save($filename, $image_type = null, $quality = null, $permissions = null, $exact_size = false) { $image_type = $image_type ?: $this->source_type; $quality = is_numeric($quality) ? (int) abs($quality) : null; switch ($image_type) { case IMAGETYPE_GIF: if( !empty($exact_size) && is_array($exact_size) ){ $dest_image = imagecreatetruecolor($exact_size[0], $exact_size[1]); } else{ $dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight()); } $background = imagecolorallocatealpha($dest_image, 255, 255, 255, 1); imagecolortransparent($dest_image, $background); imagefill($dest_image, 0, 0, $background); imagesavealpha($dest_image, true); break; case IMAGETYPE_JPEG: if( !empty($exact_size) && is_array($exact_size) ){ $dest_image = imagecreatetruecolor($exact_size[0], $exact_size[1]); $background = imagecolorallocate($dest_image, 255, 255, 255); imagefilledrectangle($dest_image, 0, 0, $exact_size[0], $exact_size[1], $background); } else{ $dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight()); $background = imagecolorallocate($dest_image, 255, 255, 255); imagefilledrectangle($dest_image, 0, 0, $this->getDestWidth(), $this->getDestHeight(), $background); } break; case IMAGETYPE_WEBP: if (version_compare(PHP_VERSION, '5.5.0', '<')) { throw new ImageResizeException('For WebP support PHP >= 5.5.0 is required'); } if( !empty($exact_size) && is_array($exact_size) ){ $dest_image = imagecreatetruecolor($exact_size[0], $exact_size[1]); $background = imagecolorallocate($dest_image, 255, 255, 255); imagefilledrectangle($dest_image, 0, 0, $exact_size[0], $exact_size[1], $background); } else{ $dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight()); $background = imagecolorallocate($dest_image, 255, 255, 255); imagefilledrectangle($dest_image, 0, 0, $this->getDestWidth(), $this->getDestHeight(), $background); } imagealphablending($dest_image, false); imagesavealpha($dest_image, true); break; case IMAGETYPE_PNG: if (!$this->quality_truecolor || !imageistruecolor($this->source_image)) { if( !empty($exact_size) && is_array($exact_size) ){ $dest_image = imagecreate($exact_size[0], $exact_size[1]); } else{ $dest_image = imagecreate($this->getDestWidth(), $this->getDestHeight()); } } else { if( !empty($exact_size) && is_array($exact_size) ){ $dest_image = imagecreatetruecolor($exact_size[0], $exact_size[1]); } else{ $dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight()); } } imagealphablending($dest_image, false); imagesavealpha($dest_image, true); $background = imagecolorallocatealpha($dest_image, 255, 255, 255, 127); imagecolortransparent($dest_image, $background); imagefill($dest_image, 0, 0, $background); break; case IMAGETYPE_BMP: if (version_compare(PHP_VERSION, '7.2.0', '<')) { throw new ImageResizeException('For WebP support PHP >= 7.2.0 is required'); } if(!empty($exact_size) && is_array($exact_size)) { $dest_image = imagecreatetruecolor($exact_size[0], $exact_size[1]); $background = imagecolorallocate($dest_image, 255, 255, 255); imagefilledrectangle($dest_image, 0, 0, $exact_size[0], $exact_size[1], $background); } else { $dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight()); $background = imagecolorallocate($dest_image, 255, 255, 255); imagefilledrectangle($dest_image, 0, 0, $this->getDestWidth(), $this->getDestHeight(), $background); } break; } imageinterlace($dest_image, $this->interlace); if ($this->gamma_correct) { imagegammacorrect($this->source_image, 2.2, 1.0); } if( !empty($exact_size) && is_array($exact_size) ) { if ($this->getSourceHeight() < $this->getSourceWidth()) { $this->dest_x = 0; $this->dest_y = ($exact_size[1] - $this->getDestHeight()) / 2; } if ($this->getSourceHeight() > $this->getSourceWidth()) { $this->dest_x = ($exact_size[0] - $this->getDestWidth()) / 2; $this->dest_y = 0; } } imagecopyresampled( $dest_image, $this->source_image, $this->dest_x, $this->dest_y, $this->source_x, $this->source_y, $this->getDestWidth(), $this->getDestHeight(), $this->source_w, $this->source_h ); if ($this->gamma_correct) { imagegammacorrect($dest_image, 1.0, 2.2); } $this->applyFilter($dest_image); switch ($image_type) { case IMAGETYPE_GIF: imagegif($dest_image, $filename); break; case IMAGETYPE_JPEG: if ($quality === null || $quality > 100) { $quality = $this->quality_jpg; } imagejpeg($dest_image, $filename, $quality); break; case IMAGETYPE_WEBP: if (version_compare(PHP_VERSION, '5.5.0', '<')) { throw new ImageResizeException('For WebP support PHP >= 5.5.0 is required'); } if ($quality === null) { $quality = $this->quality_webp; } imagewebp($dest_image, $filename, $quality); break; case IMAGETYPE_PNG: if ($quality === null || $quality > 9) { $quality = $this->quality_png; } imagepng($dest_image, $filename, $quality); break; case IMAGETYPE_BMP: imagebmp($dest_image, $filename, $quality); break; } if ($permissions) { chmod($filename, $permissions); } imagedestroy($dest_image); return $this; } /** * Convert the image to string * * @param int $image_type * @param int $quality * @return string */ public function getImageAsString($image_type = null, $quality = null) { $string_temp = tempnam(sys_get_temp_dir(), ''); $this->save($string_temp, $image_type, $quality); $string = file_get_contents($string_temp); unlink($string_temp); return $string; } /** * Convert the image to string with the current settings * * @return string */ public function __toString() { return $this->getImageAsString(); } /** * Outputs image to browser * @param string $image_type * @param integer $quality */ public function output($image_type = null, $quality = null) { $image_type = $image_type ?: $this->source_type; header('Content-Type: ' . image_type_to_mime_type($image_type)); $this->save(null, $image_type, $quality); } /** * Resizes image according to the given short side (short side proportional) * * @param integer $max_short * @param boolean $allow_enlarge * @return static */ public function resizeToShortSide($max_short, $allow_enlarge = false) { if ($this->getSourceHeight() < $this->getSourceWidth()) { $ratio = $max_short / $this->getSourceHeight(); $long = (int) ($this->getSourceWidth() * $ratio); $this->resize($long, $max_short, $allow_enlarge); } else { $ratio = $max_short / $this->getSourceWidth(); $long = (int) ($this->getSourceHeight() * $ratio); $this->resize($max_short, $long, $allow_enlarge); } return $this; } /** * Resizes image according to the given long side (short side proportional) * * @param integer $max_long * @param boolean $allow_enlarge * @return static */ public function resizeToLongSide($max_long, $allow_enlarge = false) { if ($this->getSourceHeight() > $this->getSourceWidth()) { $ratio = $max_long / $this->getSourceHeight(); $short = (int) ($this->getSourceWidth() * $ratio); $this->resize($short, $max_long, $allow_enlarge); } else { $ratio = $max_long / $this->getSourceWidth(); $short = (int) ($this->getSourceHeight() * $ratio); $this->resize($max_long, $short, $allow_enlarge); } return $this; } /** * Resizes image according to the given height (width proportional) * * @param integer $height * @param boolean $allow_enlarge * @return static */ public function resizeToHeight($height, $allow_enlarge = false) { $ratio = $height / $this->getSourceHeight(); $width = (int) ($this->getSourceWidth() * $ratio); $this->resize($width, $height, $allow_enlarge); return $this; } /** * Resizes image according to the given width (height proportional) * * @param integer $width * @param boolean $allow_enlarge * @return static */ public function resizeToWidth($width, $allow_enlarge = false) { $ratio = $width / $this->getSourceWidth(); $height = (int) ($this->getSourceHeight() * $ratio); $this->resize($width, $height, $allow_enlarge); return $this; } /** * Resizes image to best fit inside the given dimensions * * @param integer $max_width * @param integer $max_height * @param boolean $allow_enlarge * @return static */ public function resizeToBestFit($max_width, $max_height, $allow_enlarge = false) { if ($this->getSourceWidth() <= $max_width && $this->getSourceHeight() <= $max_height && $allow_enlarge === false) { return $this; } $ratio = $this->getSourceHeight() / $this->getSourceWidth(); $width = $max_width; $height = (int) ($width * $ratio); if ($height > $max_height) { $height = $max_height; $width = (int) ($height / $ratio); } return $this->resize($width, $height, $allow_enlarge); } /** * Resizes image according to given scale (proportionally) * * @param integer|float $scale * @return static */ public function scale($scale) { $width = (int) ($this->getSourceWidth() * $scale / 100); $height = (int) ($this->getSourceHeight() * $scale / 100); $this->resize($width, $height, true); return $this; } /** * Resizes image according to the given width and height * * @param integer $width * @param integer $height * @param boolean $allow_enlarge * @return static */ public function resize($width, $height, $allow_enlarge = false) { if (!$allow_enlarge) { // if the user hasn't explicitly allowed enlarging, // but either of the dimensions are larger then the original, // then just use original dimensions - this logic may need rethinking if ($width > $this->getSourceWidth() || $height > $this->getSourceHeight()) { $width = $this->getSourceWidth(); $height = $this->getSourceHeight(); } } $this->source_x = 0; $this->source_y = 0; $this->dest_w = $width; $this->dest_h = $height; $this->source_w = $this->getSourceWidth(); $this->source_h = $this->getSourceHeight(); return $this; } /** * Crops image according to the given width, height and crop position * * @param integer $width * @param integer $height * @param boolean $allow_enlarge * @param integer $position * @return static */ public function crop($width, $height, $allow_enlarge = false, $position = self::CROPCENTER) { if (!$allow_enlarge) { // this logic is slightly different to resize(), // it will only reset dimensions to the original // if that particular dimenstion is larger if ($width > $this->getSourceWidth()) { $width = $this->getSourceWidth(); } if ($height > $this->getSourceHeight()) { $height = $this->getSourceHeight(); } } $ratio_source = $this->getSourceWidth() / $this->getSourceHeight(); $ratio_dest = $width / $height; if ($ratio_dest < $ratio_source) { $this->resizeToHeight($height, $allow_enlarge); $excess_width = (int) (($this->getDestWidth() - $width) * $this->getSourceWidth() / $this->getDestWidth()); $this->source_w = $this->getSourceWidth() - $excess_width; $this->source_x = $this->getCropPosition($excess_width, $position); $this->dest_w = $width; } else { $this->resizeToWidth($width, $allow_enlarge); $excess_height = (int) (($this->getDestHeight() - $height) * $this->getSourceHeight() / $this->getDestHeight()); $this->source_h = $this->getSourceHeight() - $excess_height; $this->source_y = $this->getCropPosition($excess_height, $position); $this->dest_h = $height; } return $this; } /** * Crops image according to the given width, height, x and y * * @param integer $width * @param integer $height * @param integer $x * @param integer $y * @return static */ public function freecrop($width, $height, $x = false, $y = false) { if ($x === false || $y === false) { return $this->crop($width, $height); } $this->source_x = $x; $this->source_y = $y; if ($width > $this->getSourceWidth() - $x) { $this->source_w = $this->getSourceWidth() - $x; } else { $this->source_w = $width; } if ($height > $this->getSourceHeight() - $y) { $this->source_h = $this->getSourceHeight() - $y; } else { $this->source_h = $height; } $this->dest_w = $width; $this->dest_h = $height; return $this; } /** * Gets source width * * @return integer */ public function getSourceWidth() { return $this->original_w; } /** * Gets source height * * @return integer */ public function getSourceHeight() { return $this->original_h; } /** * Gets width of the destination image * * @return integer */ public function getDestWidth() { return $this->dest_w; } /** * Gets height of the destination image * @return integer */ public function getDestHeight() { return $this->dest_h; } /** * Gets crop position (X or Y) according to the given position * * @param integer $expectedSize * @param integer $position * @return integer */ protected function getCropPosition($expectedSize, $position = self::CROPCENTER) { $size = 0; switch ($position) { case self::CROPBOTTOM: case self::CROPRIGHT: $size = $expectedSize; break; case self::CROPCENTER: case self::CROPCENTRE: $size = $expectedSize / 2; break; case self::CROPTOPCENTER: $size = $expectedSize / 4; break; } return (int) $size; } /** * Enable or not the gamma color correction on the image, enabled by default * * @param bool $enable * @return static */ public function gamma($enable = false) { $this->gamma_correct = $enable; return $this; } } PK!!elib/ImageResizeException.phpnu[Gumlet.com is a **free** service which can process images in real-time and serve worldwide through CDN. ------------------ Setup ----- This package is available through Packagist with the vendor and package identifier the same as this repo. If using [Composer](https://getcomposer.org/), in your `composer.json` file add: ```json { "require": { "gumlet/php-image-resize": "2.0.*" } } ``` If you are still using PHP 5.3, please install version ```1.7.0``` and if you are using PHP 5.4, please install version ```1.8.0``` of this library. WebP support is added with PHP `5.6.0` and current version of library supports that. If you are facing issues, please use `1.9.2` version of this library. For PHP versions >= 7.2, `2.0.1` or above version of this library should be used. Otherwise: ```php include '/path/to/ImageResize.php'; ``` Because this class uses namespacing, when instantiating the object, you need to either use the fully qualified namespace: ```php $image = new \Gumlet\ImageResize(); ``` Or alias it: ```php use \Gumlet\ImageResize; $image = new ImageResize(); ``` > Note: This library uses GD class which do not support resizing animated gif files ------------------ Resize ------ To scale an image, in this case to half it's size (scaling is percentage based): ```php $image = new ImageResize('image.jpg'); $image->scale(50); $image->save('image2.jpg'); ``` To resize an image according to one dimension (keeping aspect ratio): ```php $image = new ImageResize('image.jpg'); $image->resizeToHeight(500); $image->save('image2.jpg'); $image = new ImageResize('image.jpg'); $image->resizeToWidth(300); $image->save('image2.jpg'); ``` To resize an image according to a given measure regardingless its orientation (keeping aspect ratio): ```php $image = new ImageResize('image.jpg'); $image->resizeToLongSide(500); $image->save('image2.jpg'); $image = new ImageResize('image.jpg'); $image->resizeToShortSide(300); $image->save('image2.jpg'); ``` To resize an image to best fit a given set of dimensions (keeping aspet ratio): ```php $image = new ImageResize('image.jpg'); $image->resizeToBestFit(500, 300); $image->save('image2.jpg'); ``` All resize functions have ```$allow_enlarge``` option which is set to false by default. You can enable by passing ```true``` to any resize function: ```php $image = new ImageResize('image.jpg'); $image->resize(500, 300, $allow_enlarge = True); $image->save('image2.jpg'); ``` If you are happy to handle aspect ratios yourself, you can resize directly: ```php $image = new ImageResize('image.jpg'); $image->resize(800, 600); $image->save('image2.jpg'); ``` This will cause your image to skew if you do not use the same width/height ratio as the source image. Crop ---- To to crop an image: ```php $image = new ImageResize('image.jpg'); $image->crop(200, 200); $image->save('image2.jpg'); ``` This will scale the image to as close as it can to the passed dimensions, and then crop and center the rest. In the case of the example above, an image of 400px × 600px will be resized down to 200px × 300px, and then 50px will be taken off the top and bottom, leaving you with 200px × 200px. Crop modes: Few crop mode options are available in order for you to choose how you want to handle the eventual exceeding width or height after resizing down your image. The default crop mode used is the `CROPCENTER`. As a result those pieces of code are equivalent: ```php $image = new ImageResize('image.jpg'); $image->crop(200, 200); $image->save('image2.jpg'); ``` ```php $image = new ImageResize('image.jpg'); $image->crop(200, 200, true, ImageResize::CROPCENTER); $image->save('image2.jpg'); ``` In the case you have an image of 400px × 600px and you want to crop it to 200px × 200px the image will be resized down to 200px × 300px, then you can indicate how you want to handle those 100px exceeding passing the value of the crop mode you want to use. For instance passing the crop mode `CROPTOP` will result as 100px taken off the bottom leaving you with 200px × 200px. ```php $image = new ImageResize('image.jpg'); $image->crop(200, 200, true, ImageResize::CROPTOP); $image->save('image2.jpg'); ``` On the contrary passing the crop mode `CROPBOTTOM` will result as 100px taken off the top leaving you with 200px × 200px. ```php $image = new ImageResize('image.jpg'); $image->crop(200, 200, true, ImageResize::CROPBOTTOM); $image->save('image2.jpg'); ``` Freecrop: There is also a way to define custom crop position. You can define $x and $y in ```freecrop``` method: ```php $image = new ImageResize('image.jpg'); $image->freecrop(200, 200, $x = 20, $y = 20); $image->save('image2.jpg'); ``` Loading and saving images from string ------------------------------------- To load an image from a string: ```php $image = ImageResize::createFromString(base64_decode('R0lGODlhAQABAIAAAAQCBP///yH5BAEAAAEALAAAAAABAAEAAAICRAEAOw==')); $image->scale(50); $image->save('image.jpg'); ``` You can also return the result as a string: ```php $image = ImageResize::createFromString(base64_decode('R0lGODlhAQABAIAAAAQCBP///yH5BAEAAAEALAAAAAABAAEAAAICRAEAOw==')); $image->scale(50); echo $image->getImageAsString(); ``` Magic `__toString()` is also supported: ```php $image = ImageResize::createFromString(base64_decode('R0lGODlhAQABAIAAAAQCBP///yH5BAEAAAEALAAAAAABAAEAAAICRAEAOw==')); $image->resize(10, 10); echo (string)$image; ``` Displaying ---------- As seen above, you can call `$image->save('image.jpg');` To render the image directly into the browser, you can call `$image->output()`; Image Types ----------- When saving to disk or outputting into the browser, the script assumes the same output type as input. If you would like to save/output in a different image type, you need to pass a (supported) PHP [`IMAGETYPE_`* constant](http://www.php.net/manual/en/image.constants.php): - `IMAGETYPE_GIF` - `IMAGETYPE_JPEG` - `IMAGETYPE_PNG` This allows you to save in a different type to the source: ```php $image = new ImageResize('image.jpg'); $image->resize(800, 600); $image->save('image.png', IMAGETYPE_PNG); ``` Quality ------- The properties `$quality_jpg`, `$quality_webp` and `$quality_png` are available for you to configure: ```php $image = new ImageResize('image.jpg'); $image->quality_jpg = 100; $image->resize(800, 600); $image->save('image2.jpg'); ``` By default they are set to 85 and 6 respectively. See the manual entries for [`imagejpeg()`](http://www.php.net/manual/en/function.imagejpeg.php) and [`imagepng()`](http://www.php.net/manual/en/function.imagepng.php) for more info. You can also pass the quality directly to the `save()`, `output()` and `getImageAsString()` methods: ```php $image = new ImageResize('image.jpg'); $image->crop(200, 200); $image->save('image2.jpg', null, 100); $image = new ImageResize('image.jpg'); $image->resizeToWidth(300); $image->output(IMAGETYPE_PNG, 4); $image = new ImageResize('image.jpg'); $image->scale(50); $result = $image->getImageAsString(IMAGETYPE_PNG, 4); ``` We're passing `null` for the image type in the example above to skip over it and provide the quality. In this case, the image type is assumed to be the same as the input. Interlacing ----------- By default, [image interlacing](http://php.net/manual/en/function.imageinterlace.php) is turned on. It can be disabled by setting `$interlace` to `0`: ```php $image = new ImageResize('image.jpg'); $image->scale(50); $image->interlace = 0; $image->save('image2.jpg'); ``` Chaining -------- When performing operations, the original image is retained, so that you can chain operations without excessive destruction. This is useful for creating multiple sizes: ```php $image = new ImageResize('image.jpg'); $image ->scale(50) ->save('image2.jpg') ->resizeToWidth(300) ->save('image3.jpg') ->crop(100, 100) ->save('image4.jpg') ; ``` Exceptions -------- ImageResize throws ImageResizeException for it's own for errors. You can catch that or catch the general \Exception which it's extending. It is not to be expected, but should anything go horribly wrong mid way then notice or warning Errors could be shown from the PHP GD and Image Functions (http://php.net/manual/en/ref.image.php) ```php try{ $image = new ImageResize(null); echo "This line will not be printed"; } catch (ImageResizeException $e) { echo "Something went wrong" . $e->getMessage(); } ``` Filters -------- You can apply special effects for new image like blur or add banner. ```php $image = new ImageResize('image.jpg'); // Add blure $image->addFilter(function ($imageDesc) { imagefilter($imageDesc, IMG_FILTER_GAUSSIAN_BLUR); }); // Add banner on bottom left corner $image18Plus = 'banner.png' $image->addFilter(function ($imageDesc) use ($image18Plus) { $logo = imagecreatefrompng($image18Plus); $logo_width = imagesx($logo); $logo_height = imagesy($logo); $image_width = imagesx($imageDesc); $image_height = imagesy($imageDesc); $image_x = $image_width - $logo_width - 10; $image_y = $image_height - $logo_height - 10; imagecopy($imageDesc, $logo, $image_x, $image_y, 0, 0, $logo_width, $logo_height); }); ``` Flip -------- Flips an image using a given mode and this method is only for PHP version 5.4. ```php $flip = new ImageResize('image.png'); $image = imagecreatetruecolor(200, 100); $flip->imageFlip($image, 0); ``` Both functions will be used in the order in which they were added. Gamma color correction -------- You can enable the gamma color correction which is disabled by default. ```php $image = new ImageResize('image.png'); $image->gamma(true); ``` API Doc ------- https://gumlet.github.io/php-image-resize/index.html ------------------ Maintainer ---------- This library is maintained by Gumlet.com [](https://www.gumlet.com) PK!=55 Licence.mdnu[MIT License Copyright (c) 2018 Turing Analytics LLP 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. PK!XX!.github/workflows/php-testing.ymlnu[name: PHP CI on: ["push", "pull_request"] jobs: run: runs-on: ${{ matrix.operating-system }} strategy: fail-fast: false matrix: operating-system: [ubuntu-20.04] php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1'] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} steps: - name: Checkout uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} extensions: gd, xdebug, fileinfo coverage: xdebug tools: php-cs-fixer, phpunit - name: Composer Install run: composer install --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist - name: Running Tests run: | mkdir -p build/logs ./vendor/bin/phpunit PK!{!test/ImageResizeExceptionTest.phpnu[assertEquals("", $e->getMessage()); $this->assertInstanceOf('\Gumlet\ImageResizeException', $e); } public function testExceptionMessage() { $e = new ImageResizeException("General error"); $this->assertEquals("General error", $e->getMessage()); $this->assertInstanceOf('\Gumlet\ImageResizeException', $e); } public function testExceptionExtending() { $e = new ImageResizeException("General error"); $this->assertInstanceOf('\Exception', $e); } public function testExceptionThrown() { try{ throw new ImageResizeException("General error"); } catch (\Exception $e) { $this->assertEquals("General error", $e->getMessage()); $this->assertInstanceOf('\Gumlet\ImageResizeException', $e); return; } $this->fail(); } } // It's pretty easy to get your attention these days, isn't it? :D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@J$ĉB&|Va\J\buq^q9|875_-:Whp8B% Pܐk͈c4)`ousms-WE5zvߊ[}=Qj暑 t7tH JwD8{u%/t~=DQ.F7ފ:`%yawV.u!ؐ%"g:CkĶsC!5\Fh:Q!$qǒӥ7"Wb3^4,HQP"o\Uw01X1p;3imtðb&mZVQD`O**JW l ~q)R>ޕ3XOd'*F+qW-vE?Ǭ}8}fnmEHVLqpRN4EpBv̮MEW80FMx*yvɵ↹&PcIT +ڽwгX}:8)e_|E^kľoPRM31eSavLHݔ](t-xnya|%p`2 @]7WX8 a/E̻{zãn8^M(rs^(`] 1!xPTYoc7?+d{B!Voc0t&_ԃ$W)I(Ý)mۛ06ENXZN Adobe Fireworks CS3 2017-06-19T11:25:05Z 2017-06-19T11:25:38Z image/jpeg Test Test Test Test Test Test C    ! ''**''555556666666666C &&,$ $,(+&&&+(//,,//666666666666666d ?PK!ΓgZ8Z8test/ImageResizeTest.phpnu[createImage(1, 1, 'gif'); $resize = new ImageResize($image); $this->assertEquals(IMAGETYPE_GIF, $resize->source_type); $this->assertInstanceOf('\Gumlet\ImageResize', $resize); } public function testLoadJpg() { $image = $this->createImage(1, 1, 'jpeg'); $resize = new ImageResize($image); $this->assertEquals(IMAGETYPE_JPEG, $resize->source_type); $this->assertInstanceOf('\Gumlet\ImageResize', $resize); } public function testLoadIgnoreXmpExifJpg() { $image = __DIR__.'/ressources/test_xmp.jpg'; $resize = new ImageResize($image); $this->assertEquals(IMAGETYPE_JPEG, $resize->source_type); $this->assertInstanceOf('\Gumlet\ImageResize', $resize); } public function testLoadPng() { $image = $this->createImage(1, 1, 'png'); $resize = new ImageResize($image); $this->assertEquals(IMAGETYPE_PNG, $resize->source_type); $this->assertInstanceOf('\Gumlet\ImageResize', $resize); } public function testLoadWebp() { $image = __DIR__ . '/ressources/test_webp.webp'; $resize = new ImageResize($image); $this->assertEquals(IMAGETYPE_WEBP, $resize->source_type); $this->assertInstanceOf('\Gumlet\ImageResize', $resize); } public function testLoadBmp() { $image = __DIR__ . '/ressources/test_bmp.bmp'; $resize = new ImageResize($image); $this->assertEquals(IMAGETYPE_BMP, $resize->source_type); $this->assertInstanceOf('\Gumlet\ImageResize', $resize); } public function testLoadString() { $resize = ImageResize::createFromString(base64_decode($this->image_string)); $this->assertEquals(IMAGETYPE_GIF, $resize->source_type); $this->assertInstanceOf('\Gumlet\ImageResize', $resize); } public function testLoadRfc2397() { $resize = new ImageResize($this->data_url); $this->assertEquals(IMAGETYPE_GIF, $resize->source_type); $this->assertInstanceOf('\Gumlet\ImageResize', $resize); } public function testAddFilter() { $image = $this->createImage(1, 1, 'png'); $resize = new ImageResize($image); $filename = $this->getTempFile(); $this->assertInstanceOf('\Gumlet\ImageResize', $resize->addFilter('imagefilter')); } public function testApplyFilter() { $image = $this->createImage(1, 1, 'png'); $resize = new ImageResize($image); $resize->addFilter('imagefilter'); $filename = $this->getTempFile(); $this->assertInstanceOf('\Gumlet\ImageResize', $resize->save($filename)); } /** * Bad load tests */ public function testLoadNoFile() { $this->expectException(ImageResizeException::class); $this->expectExceptionMessage('File does not exist'); new ImageResize(null); } public function testLoadUnsupportedFile() { $this->expectException(ImageResizeException::class); $this->expectExceptionMessage('Unsupported file type'); new ImageResize(__FILE__); } public function testLoadUnsupportedFileString() { $this->expectException(ImageResizeException::class); $this->expectExceptionMessage('image_data must not be empty'); ImageResize::createFromString(''); } public function testLoadUnsupportedImage() { $this->expectException(ImageResizeException::class); $this->expectExceptionMessage('Unsupported image type'); $filename = $this->getTempFile(); $image = fopen($filename, 'w'); fwrite($image, base64_decode($this->unsupported_image)); fclose($image); new ImageResize($filename); } public function testInvalidString() { $this->expectException(ImageResizeException::class); $this->expectExceptionMessage('Unsupported image type'); ImageResize::createFromString(base64_decode($this->unsupported_image)); } /** * Resize tests */ public function testResizeToLongSide() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->resizeToLongSide(100); $this->assertEquals(100, $resize->getDestWidth()); $this->assertEquals(50, $resize->getDestHeight()); } public function testResizeToLongSideVertical() { $image = $this->createImage(100, 200, 'png'); $resize = new ImageResize($image); $resize->resizeToLongSide(100); $this->assertEquals(50, $resize->getDestWidth()); $this->assertEquals(100, $resize->getDestHeight()); } public function testResizeToShortSide() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->resizeToShortSide(50); $this->assertEquals(100, $resize->getDestWidth()); $this->assertEquals(50, $resize->getDestHeight()); } public function testResizeToShortSideVertical() { $image = $this->createImage(100, 200, 'png'); $resize = new ImageResize($image); $resize->resizeToShortSide(50); $this->assertEquals(50, $resize->getDestWidth()); $this->assertEquals(100, $resize->getDestHeight()); } public function testResizeToHeight() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->resizeToHeight(50); $this->assertEquals(100, $resize->getDestWidth()); $this->assertEquals(50, $resize->getDestHeight()); } public function testResizeToWidth() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->resizeToWidth(100); $this->assertEquals(100, $resize->getDestWidth()); $this->assertEquals(50, $resize->getDestHeight()); } public function testResizeToBestFit() { $image = $this->createImage(200, 500, 'png'); $resize = new ImageResize($image); $resize->resizeToBestFit(100, 100); $this->assertEquals(40, $resize->getDestWidth()); $this->assertEquals(100, $resize->getDestHeight()); } public function testResizeToBestFitNoEnlarge() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->resizeToBestFit(250, 250); $this->assertEquals(200, $resize->getDestWidth()); $this->assertEquals(100, $resize->getDestHeight()); } public function testScale() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->scale(50); $this->assertEquals(100, $resize->getDestWidth()); $this->assertEquals(50, $resize->getDestHeight()); } public function testResize() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->resize(50, 50); $this->assertEquals(50, $resize->getDestWidth()); $this->assertEquals(50, $resize->getDestHeight()); } public function testResizeLargerNotAllowed() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->resize(400, 200); $this->assertEquals(200, $resize->getDestWidth()); $this->assertEquals(100, $resize->getDestHeight()); } /** * Crop tests */ public function testCrop() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->crop(50, 50); $this->assertEquals(50, $resize->getDestWidth()); $this->assertEquals(50, $resize->getDestHeight()); } public function testFreeCrop() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->freecrop(50, 50 , $x = 20, $y = 20); $this->assertEquals(50, $resize->getDestWidth()); $this->assertEquals(50, $resize->getDestHeight()); $resize->freecrop(50, 50); $this->assertEquals(50, $resize->getDestWidth()); $this->assertEquals(50, $resize->getDestHeight()); $resize->freecrop(300, 300, 1, 1); $this->assertEquals(300, $resize->getDestWidth()); $this->assertEquals(300, $resize->getDestHeight()); } public function testCropPosition() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->crop(50, 50, false, $resize::CROPRIGHT); $reflection_class = new ReflectionClass('\Gumlet\ImageResize'); $source_x = $reflection_class->getProperty('source_x'); $source_x->setAccessible(true); $this->assertEquals(100, $source_x->getValue($resize)); $resize->crop(50, 50, false, $resize::CROPCENTRE); $reflection_class = new ReflectionClass('\Gumlet\ImageResize'); $source_x = $reflection_class->getProperty('source_x'); $source_x->setAccessible(true); $this->assertEquals(50, $source_x->getValue($resize)); $resize->crop(50, 50, false, $resize::CROPTOPCENTER); $reflection_class = new ReflectionClass('\Gumlet\ImageResize'); $source_x = $reflection_class->getProperty('source_x'); $source_x->setAccessible(true); $this->assertEquals(25, $source_x->getValue($resize)); } public function testCropLargerNotAllowed() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $resize->crop(500, 500); $this->assertEquals(200, $resize->getDestWidth()); $this->assertEquals(100, $resize->getDestHeight()); } /** * Save tests */ public function testSaveGif() { $image = $this->createImage(200, 100, 'gif'); $resize = new ImageResize($image); $filename = $this->getTempFile(); $resize->save($filename); $this->assertEquals(IMAGETYPE_GIF, exif_imagetype($filename)); } public function testSaveJpg() { $image = $this->createImage(200, 100, 'jpeg'); $resize = new ImageResize($image); $filename = $this->getTempFile(); $resize->save($filename); $this->assertEquals(IMAGETYPE_JPEG, exif_imagetype($filename)); } public function testSavePng() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $filename = $this->getTempFile(); $resize->save($filename); $this->assertEquals(IMAGETYPE_PNG, exif_imagetype($filename)); } public function testSaveBmp() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $filename = $this->getTempFile(); $resize->save($filename, IMAGETYPE_BMP); $this->assertEquals(IMAGETYPE_BMP, exif_imagetype($filename)); } public function testSaveChmod() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); $filename = $this->getTempFile(); $resize->save($filename, null, null, 0600); $this->assertEquals(600, substr(decoct(fileperms($filename)), 3)); } /** * String test */ public function testGetImageAsString() { $resize = ImageResize::createFromString(base64_decode($this->image_string)); $image = $resize->getImageAsString(); $this->assertEquals(43, strlen($image)); } public function testToString() { $resize = ImageResize::createFromString(base64_decode($this->image_string)); $image = (string)$resize; $this->assertEquals(43, strlen($image)); } /** * Output tests */ public function testOutputGif() { $image = $this->createImage(200, 100, 'gif'); $resize = new ImageResize($image); ob_start(); // supressing header errors @$resize->output(); $image_contents = ob_get_clean(); $info = finfo_open(); $type = finfo_buffer($info, $image_contents, FILEINFO_MIME_TYPE); $this->assertEquals('image/gif', $type); } public function testOutputJpg() { $image = $this->createImage(200, 100, 'jpeg'); $resize = new ImageResize($image); ob_start(); // supressing header errors @$resize->output(); $image_contents = ob_get_clean(); $info = finfo_open(); $type = finfo_buffer($info, $image_contents, FILEINFO_MIME_TYPE); $this->assertEquals('image/jpeg', $type); } public function testOutputPng() { $image = $this->createImage(200, 100, 'png'); $resize = new ImageResize($image); ob_start(); // supressing header errors @$resize->output(); $image_contents = ob_get_clean(); $info = finfo_open(); $type = finfo_buffer($info, $image_contents, FILEINFO_MIME_TYPE); $this->assertEquals('image/png', $type); } /** * Helpers */ private function createImage($width, $height, $type) { if (!in_array($type, $this->image_types)) { throw new ImageResizeException('Unsupported image type'); } $image = imagecreatetruecolor($width, $height); $filename = $this->getTempFile(); $output_function = 'image' . $type; $output_function($image, $filename); return $filename; } private function getTempFile() { return tempnam(sys_get_temp_dir(), 'resize_test_image'); } } PK!@ phpunit.xmlnu[ test lib PK!}ȉ8 .gitignorenu[PK!g" Tcomposer.jsonnu[PK!g=[[Dlib/ImageResize.phpnu[PK!!eM`lib/ImageResizeException.phpnu[PK!;)*)* aREADME.mdnu[PK!=55 ~Licence.mdnu[PK!XX!.github/workflows/php-testing.ymlnu[PK!{!test/ImageResizeExceptionTest.phpnu[PK!?ztest/ressources/test_bmp.bmpnu[PK!v_pvpvttest/ressources/test_webp.webpnu[PK!@R[]7]72test/ressources/test_xmp.jpgnu[PK!ΓgZ8Z8Gtest/ImageResizeTest.phpnu[PK!@ }phpunit.xmlnu[PK T