{"id":13398231,"url":"https://github.com/claviska/SimpleImage","last_synced_at":"2025-03-14T02:30:52.308Z","repository":{"id":1860093,"uuid":"2785023","full_name":"claviska/SimpleImage","owner":"claviska","description":"A PHP class that makes working with images and GD as simple as possible.","archived":false,"fork":false,"pushed_at":"2024-04-15T16:08:13.000Z","size":2448,"stargazers_count":1380,"open_issues_count":20,"forks_count":383,"subscribers_count":76,"default_branch":"master","last_synced_at":"2024-10-29T15:00:35.220Z","etag":null,"topics":["gd","image-processing","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"eligrey/FileSaver.js","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/claviska.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["claviska"]}},"created_at":"2011-11-16T02:21:47.000Z","updated_at":"2024-09-13T14:46:24.000Z","dependencies_parsed_at":"2023-07-06T09:16:16.124Z","dependency_job_id":"88fe9dac-0fb0-4115-9587-7ed88a31c685","html_url":"https://github.com/claviska/SimpleImage","commit_stats":{"total_commits":253,"total_committers":34,"mean_commits":"7.4411764705882355","dds":"0.35573122529644263","last_synced_commit":"226d507cca0c8400d69bee7eb324158e3cbe246e"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/claviska%2FSimpleImage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/claviska%2FSimpleImage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/claviska%2FSimpleImage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/claviska%2FSimpleImage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/claviska","download_url":"https://codeload.github.com/claviska/SimpleImage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243335390,"owners_count":20274899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gd","image-processing","php"],"created_at":"2024-07-30T19:00:20.643Z","updated_at":"2025-03-14T02:30:52.278Z","avatar_url":"https://github.com/claviska.png","language":"PHP","readme":"# SimpleImage\n\nA PHP class that makes working with images as simple as possible.\n\nDeveloped and maintained by [Cory LaViska](https://github.com/claviska).\n\n_If this project has you loving PHP image manipulation again, please consider [sponsoring me](https://github.com/sponsors/claviska) to support its development._\n\n---\n\n## Overview\n\n```php\n\u003c?php\ntry {\n  // Create a new SimpleImage object\n  $image = new \\claviska\\SimpleImage();\n\n  // Magic! ✨\n  $image\n    -\u003efromFile('image.jpg')                     // load image.jpg\n    -\u003eautoOrient()                              // adjust orientation based on exif data\n    -\u003eresize(320, 200)                          // resize to 320x200 pixels\n    -\u003eflip('x')                                 // flip horizontally\n    -\u003ecolorize('DarkBlue')                      // tint dark blue\n    -\u003eborder('black', 10)                       // add a 10 pixel black border\n    -\u003eoverlay('watermark.png', 'bottom right')  // add a watermark image\n    -\u003etoFile('new-image.png', 'image/png')      // convert to PNG and save a copy to new-image.png\n    -\u003etoScreen();                               // output to the screen\n\n  // And much more! 💪\n} catch(Exception $err) {\n  // Handle errors\n  echo $err-\u003egetMessage();\n}\n```\n\n## Requirements\n\n- PHP 8.0+\n- [GD extension](http://php.net/manual/en/book.image.php)\n\n## Features\n\n- Supports reading, writing, and converting GIF, JPEG, PNG, WEBP, BMP, AVIF formats.\n- Reads and writes files, data URIs, and image strings.\n- Manipulation: crop, resize, overlay/watermark, adding TTF text\n- Drawing: arc, border, dot, ellipse, line, polygon, rectangle, rounded rectangle\n- Filters: blur, brighten, colorize, contrast, darken, desaturate, edge detect, emboss, invert, opacity, pixelate, sepia, sharpen, sketch\n- Utilities: color adjustment, darken/lighten color, extract colors\n- Properties: exif data, height/width, mime type, orientation\n- Color arguments can be passed in as any CSS color (e.g. `LightBlue`), a hex color, or an RGB(A) array.\n- Support for alpha-transparency (GIF, PNG, WEBP, AVIF)\n- Chainable methods\n- Uses exceptions\n- Load with Composer or manually (just one file)\n- [Semantic Versioning](http://semver.org/)\n\n## Installation\n\nInstall with Composer:\n\n```\ncomposer require claviska/simpleimage\n```\n\nOr include the library manually:\n\n```php\n\u003c?php\nrequire 'src/claviska/SimpleImage.php';\n```\n\n## About\n\nSimpleImage is developed and maintained by [Cory LaViska](https://github.com/claviska). Copyright A Beautiful Site, LLC.\n\nIf you enjoy using SimpleImage, especially in commercial applications, please consider [sponsoring me](https://github.com/sponsors/claviska) to support its development.\n\nThanks! 🙌\n\n## License\n\nLicensed under the [MIT license](http://opensource.org/licenses/MIT).\n\n## API\n\nOrder of awesomeness:\n\n1. Load an image\n2. Manipulate the image\n3. Save/output the image\n\nAPI tips:\n\n- An asterisk denotes a required argument.\n- Methods that return a SimpleImage object are chainable.\n- You can pass a file or data URI to the constructor to avoid calling `fromFile` or `fromDataUri`.\n- Static methods can be called with `$image::methodName()` or `\\claviska\\SimpleImage::methodName()`.\n- Colors can be a CSS color (e.g. `white`), a hex string (e.g. '#ffffff'), or an RGBA array.\n- You can pipe transparency to `normalizeColor` when you pass a CSS color or hex string: `white|0.25`\n\n### Loaders\n\n#### `fromDataUri($uri)`\n\nLoads an image from a data URI.\n\n- `$uri`* (string) - A data URI.\n\nReturns a SimpleImage object.\n\n#### `fromFile($file)`\n\nLoads an image from a file.\n\n- `$file`* (string) - The image file to load.\n\nReturns a SimpleImage object.\n\n#### `fromNew($width, $height, $color)`\n\nCreates a new image.\n\n- `$width`* (int) - The width of the image.\n- `$height`* (int) - The height of the image.\n- `$color` (string|array) - Optional fill color for the new image (default 'transparent').\n\nReturns a SimpleImage object.\n\n#### `fromString($string)`\n\nCreates a new image from a string.\n\n- `$string`* (string) - The raw image data as a string. Example:\n  ```\n  $string = file_get_contents('image.jpg');\n  ```\n\nReturns a SimpleImage object.\n\n### Savers\n\n#### `toDataUri($mimeType, $options)`\n\nGenerates a data URI.\n\n- `$mimeType` (string) - The image format to output as a mime type (defaults to the original mime type).\n- `$options` (array|int) - Array of options or Image quality as a percentage (default 100).\n\nReturns a string containing a data URI.\n\n#### `toDownload($filename, $mimeType, $options)`\n\nForces the image to be downloaded to the clients machine. Must be called before any output is sent to the screen.\n\n- `$filename`* (string) - The filename (without path) to send to the client (e.g. 'image.jpeg').\n- `$mimeType` (string) - The image format to output as a mime type (defaults to the original mime type).\n- `$options` (array|int) - Array of options or Image quality as a percentage (default 100).\n\nReturns a SimpleImage object.\n\n#### `toFile($file, $mimeType, $options)`\n\nWrites the image to a file.\n\n- `$mimeType` (string) - The image format to output as a mime type (defaults to the original mime type).\n- `$options` (array|int) - Array of options or Image quality as a percentage (default 100).\n\nReturns a SimpleImage object.\n\n#### `toScreen($mimeType, $options)`\n\nOutputs the image to the screen. Must be called before any output is sent to the screen.\n\n- `$mimeType` (string) - The image format to output as a mime type (defaults to the original mime type).\n- `$options` (array|int) - Array of options or Image quality as a percentage (default 100).\n\nReturns a SimpleImage object.\n\n#### `toString($mimeType, $options)`\n\nGenerates an image string.\n\n- `$mimeType` (string) - The image format to output as a mime type (defaults to the original mime type).\n- `$options` (array|int) - Array of options or Image quality as a percentage (default 100).\n\nReturns a SimpleImage object.\n\n#### `generate($mimeType, $options)`\n\nGenerates an image.\n\n- `$mimeType` (string) - The image format to output as a mime type (defaults to the original mime type).\n- `$options` (array|int) - Array of options or Image quality as a percentage (default 100).\n\nReturns an array: [mimeType, data]\n\n#### Options array\n\nInstead of providing the quality as an integer as the last function parameter you can also set various options depending on the targeted Mime type using an associative array.\n\n```php\n$image-\u003etoFile($file, 'image/avif', [\n    // JPG, WEBP, AVIF (default 100)\n    'quality' =\u003e 100,\n\n    // AVIF (default -1 which is 6)\n    // range of slow and small file 0 to 10 fast but big file\n    'speed' =\u003e -1,\n]);\n```\n\n```php\n$image-\u003etoFile($file, 'image/bmp', [\n    // BMP: boolean (default true)\n    'compression' =\u003e true,\n\n    // BMP, JPG (default null, keep the same)\n    'interlace' =\u003e null,\n]);\n```\n\n```php\n$image-\u003etoFile($file, 'image/gif', [\n    // GIF, PNG (default true)\n    'alpha' =\u003e true,\n]);\n```\n\n```php\n$image-\u003etoFile($file, 'image/jpeg', [\n    // BMP, JPG (default null, keep the same)\n    'interlace' =\u003e null,\n\n    // JPG, WEBP, AVIF (default 100)\n    'quality' =\u003e 100,\n]);\n```\n\n```php\n$image-\u003etoFile($file, 'image/png', [\n    // GIF, PNG (default true)\n    'alpha' =\u003e true,\n\n    // PNG: 0-10, defaults to zlib (default 6)\n    'compression' =\u003e -1,\n\n    // PNG (default -1)\n    'filters' =\u003e -1,\n\n    // has no effect on PNG images, since the format is lossless\n    // 'quality' =\u003e 100,\n]);\n```\n\n```php\n$image-\u003etoFile($file, 'image/webp', [\n    // JPG, WEBP, AVIF (default 100)\n    'quality' =\u003e 100,\n]);\n```\n\n### Utilities\n\n#### `getAspectRatio()`\n\nGets the image's current aspect ratio.\n\nReturns the aspect ratio as a float.\n\n#### `getExif()`\n\nGets the image's exif data.\n\nReturns an array of exif data or null if no data is available.\n\n#### `getHeight()`\n\nGets the image's current height.\n\nReturns the height as an integer.\n\n#### `getMimeType()`\n\nGets the mime type of the loaded image.\n\nReturns a mime type string.\n\n#### `getOrientation()`\n\nGets the image's current orientation.\n\nReturns a string: 'landscape', 'portrait', or 'square'\n\n#### `getResolution()`\n\nGets the image's current resolution in DPI.\n\nReturns an array of integers: [0 =\u003e 96, 1 =\u003e 96]\n\n#### `getWidth()`\n\nGets the image's current width.\n\nReturns the width as an integer.\n\n#### `hasImage()`\n\nChecks if the SimpleImage object has loaded an image.\n\nReturns a boolean.\n\n#### `reset()`\n\nDestroys the image resource.\n\nReturns a SimpleImage object.\n\n### Manipulation\n\n#### `autoOrient()`\n\nRotates an image so the orientation will be correct based on its exif data. It is safe to call this method on images that don't have exif data (no changes will be made).\nReturns a SimpleImage object.\n\n#### `bestFit($maxWidth, $maxHeight)`\n\nProportionally resize the image to fit inside a specific width and height.\n\n- `$maxWidth`* (int) - The maximum width the image can be.\n- `$maxHeight`* (int) - The maximum height the image can be.\n\nReturns a SimpleImage object.\n\n#### `crop($x1, $y1, $x2, $y2)`\n\nCrop the image.\n\n- $x1 - Top left x coordinate.\n- $y1 - Top left y coordinate.\n- $x2 - Bottom right x coordinate.\n- $y2 - Bottom right x coordinate.\n\nReturns a SimpleImage object.\n\n#### `fitToHeight($height)` (DEPRECATED)\n\nProportionally resize the image to a specific height.\n\n_This method was deprecated in version 3.2.2 and will be removed in version 4.0. Please use `resize(null, $height)` instead._\n\n- `$height`* (int) - The height to resize the image to.\n\nReturns a SimpleImage object.\n\n#### `fitToWidth($width)`  (DEPRECATED)\n\nProportionally resize the image to a specific width.\n\n_This method was deprecated in version 3.2.2 and will be removed in version 4.0. Please use `resize($width, null)` instead._\n\n- `$width`* (int) - The width to resize the image to.\n\nReturns a SimpleImage object.\n\n#### `flip($direction)`\n\nFlip the image horizontally or vertically.\n\n- `$direction`* (string) - The direction to flip: x|y|both\n\nReturns a SimpleImage object.\n\n#### `maxColors($max, $dither)`\n\nReduces the image to a maximum number of colors.\n\n- `$max`* (int) - The maximum number of colors to use.\n- `$dither` (bool) - Whether or not to use a dithering effect (default true).\n\nReturns a SimpleImage object.\n\n#### `overlay($overlay, $anchor, $opacity, $xOffset, $yOffset)`\n\nPlace an image on top of the current image.\n\n- `$overlay`* (string|SimpleImage) - The image to overlay. This can be a filename, a data URI, or a SimpleImage object.\n- `$anchor` (string) - The anchor point: 'center', 'top', 'bottom', 'left', 'right', 'top left', 'top right', 'bottom left', 'bottom right' (default 'center')\n- `$opacity` (float) - The opacity level of the overlay 0-1 (default 1).\n- `$xOffset` (int) - Horizontal offset in pixels (default 0).\n- `$yOffset` (int) - Vertical offset in pixels (default 0).\n- `$calculateOffsetFromEdge` (bool) - Calculate Offset referring to the edges of the image. $xOffset and $yOffset have no effect in center anchor. (default false).\n\nReturns a SimpleImage object.\n\n#### `resize($width, $height)`\n\nResize an image to the specified dimensions. If only one dimension is specified, the image will be resized proportionally.\n\n- `$width`* (int) - The new image width.\n- `$height`* (int) - The new image height.\n\nReturns a SimpleImage object.\n\n#### `resolution($res_x, $res_y)`\n\nChanges the resolution (DPI) of an image.\n\n- `$res_x`* (int) - The horizontal resolution, in DPI.\n- `$res_y` (int) - The vertical resolution, in DPI.\n\nReturns a SimpleImage object.\n\n#### `rotate($angle, $backgroundColor)`\n\nRotates the image.\n\n- `$angle`* (int) - The angle of rotation (-360 - 360).\n- `$backgroundColor` (string|array) - The background color to use for the uncovered zone area after rotation (default 'transparent').\n\nReturns a SimpleImage object.\n\n#### `text($text, $options, \u0026$boundary)`\n\nAdds text to the image.\n\n- `$text*` (string) - The desired text.\n- `$options` (array) - An array of options.\n  - `fontFile`* (string) - The TrueType (or compatible) font file to use.\n  - `size` (int) - The size of the font in pixels (default 12).\n  - `color` (string|array) - The text color (default black).\n  - `anchor` (string) - The anchor point: 'center', 'top', 'bottom', 'left', 'right',\n    'top left', 'top right', 'bottom left', 'bottom right' (default 'center').\n  - `xOffset` (int) - The horizontal offset in pixels (default 0).\n  - `yOffset` (int) - The vertical offset in pixels (default 0).\n  - `shadow` (array) - Text shadow params.\n      - `x`* (int) - Horizontal offset in pixels.\n      - `y`* (int) - Vertical offset in pixels.\n      - `color`* (string|array) - The text shadow color.\n  - `calculateOffsetFromEdge` (bool) - Calculate Offset referring to the edges of the image (default false).\n  - `baselineAlign` (bool) - Align the text font with the baseline. (default true).\n- `$boundary` (array) - If passed, this variable will contain an array with coordinates that\n  surround the text: [x1, y1, x2, y2, width, height]. This can be used for calculating the\n  text's position after it gets added to the image.\n\nReturns a SimpleImage object.\n\n#### `thumbnail($width, $height, $anchor)`\n\nCreates a thumbnail image. This function attempts to get the image as close to the provided dimensions as possible, then crops the remaining overflow to force the desired size. Useful for generating thumbnail images.\n\n- `$width`* (int) - The thumbnail width.\n- `$height`* (int) - The thumbnail height.\n- `$anchor` (string) - The anchor point: 'center', 'top', 'bottom', 'left', 'right', 'top left', 'top right', 'bottom left', 'bottom right' (default 'center').\n\nReturns a SimpleImage object.\n\n###  Drawing\n\n#### `arc($x, $y, $width, $height, $start, $end, $color, $thickness)`\n\nDraws an arc.\n\n- `$x`* (int) - The x coordinate of the arc's center.\n- `$y`* (int) - The y coordinate of the arc's center.\n- `$width`* (int) - The width of the arc.\n- `$height`* (int) - The height of the arc.\n- `$start`* (int) - The start of the arc in degrees.\n- `$end`* (int) - The end of the arc in degrees.\n- `$color`* (string|array) - The arc color.\n- `$thickness` (int|string) - Line thickness in pixels or 'filled' (default 1).\n\nReturns a SimpleImage object.\n\n#### `border($color, $thickness)`\n\nDraws a border around the image.\n\n- `$color`* (string|array) - The border color.\n- `$thickness` (int) - The thickness of the border (default 1).\n\nReturns a SimpleImage object.\n\n#### `dot($x, $y, $color)`\n\nDraws a single pixel dot.\n\n- `$x`* (int) - The x coordinate of the dot.\n- `$y`* (int) - The y coordinate of the dot.\n- `$color`* (string|array) - The dot color.\n\nReturns a SimpleImage object.\n\n#### `ellipse($x, $y, $width, $height, $color, $thickness)`\n\nDraws an ellipse.\n\n- `$x`* (int) - The x coordinate of the center.\n- `$y`* (int) - The y coordinate of the center.\n- `$width`* (int) - The ellipse width.\n- `$height`* (int) - The ellipse height.\n- `$color`* (string|array) - The ellipse color.\n- `$thickness` (int|string) - Line thickness in pixels or 'filled' (default 1).\n\nReturns a SimpleImage object.\n\n#### `fill($color)`\n\nFills the image with a solid color.\n\n- `$color` (string|array) - The fill color.\n\nReturns a SimpleImage object.\n\n#### `line($x1, $y1, $x2, $y2, $color, $thickness)`\n\nDraws a line.\n\n- `$x1`* (int) - The x coordinate for the first point.\n- `$y1`* (int) - The y coordinate for the first point.\n- `$x2`* (int) - The x coordinate for the second point.\n- `$y2`* (int) - The y coordinate for the second point.\n- `$color` (string|array) - The line color.\n- `$thickness` (int) - The line thickness (default 1).\n\nReturns a SimpleImage object.\n\n#### `polygon($vertices, $color, $thickness)`\n\nDraws a polygon.\n\n- `$vertices`* (array) - The polygon's vertices in an array of x/y arrays. Example:\n  ```\n  [\n    ['x' =\u003e x1, 'y' =\u003e y1],\n    ['x' =\u003e x2, 'y' =\u003e y2],\n    ['x' =\u003e xN, 'y' =\u003e yN]\n  ]\n  ```\n- `$color`* (string|array) - The polygon color.\n- `$thickness` (int|string) - Line thickness in pixels or 'filled' (default 1).\n\nReturns a SimpleImage object.\n\n#### `rectangle($x1, $y1, $x2, $y2, $color, $thickness)`\n\nDraws a rectangle.\n\n- `$x1`* (int) - The upper left x coordinate.\n- `$y1`* (int) - The upper left y coordinate.\n- `$x2`* (int) - The bottom right x coordinate.\n- `$y2`* (int) - The bottom right y coordinate.\n- `$color`* (string|array) - The rectangle color.\n- `$thickness` (int|string) - Line thickness in pixels or 'filled' (default 1).\n\nReturns a SimpleImage object.\n\n#### `roundedRectangle($x1, $y1, $x2, $y2, $radius, $color, $thickness)`\n\nDraws a rounded rectangle.\n\n- `$x1`* (int) - The upper left x coordinate.\n- `$y1`* (int) - The upper left y coordinate.\n- `$x2`* (int) - The bottom right x coordinate.\n- `$y2`* (int) - The bottom right y coordinate.\n- `$radius`* (int) - The border radius in pixels.\n- `$color`* (string|array) - The rectangle color.\n- `$thickness` (int|string) - Line thickness in pixels or 'filled' (default 1).\n\nReturns a SimpleImage object.\n\n### Filters\n\n#### `blur($type, $passes)`\n\nApplies the blur filter.\n\n- `$type` (string) - The blur algorithm to use: 'selective', 'gaussian' (default 'gaussian').\n- `$passes` (int) - The number of time to apply the filter, enhancing the effect (default 1).\n\nReturns a SimpleImage object.\n\n#### `brighten($percentage)`\n\nApplies the brightness filter to brighten the image.\n\n- `$percentage`* (int) - Percentage to brighten the image (0 - 100).\n\nReturns a SimpleImage object.\n\n#### `colorize($color)`\n\nApplies the colorize filter.\n\n- `$color`* (string|array) - The filter color.\n\nReturns a SimpleImage object.\n\n#### `contrast($percentage)`\n\nApplies the contrast filter.\n\n- `$percentage`* (int) - Percentage to adjust (-100 - 100).\n\nReturns a SimpleImage object.\n\n#### `darken($percentage)`\n\nApplies the brightness filter to darken the image.\n\n- `$percentage`* (int) - Percentage to darken the image (0 - 100).\n\nReturns a SimpleImage object.\n\n#### `desaturate()`\n\nApplies the desaturate (grayscale) filter.\n\nReturns a SimpleImage object.\n\n#### `duotone($lightColor, $darkColor)`\n\nApplies the duotone filter to the image.\n\n- `$lightColor`* (string|array) - The lightest color in the duotone.\n- `$darkColor`* (string|array) - The darkest color in the duotone.\n\nReturns a SimpleImage object.\n\n#### `edgeDetect()`\n\nApplies the edge detect filter.\n\nReturns a SimpleImage object.\n\n#### `emboss()`\n\nApplies the emboss filter.\n\nReturns a SimpleImage object.\n\n#### `invert()`\n\nInverts the image's colors.\n\nReturns a SimpleImage object.\n\n#### `opacity()`\n\nChanges the image's opacity level.\n\n- `$opacity`* (float) - The desired opacity level (0 - 1).\n\nReturns a SimpleImage object.\n\n#### `pixelate($size)`\n\nApplies the pixelate filter.\n\n- `$size` (int) - The size of the blocks in pixels (default 10).\n\nReturns a SimpleImage object.\n\n#### `sepia()`\n\nSimulates a sepia effect by desaturating the image and applying a sepia tone.\n\nReturns a SimpleImage object.\n\n#### `sharpen($amount)`\n\nSharpens the image.\n\n- `$amount` (int) - Sharpening amount (1 - 100, default 50)\n\nReturns a SimpleImage object.\n\n#### `sketch()`\n\nApplies the mean remove filter to produce a sketch effect.\n\nReturns a SimpleImage object.\n\n### Color utilities\n\n#### `(static) adjustColor($color, $red, $green, $blue, $alpha)`\n\nAdjusts a color by increasing/decreasing red/green/blue/alpha values independently.\n\n- `$color`* (string|array) - The color to adjust.\n- `$red`* (int) - Red adjustment (-255 - 255).\n- `$green`* (int) - Green adjustment (-255 - 255).\n- `$blue`* (int) - Blue adjustment (-255 - 255).\n- `$alpha`* (float) - Alpha adjustment (-1 - 1).\n\nReturns an RGBA color array.\n\n#### `(static) darkenColor($color, $amount)`\n\nDarkens a color.\n\n- `$color`* (string|array) - The color to darken.\n- `$amount`* (int) - Amount to darken (0 - 255).\n\nReturns an RGBA color array.\n\n#### `extractColors($count = 10, $backgroundColor = null)`\n\nExtracts colors from an image like a human would do.™ This method requires the third-party library \\League\\ColorExtractor. If you're using Composer, it will be installed for you automatically.\n\n- `$count` (int) - The max number of colors to extract (default 5).\n- `$backgroundColor` (string|array) - By default any pixel with alpha value greater than zero will be discarded. This is because transparent colors are not perceived as is. For example, fully transparent black would be seen white on a white background. So if you want to take transparency into account, you have to specify a default background color.\n\nReturns an array of RGBA colors arrays.\n\n#### `getColorAt($x, $y)`\n\nGets the RGBA value of a single pixel.\n\n- `$x`* (int) - The horizontal position of the pixel.\n- `$y`* (int) - The vertical position of the pixel.\n\nReturns an RGBA color array or false if the x/y position is off the canvas.\n\n#### `(static) lightenColor($color, $amount)`\n\nLightens a color.\n\n- `$color`* (string|array) - The color to lighten.\n- `$amount`* (int) - Amount to darken (0 - 255).\n\nReturns an RGBA color array.\n\n#### `(static) normalizeColor($color)`\n\nNormalizes a hex or array color value to a well-formatted RGBA array.\n\n- `$color`* (string|array) - A CSS color name, hex string, or an array [red, green, blue, alpha].\n\nYou can pipe alpha transparency through hex strings and color names. For example:\n\n  #fff|0.50 \u003c-- 50% white\n  red|0.25 \u003c-- 25% red\n\nReturns an array: [red, green, blue, alpha]\n\n### Exceptions\n\nSimpleImage throws standard exceptions when things go wrong. You should always use a try/catch block around your code to properly handle them.\n\n```php\n\u003c?php\ntry {\n  $image = new \\claviska\\SimpleImage('image.jpeg')\n  // ...\n} catch(Exception $err) {\n  echo $err-\u003egetMessage();\n}\n```\n\nTo check for specific errors, compare `$err-\u003egetCode()` to the defined error constants.\n\n```php\n\u003c?php\ntry {\n  $image = new \\claviska\\SimpleImage('image.jpeg')\n  // ...\n} catch(Exception $err) {\n  if($err-\u003egetCode() === $image::ERR_FILE_NOT_FOUND) {\n    echo 'File not found!';\n  } else {\n    echo $err-\u003egetMessage();\n  }\n}\n```\n\nAs a best practice, always use the defined constants instead of their integers values. The values will likely change in future versions, and WILL NOT be considered a breaking change.\n\n- `ERR_FILE_NOT_FOUND` - The specified file could not be found or loaded for some reason.\n- `ERR_FONT_FILE` - The specified font file could not be loaded.\n- `ERR_FREETYPE_NOT_ENABLED` - Freetype support is not enabled in your version of PHP.\n- `ERR_GD_NOT_ENABLED` - The GD extension is not enabled in your version of PHP.\n- `ERR_LIB_NOT_LOADED` - A required library has not been loaded.\n- `ERR_INVALID_COLOR` - An invalid color value was passed as an argument.\n- `ERR_INVALID_DATA_URI` - The specified data URI is not valid.\n- `ERR_INVALID_IMAGE` - The specified image is not valid.\n- `ERR_UNSUPPORTED_FORMAT` - The image format specified is not valid.\n- `ERR_WEBP_NOT_ENABLED` - WEBP support is not enabled in your version of PHP.\n- `ERR_WRITE` - Unable to write to the file system.\n- `ERR_INVALID_FLAG` - The specified flag key does not exist.\n\n### Useful Things To Know\n\n- Color arguments can be a CSS color name (e.g. `LightBlue`), a hex color string (e.g. `#0099dd`), or an RGB(A) array (e.g. `['red' =\u003e 255, 'green' =\u003e 0, 'blue' =\u003e 0, 'alpha' =\u003e 1]`).\n\n- When `$thickness` \u003e 1, GD draws lines of the desired thickness from the center origin. For example, a rectangle drawn at [10, 10, 20, 20] with a thickness of 3 will actually be draw at [9, 9, 21, 21]. This is true for all shapes and is not a bug in the SimpleImage library.\n\n### Instance flags\n\nTweak the behavior of a SimpleImage instance by setting instance flag values with the `setFlag($key, $value)` method.\n\n```php\n$image = new \\claviska\\SimpleImage('image.jpeg')-\u003esetFlag(\"foo\", \"bar\");\n```\n\nYou can also pass an associative array to the SimpleImage constructor to set instance flags.\n\n```php\n$image = new \\claviska\\SimpleImage('image.jpeg', ['foo' =\u003e 'bar']);\n// .. or without an $image\n$image = new \\claviska\\SimpleImage(flags: ['foo' =\u003e 'bar']);\n```\n\n*Note: `setFlag()` throws an `ERR_INVALID_FLAG` exception if the key does not exist (no default value).*\n\n#### `sslVerify`\n\nSetting `sslVerify` to `false` (defaults to `true`) will make all images loaded over HTTPS forgo certificate peer validation. This is especially usefull for self-signed certificates.\n\n```php\n$image = new \\claviska\\SimpleImage('https://localhost/image.jpeg', ['sslVerify' =\u003e false]);\n// Would normally throw an OpenSSL exception, but is ignored with the sslVerify flag set to false.\n```\n\n## Differences from SimpleImage 2.x\n\n- Normalized color arguments (colors can be a CSS color name, hex color, or RGB(A) array).\n- Normalized alpha (opacity) arguments: 0 (transparent) - 1 (opaque)\n- Added text shadow to `text` method.\n- Added `fromString()` method to load images from strings.\n- Added `toString()` method to generate image strings.\n- Added `arc` method for drawing arcs.\n- Added `border` method for drawing borders.\n- Added `dot` method for drawing individual pixels.\n- Added `ellipse` method for drawing ellipses and circles.\n- Added `line` method for drawing lines.\n- Added `polygon` method for drawing polygons.\n- Added `rectangle` method for drawing rectangles.\n- Added `roundedRectangle` method for drawing rounded rectangles.\n- Added `adjustColor` method for modifying RGBA color channels to create relative color variations.\n- Added `darkenColor` method to darken a color.\n- Added `extractColors` method to get the most common colors from the image.\n- Added `getColorAt` method to get the RGBA values of a specific pixel.\n- Added `lightenColor` method to lighten a color.\n- Added `toDownload` method to force the image to download on the client's machine.\n- Added `duotone` filter to create duotone images.\n- Added `sharpen` method to sharpen the image.\n- Changed namespace from `abeautifulsite` to `claviska`.\n- Changed `create` method to `fromNew`.\n- Changed `load` method to `fromFile`.\n- Changed `load_base64` method to `fromDataUri`.\n- Changed `output` method to `toScreen`.x\n- Changed `output_base64` method to `toDataUri`.\n- Changed `save` method to `toFile`.\n- Changed `text` method to accept an array of options instead of tons of arguments.\n- Removed text stroke from `text` method because it produced dirty results and didn't support transparency.\n- Removed `smooth` method because its arguments in the PHP manual aren't documented well.\n- Removed deprecated method `adaptive_resize` (use `thumbnail` instead).\n- Removed `get_meta_data` (use `getExif`, `getHeight`, `getMime`, `getOrientation`, and `getWidth` instead).\n- Added [.editorconfig](http://editorconfig.org/) file. Please make sure your editor supports these settings before submitting contributions.\n- Switched from four spaces to two for indentations (sorry PHP-FIG!).\n- Switched from underscore_methods to camelCaseMethods.\n- Organized methods into groups based on function\n- Removed PHPDoc comments. At this time, I don't wish to incorporate them into the library.\n","funding_links":["https://github.com/sponsors/claviska"],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclaviska%2FSimpleImage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclaviska%2FSimpleImage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclaviska%2FSimpleImage/lists"}