{"id":14985408,"url":"https://github.com/antonlukin/poster-editor","last_synced_at":"2026-03-07T00:30:49.025Z","repository":{"id":41143508,"uuid":"220007406","full_name":"antonlukin/poster-editor","owner":"antonlukin","description":"Wrapper for PHP's GD Library for easy image manipulation. Support for scaling multi-line text, shapes, filters and smart resize.","archived":false,"fork":false,"pushed_at":"2025-02-04T20:32:57.000Z","size":12743,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-29T08:33:52.994Z","etag":null,"topics":["composer","image-processing","image-text","intervention","php","php-class","php-gd","php-image","php-library","poster-editor"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/antonlukin/poster-editor","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antonlukin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2019-11-06T13:49:40.000Z","updated_at":"2025-02-04T20:33:47.000Z","dependencies_parsed_at":"2025-04-11T19:43:11.897Z","dependency_job_id":"a7518be8-c695-4c36-b57f-a400acfeb168","html_url":"https://github.com/antonlukin/poster-editor","commit_stats":{"total_commits":38,"total_committers":2,"mean_commits":19.0,"dds":0.02631578947368418,"last_synced_commit":"190fc123de1d8c4453481d413dfcf40bd58eb30d"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/antonlukin/poster-editor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonlukin%2Fposter-editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonlukin%2Fposter-editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonlukin%2Fposter-editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonlukin%2Fposter-editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonlukin","download_url":"https://codeload.github.com/antonlukin/poster-editor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonlukin%2Fposter-editor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30204154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"ssl_error","status_checked_at":"2026-03-06T18:57:34.882Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["composer","image-processing","image-text","intervention","php","php-class","php-gd","php-image","php-library","poster-editor"],"created_at":"2024-09-24T14:10:55.728Z","updated_at":"2026-03-07T00:30:49.003Z","avatar_url":"https://github.com/antonlukin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Poster Editor\n\nThis class is an alternative to the package [Intervention Image](https://github.com/Intervention/image) for more flexible work with text on the image.\nUse it if you need to **fit text** in a given area, automatically **calculate font size** and change **line height**. \nThe text drawing method also knows how to return the actual size of the inscriptions, which will allow, for example, to place blocks under each other.\n\nIn addition to flexible work with text, the class provides an Image API similar to the Intervention package. \nIncluding smart poster resizing, filters, drawing shapes, and overlaying other images.\n\nIf you are not using composer in your work, you may also be interested in the simplicity of the class and the absence of any dependencies.\nNote that this class supports PHP-GD driver only.\nYou can also easily inherit your class — all methods of the parent can be overridden.\n\n## Installation\nThe best way to install Poster Editor is quickly and easily with [Composer](http://getcomposer.org/).  \nHowever, you can require the class directly without using a loader - this will not affect performance in any way.\n\n`php composer.phar require antonlukin/poster-editor`\n\n## Usage\nIn case of an error, the class methods return an exception.  \nTherefore, it is best to call them inside a block `try..catch`.\n\n#### Example\n```php\n// Using composer\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n// Or directly\n// require_once __DIR__ . '/PosterEditor.php';\n\ntry {\n    $image = new PosterEditor\\PosterEditor();\n    $image-\u003emake('images/bridge.jpg')-\u003efit(600, 600);\n    $image-\u003eshow();\n\n} catch(Exception $e) {\n    echo $e-\u003egetMessage();\n}\n```\n\n## Availible methods\n### get\n```\n$image-\u003eget()\n```\nGet image resource to use raw gd commands.\n\n### set\n```\n$image-\u003eset(instance $resourse)\n```\nSet image resource after using raw gd commands.\n\n### make\n```\n$image-\u003emake(mixed $data)\n```\nMake new image instance from file or binary data.\n\n### insert\n```\n$image-\u003einsert(mixed $data, array $options = array())\n```\nPaste a given image source over the current image with an optional position. \nFirst param can be binary data or path to file or another class instance.\nOptions is an array of x/y relative offset coords from top left corner and opacity from 0 to 100, where 0 is no transparency. \nBy default image will be centered.\n\n### canvas\n```\n$image-\u003ecanvas(int $width, int $height, array $options = array())\n```\nIntialise the canvas by width and height. Background color options is in array of color/opacity settings.\nBy default black canvas without opacity.\n\n### show\n```\n$image-\u003eshow(string $format = null, int $quality = 90)\n```\nSends HTTP response with current image in given format and quality.\nFormat is a file image extension. By default the response data will be encoded in the type of the current image. If no image type is defined yet, method will return jpeg encoded data.\nQuality is normalized for all file types to a range from 0 (poor quality, small file) to 100 (best quality, big file). \nThe default value is 90. PNG format is losless and the quality affects only image size and compression speed.\n\n### save\n```\n$image-\u003esave(string $path, int $quality = 90, string $format = null)\n```\nSave the current state of the image object in filesystem. Define optionally a certain path where the image should be saved. The image type will be defined by file extension. If there is no extension available, the response data will be encoded in the type of the current image. If no image type is defined yet, method will return jpeg encoded data. Optionally you can override this with the format parameter. \nQuality is normalized for all file types to a range from 0 (poor quality, small file) to 100 (best quality, big file). \nThe default value is 90. PNG format is losless and the quality affects only image size and compression speed.\n\n### destroy\n```\n$image-\u003edestroy()\n```\nFrees memory associated with the current image instance before the PHP script ends. \nNormally resources are destroyed automatically after the script is finished.\n\n### width\n```\n$image-\u003ewidth()\n```\nReturns the height in pixels of the current image.\n\n### height\n```\n$image-\u003eheight()\n```\nReturns the height in pixels of the current image.\n\n### resize\n```\n$image-\u003eresize(int $width, int $height)\n```\nResizes current image based on given width and height. \nDoes not pay attention to the aspect ratio. In order to resize proportionally, use `upsize` and `downsize` methods.\n\n### upsize\n```\n$image-\u003eupsize(int $width = null, int $height = null)\n```\nUpsize image on the largest side. Calculated by ratio for nulled width or height.\n\n### downsize\n```\n$image-\u003edownsize(int $width = null, int $height = null)\n```\nDownsize image on the largest side. Calculated by ratio for nulled width or height.\n\n### crop\n```\n$image-\u003ecrop(int $width, int $height, array $options = array())\n```\nCut out a rectangular part of the current image with given width and height.\nDefine optional x,y coordinates to move the top-left corner of the cutout to a certain position.\n\n### fit\n```\n$image-\u003efit(int $width, int $height, string $position = 'center')\n```\nCombine cropping and resizing to format image in a smart way.\nThe method will find the best fitting aspect ratio on the current image automatically, \ncut it out and resize it to the given dimension. \nPossible positions `top-left`, `top`, `top-right`, `bottom-left`, `bottom`, `bottom-right`, `right`, `left` and `center` by default.\n\n### line\n```\n$image-\u003eline(int $x1, int $y1, int $x2, int $y2, array $options = array())\n```\nDraw a line from x,y point 1 to x,y point 2 on current image. Use options param to set color, opacity and width values.\n\n### rectangle\n```\n$image-\u003erectangle(int $x, int $y, int $width, int $height, array $options = array())\n```\nDraw a colored rectangle on current image. Use options param to set color, opacity, thickness and outline values.\n\n### ellipse\n```\n$image-\u003eellipse(int $x, int $y, int $width, int $height, array $options = array())\n```\nDraw an ellipse. Use options param to set color, opacity and outline values.\n\n### brightness\n```\n$image-\u003ebrightness(int $level = 0)\n```\nChange the brightness of the current image by the given level.\nUse values between -100 for min brightness 0 for no change and +100 for max.\n\n### contrast\n```\n$image-\u003econtrast(int $level = 0)\n```\nChange the contrast of the current image by the given level.\nUse values between -100 for min contrast 0 for no change and +100 for max.\n\n### grayscale\n```\n$image-\u003egrayscale()\n```\nTurn an image into a grayscale version.\n\n### blur\n```\n$image-\u003eblur()\n```\nApply a blur image effect.\n\n### invert\n```\n$image-\u003einvert()\n```\nInvert colors of an image.\n\n### blackout\n```\n$image-\u003eblackout()\n```\nDraw black opactity rectangle on image.\n\n### rotate\n```\n$image-\u003erotate(int $angle, array $options = array())\n```\nRotate image. Set an angle in degrees and optional color of the uncovered zone after the rotation.\n\n### text\n```\n$image-\u003etext(string $text, array $options = array(), array \u0026$boundary = array())\n```\nDraw text on image. Possible options:\n- **x**: X-Coordinate of text box starting point.\n- **y**: Y-Coordinate of text box starting point.\n- **width**: Width of text box. Calculated from image size for nulled values.\n- **height**: Height of text box. Calculated from image size for nulled values.\n- **fontsize**: Maximum font size. Will be scaled down if the text doesn't fit box.\n- **color**: Color of text. Can be rgb-array or '#ffffff' format.\n- **lineheight**: Line height of text.\n- **opacity**: Text opacity from 0 to 100. Where 0 is no transparency.\n- **horizontal**: Horizontal alignment. Can be left/right/center/justify.\n- **vertical**: Vertical alginment. Can be top/center/bottom/justify.\n- **fontpath**: Path to .ttf or .otf font file.\n- **debug**: Draws text box rectangle if true.\n\nUse boundary to get actual dimensions of the drawn text box. See detailed examples below.\n\n## Examples\n\n### Append downsized image to blackout background\n```php\n$image = new PosterEditor\\PosterEditor();\n$image-\u003emake('images/bridge.jpg')-\u003efit(1200, 630, 'bottom')-\u003eblackout(50);\n\n$logo = new PosterEditor\\PosterEditor();\n$logo-\u003emake('images/logo.png')-\u003edownsize(150, null);\n\n$image-\u003einsert($logo, array('x' =\u003e 50, 'y' =\u003e 50))-\u003eshow();\n```\n#### Result\n\u003cimg src=\"tests/references/append.jpg\" alt=\"append image\" width=\"400\" /\u003e\n\n### Draw and center multiline text\n```php\n$image = new PosterEditor\\PosterEditor();\n$image-\u003emake('images/bridge.jpg')-\u003efit(1200, 630);\n$image-\u003egrayscale()-\u003ebrightness(-40);\n\n$image-\u003etext(\n    'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat Lorem ipsum dolor sit amet', // phpcs:ignore\n    array(\n        'x'          =\u003e 100,\n        'y'          =\u003e 100,\n        'width'      =\u003e 1000,                 \n        'height'     =\u003e 400,                  \n        'horizontal' =\u003e 'center',             \n        'vertical'   =\u003e 'center',             \n        'fontpath'   =\u003e 'fonts/opensans.ttf',\n        'fontsize'   =\u003e 24,\n        'lineheight' =\u003e 1.75,\n        'color'      =\u003e '#ffffff',\n        'opacity'    =\u003e 0,\n        'debug'      =\u003e true,\n    )\n);\n\n$image-\u003eshow('jpg', 70);\n```\n#### Result\n\u003cimg src=\"tests/references/center.jpg\" alt=\"multiline centered text\" width=\"400\" /\u003e\n\n### Draw and justify multiline text\n```php\n$image = new PosterEditor\\PosterEditor();\n$image-\u003emake('images/bridge.jpg')-\u003efit(900, 600);\n$image-\u003eblackout(70);\n\n$image-\u003etext(\n    'Lorem ipsum dolor d d 4 g sit amet, consectetur adipiscing et, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex eas commodo consequat sdfsdfl', // phpcs:ignore\n    array(\n        'x'          =\u003e 100,\n        'y'          =\u003e 100,\n        'width'      =\u003e 600,                   \n        'height'     =\u003e 400,                   \n        'horizontal' =\u003e 'justify',             \n        'vertical'   =\u003e 'justify',             \n        'fontpath'   =\u003e 'fonts/opensans.ttf',\n        'fontsize'   =\u003e 20,\n        'lineheight' =\u003e 1.5,\n        'color'      =\u003e '#ffffff',\n        'opacity'    =\u003e 0,\n        'debug'      =\u003e true,\n    )\n);\n\n$image-\u003eshow('png');\n```\n#### Result\n\u003cimg src=\"tests/references/justify.png\" alt=\"multiline justified text\" width=\"400\" /\u003e\n\n### Use boundaries to draw one title right after another\n```php\n$image = new PosterEditor\\PosterEditor();\n$image-\u003emake('images/bridge.jpg')-\u003ecrop(\n    900, 600,\n    array(\n        'x' =\u003e '0',\n        'y' =\u003e '100'\n    )\n);\n\n$image-\u003egrayscale()-\u003ebrightness(-40);\n\n$image-\u003etext(\n    'Large title with unknown height. Can be multi-line',\n    array(\n        'x'          =\u003e 50,\n        'y'          =\u003e 100,\n        'width'      =\u003e 800,\n        'fontpath'   =\u003e '/fonts/merriweather.ttf',\n        'fontsize'   =\u003e 48,\n        'lineheight' =\u003e 1.5,\n        'color'      =\u003e '#9999ff',\n    ),\n    $boundary\n);\n\n$image-\u003etext(\n    'This text appears right after title using smart boundaries',\n    array(\n        'x'          =\u003e 50,\n        'y'          =\u003e $boundary['y'] + $boundary['height'],\n        'width'      =\u003e 800,\n        'fontpath'   =\u003e '/fonts/opensans.ttf',\n        'fontsize'   =\u003e 20,\n        'lineheight' =\u003e 1.5,\n        'color'      =\u003e '#ff9999',\n    ),\n    $boundary\n);\n\n$image-\u003eshow();\n```\n#### Result\n\u003cimg src=\"tests/references/boundary.jpg\" alt=\"boundary\" width=\"400\" /\u003e\n\n### Draw shapes\n```php\n$image = new PosterEditor\\PosterEditor();\n$image-\u003emake('images/bridge.jpg')-\u003efit(1000, 630, 'bottom');\n$image-\u003econtrast(5)-\u003ebrightness(-30)-\u003eblur();\n\n$image-\u003erectangle(\n    20, 20, 960, 590,\n    array(\n        'color'   =\u003e '#ffffff',\n        'outline' =\u003e true,\n        'width'   =\u003e 4,\n    )\n);\n\n$image-\u003eellipse(\n    200, 200, 200, 200,\n    array(\n        'color'   =\u003e '#00ff00',\n        'opacity' =\u003e 50,\n    )\n);\n\n$image-\u003eellipse(\n    800, 200, 200, 200,\n    array(\n        'color'   =\u003e '#ff0000',\n        'opacity' =\u003e 50,\n    )\n);\n\n$image-\u003erectangle(\n    480, 280, 80, 140,\n    array(\n        'color'   =\u003e '#0000ff',\n    )\n);\n\n$image-\u003eline(\n    200, 500, 800, 500,\n    array(\n        'color'   =\u003e array(255, 255, 0),\n        'opacity' =\u003e 10,\n        'width'   =\u003e 4,\n    )\n);\n\n$image-\u003eshow('png');\n```\n#### Result\n\u003cimg src=\"tests/references/shapes.png\" alt=\"shapes result\" width=\"400\" /\u003e\n\n\n## Contribution\nAll project code is stored on Github. The best way to help the project is to report a bug or add some new functionality. \nYou can also open here an [issue](https://github.com/antonlukin/poster-editor/issues) or send a [pull reguest](https://github.com/antonlukin/poster-editor/pulls).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonlukin%2Fposter-editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonlukin%2Fposter-editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonlukin%2Fposter-editor/lists"}