{"id":22181010,"url":"https://github.com/easygithdev/easygd","last_synced_at":"2025-10-12T03:37:28.907Z","repository":{"id":6878432,"uuid":"8127640","full_name":"EasyGithDev/EasyGD","owner":"EasyGithDev","description":"EasyGD - a PHP framework for use GD easier","archived":false,"fork":false,"pushed_at":"2020-06-23T07:41:15.000Z","size":654,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-29T23:30:16.604Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/EasyGithDev.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}},"created_at":"2013-02-10T20:30:19.000Z","updated_at":"2020-06-23T07:41:18.000Z","dependencies_parsed_at":"2022-08-26T07:11:13.355Z","dependency_job_id":null,"html_url":"https://github.com/EasyGithDev/EasyGD","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyGithDev%2FEasyGD","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyGithDev%2FEasyGD/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyGithDev%2FEasyGD/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EasyGithDev%2FEasyGD/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EasyGithDev","download_url":"https://codeload.github.com/EasyGithDev/EasyGD/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245334914,"owners_count":20598389,"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":[],"created_at":"2024-12-02T09:21:33.283Z","updated_at":"2025-10-12T03:37:23.876Z","avatar_url":"https://github.com/EasyGithDev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"EasyGD\n======\n\nEasyGD is a PHP framework to use GD easier\u003cbr/\u003e\nThe frame allows you to easily load images from a file, URL or string.\u003cbr/\u003e\nAfter loading the image, you can apply transformations.\u003cbr/\u003e\nYou can then choose to save the result as a file, either to return a character string, or to send the image directly to the browser.\u003cbr/\u003e\n\n## Installing\n\nInstallation is quite typical - with composer:\n\n```\ncomposer require easygithdev/easygd\n```\n\n## The header script\n\nYou will need to include the autoloader before using the classes.\n\n```php\n\u003c?php\n\nrequire __DIR__ . '/vendor/autoload.php';\n\nuse Easygd\\Image;\n\n```\n\n## The basic stuff \n\nIn all the examples that follow, the $stream variable is either a URL or a file or a character string.\u003cbr/\u003e\nFor example, you can use the PHP logo with the following URL:\n\n```php\n$stream = 'https://www.php.net/images/logos/new-php-logo.png';\n```\n\n![PHP Logo](https://www.php.net/images/logos/new-php-logo.png)\n\n#### How to load and show an image\n\nIn this case, the stream is directly sent to the browser.\n\n```php\n(new Image())-\u003eload($stream)-\u003eshow();\n```\t\n\n#### How to load and render an image in a HTML tag\n\nYou can use the data src property to render the image in the HTML tag.\u003cbr /\u003e\nUse it only on small image, if you dont want that your HTML page becommes to big. \n\n```php\n\u003cimg src=\"\u003c?php echo (new Image())-\u003eload($stream)-\u003esrc() ?\u003e\" /\u003e\n```\n\n#### How to load and save an image on disk\n\nIn this case, the stream is saved to the browser.\n\n```php\n(new Image())-\u003eload($stream)-\u003esave('php.png');\n```\n\n#### How to load, save and show an image in the same time\n\n```php\n(new Image())-\u003eload($stream)-\u003esave('php.png')-\u003eshow();\n```\n\n#### How to make multiple save\n\n```php\n(new Image())-\u003eload($stream)-\u003esave('php.png')\n-\u003esetType(IMAGETYPE_GIF)-\u003esave('php.gif')\n-\u003esetType(IMAGETYPE_JPEG)-\u003esave('php.jpg');\n```\n\n----\n\n\n## The other types\n\n#### Define a dimension\n\n```php\n$dimension = (new Dimension())-\u003ecreate(300, 300);\n```\n\n#### Define a color\n\n```php\n// Create a color with hexadecimal code\n$color = (new Color())-\u003ecreate('#83d01e');\n\n// OR create a color from a preset\n$color = (new Color())-\u003ecreate(Color::Yellow);\n\n// OR create a preseted color \n$color = Color::Yellow();\n```\n\n#### Define a position\n\n```php\n$position = (new Position())-\u003ecreate(200, 125);\n```\n\n#### Define a text\n\n```php\n$text = (new Text())-\u003ecreate('Hello World');\n```\n\n## Create your own images\n\n#### How to create a truetype image\n\n```php\n(new Image())-\u003ecreate($dimension, $color)-\u003eshow();\n```\n\n----\n\n## Adding text in the images \n\n#### How to draw a text into an image\n\n```php\n(new Image)-\u003ecreate((new Dimension)-\u003ecreate(300, 300), Color::Blue())\n-\u003eaddText(\n(new Text())-\u003ecreate('Hello World')\n    -\u003esetColor(Color::Silver())\n    -\u003esetSize(3)\n    -\u003esetPosition((new Position)-\u003ecreate(200, 125))\n)-\u003eshow();\n```\n\n#### How to draw a string vertically into an image\n\n```php\n(new Image())-\u003ecreate((new Dimension())-\u003ecreate(200, 200))-\u003eaddText(\n\t(new Text())-\u003ecreate('gd library')\n\t-\u003esetSize(5)\n\t-\u003esetColor(Color::White())\n\t-\u003esetDrawtype(Text::TEXT_DRAW_VERTICAL)\n\t-\u003esetPosition((new Position())-\u003ecreate(40, 100))\n)-\u003eshow();\n```\n\n#### How to apply an alpha color to a text into an image\n    \n```php    \n(new Image)-\u003ecreate((new Dimension())-\u003ecreate(300, 300), Color::White())-\u003eaddText(\n\t(new Text())-\u003ecreate('Alpha Color')\n\t-\u003esetColor(\n\t\t(new Color())-\u003ecreate('#FF0000')-\u003esetAlpha(95)\n\t)\n\t-\u003esetSize(5)\n\t-\u003esetPosition((new Position())-\u003ecreate(55, 35))\n)\n-\u003eshow();\n```\n\n#### How to mix \"GD text\", \"TrueType text\", \"FreeType text\" into an image\n\n```php\n(new Image())-\u003ecreate((new Dimension())-\u003ecreate(300, 300), (new Color())-\u003ecreate('#f2f2f2'))\n-\u003eaddText(\n\t(new Text())-\u003ecreate('True Type')\n\t\t-\u003esetFontType(Text::TEXT_FONT_TRUETYPE)\n\t\t-\u003esetFontfile(Text::TEXT_UNIX_FONT_PATH . '/truetype/dejavu/DejaVuSans.ttf')\n\t\t-\u003esetColor(Color::Silver())\n\t\t-\u003esetSize(16)\n\t\t-\u003esetAngle(45)\n\t\t-\u003esetPosition((new Position())-\u003ecreate(100, 100))\n)\n-\u003eaddText(\n\t(new Text())-\u003ecreate('Hello ' . PHP_EOL . 'Free Type')\n\t\t-\u003esetFontType(Text::TEXT_FONT_FREETYPE)\n\t\t-\u003esetFontfile(Text::TEXT_UNIX_FONT_PATH . '/truetype/dejavu/DejaVuSans.ttf')\n\t\t-\u003esetColor(Color::Silver())\n\t\t-\u003esetSize(16)\n\t\t-\u003esetAngle(45)\n\t\t-\u003esetPosition((new Position())-\u003ecreate(100, 175))\n)\n-\u003eaddText(\n\t(new Text())-\u003ecreate('hello world')\n\t\t-\u003esetColor(Color::Maroon())\n\t\t-\u003esetPosition((new Position())-\u003ecreate(98, 173))\n)\n-\u003eshow();\n```\n\n----\n\n## Get the informations\n\n#### How to get the information about an image\n\n```php\n$infos = (new Image())-\u003eload($stream)-\u003egetInfos();\necho '\u003cpre\u003e', $infos, '\u003c/pre\u003e';\n\n$infos = (new Image())-\u003eload($stream)-\u003egetInfos()-\u003etoArray();\necho '\u003cpre\u003e', print_r($infos, true), '\u003c/pre\u003e'; \n```\n\n#### How to have the preseted positions\n\n```php\n$image = (new Image())-\u003eload($stream);\n\necho 'TOP_LEFT:', $image-\u003etopLeft(), '\u003cbr/\u003e';\necho 'TOP_CENTER:', $image-\u003etopCenter(), '\u003cbr/\u003e';\necho 'TOP_RIGHT:', $image-\u003etopRight(), '\u003cbr/\u003e';\necho 'MIDDLE_LEFT', $image-\u003emiddleLeft(), '\u003cbr/\u003e';\necho 'MIDDLE_CENTER', $image-\u003emiddleCenter(), '\u003cbr/\u003e';\necho 'MIDDLE_RIGHT', $image-\u003emiddleRight(), '\u003cbr/\u003e';\necho 'BOTTOM_LEFT', $image-\u003ebottomLeft(), '\u003cbr/\u003e';\necho 'BOTTOM_CENTER', $image-\u003ebottomeCenter(), '\u003cbr/\u003e';\necho 'BOTTOM_RIGHT', $image-\u003ebottomRight(), '\u003cbr/\u003e';\n```\n\nIt will return an object Position ...\n\n#### How to get / add the IPTC tag\n\nRemember IPTC work with JPEG files.\n\n```php\n(new Image())-\u003eload($stream)-\u003esetType(IMG_JPEG)-\u003esave('iptc.jpg');\n\n$fileSrc = __DIR__ . '/iptc.jpg';\n$fileDst = __DIR__ . '/iptc2.jpg';\n\n$iptc = (new Iptc())-\u003ecreate($fileSrc, null);\n$iptc-\u003eaddTag(Iptc::IPTC_CITY, 'CHEVERNY')\n    -\u003eaddTag(Iptc::IPTC_COUNTRY, 'FRANCE')\n    -\u003eaddTag(Iptc::IPTC_CREATED_DATE, '2012-03-01')\n    -\u003eaddTag(Iptc::IPTC_CATEGORY, 'JOURNEY');\n\nif ($iptc-\u003ewrite($fileDst) === false) {\n    throw new Exception('Error to write IPTC');\n}\necho '\u003cpre\u003e', (new Image())-\u003eload($fileDst)-\u003egetInfos(), '\u003c/pre\u003e';\n```\n\n----\n\n## Resizing the images\n\n#### How to resize an image\n\n```php\n(new Image)-\u003eload($stream)\n-\u003eresizeByPercent(0.5)\n-\u003eshow();\n```\n\n#### How to resize an image by fixing the width or height\n\n```php\n(new Image)-\u003eload($stream)\n-\u003eresizeByWidth(50)\n-\u003eshow();\n\n(new Image)-\u003eload($stream)\n-\u003eresizeByHeight(30)\n-\u003eshow();\n```\n\n#### How to safetly resize an image \n\n```php\n(new Image)-\u003eload($stream)\n-\u003eresizeAuto((new Dimension())-\u003ecreate(300, 200))\n-\u003eshow();\n```\n\n#### How to make a thumbnail\n\n```php\n(new Image)-\u003eload($stream)\n-\u003ethumbnail(140, Color::Silver())\n-\u003eshow();\n```\n\n## Croping and Rotation\n\n#### How to crop an image\n\n```php\n(new Image)-\u003eload($stream)\n-\u003ecrop((new Position)-\u003ecreate(20, 13), (new Dimension())-\u003ecreate(80, 40))\n-\u003eshow();\n```\n\n#### How to make a rotation\n\n```php\n(new Image)-\u003eload($stream)\n-\u003erotate(90)\n-\u003eshow();\n```\n\n## Merging two images\n\n#### How to insert a logo into an image\n\n```php\n$logo = (new Image)-\u003eload('http://www.php.net/images/logos/php-med-trans-light.gif')\n-\u003eresizeByPercent(0.6);\n\n(new Image)-\u003eload('http://static.php.net/www.php.net/images/logos/php-med-trans.png')\n-\u003einlay($logo, (new Position)-\u003ecreate(30, 20), 100)\n-\u003eshow();\n```\n\n## Make thumbnails\n\nHere you can find an example to, easyly, generate some thumbnails.\n\n```php\n$text = (new Text)-\u003ecreate('Copyright (C) 2020 Your Name')\n\t-\u003esetFontType(Text::TEXT_FONT_TRUETYPE)\n\t-\u003esetFontfile(Text::TEXT_UNIX_FONT_PATH . '/truetype/dejavu/DejaVuSans.ttf')\n\t-\u003esetSize(5)\n\t-\u003esetColor(Color::White())\n\t-\u003esetPosition((new Position())-\u003ecreate(40, 190));\n\n$path = __DIR__ . '/images/original/';\n\nforeach (new ImageFilterIterator(new DirectoryIterator($path)) as $file) {\n\n\tif (($image = (new Image)-\u003eload($file-\u003egetPathname())) === false) {\n\t\tcontinue;\n\t}\n\n\t$thumb1 = $image-\u003ethumbnail(100)-\u003esrc();\n\t$thumb2 = $image-\u003ethumbnail(200)-\u003eaddText($text)-\u003esrc();\n\t$thumb3 = $image-\u003ethumbnail(400)-\u003esrc();\n?\u003e\n\n\t\u003cimg src=\"\u003c?php echo $thumb1 ?\u003e\" /\u003e\n\t\u003cimg src=\"\u003c?php echo $thumb2 ?\u003e\" /\u003e\n\t\u003cimg src=\"\u003c?php echo $thumb3 ?\u003e\" /\u003e\n\t\u003cbr /\u003e\n\u003c?php\n}\n?\u003e\n```\n\n----\n\n## Filters\n\n#### Using all the filters with the factory\n\nYou can use filters with a common syntax.\nThe factory, use the three types of filters :\n+ FILTER_PRESET\n+ FILTER_LOOKUPTABLE\n+ FILTER_CONVOLUTION\n\nYou ca use this way to call, preset/convolution/lookuptable filters like this :\n\n```php\n// Preset filters\n$src1 = Filter::negate()-\u003eprocess((new Image())-\u003eload($stream))-\u003esrc();\n\n// Convolution filters\n$src2 = Filter::emboss()-\u003eprocess((new Image())-\u003eload($stream))-\u003esrc();\n\n// LookupTable filters\n$src3 = Filter::thresholding()-\u003eprocess((new Image())-\u003eload($stream))-\u003esrc();\n```\n\n#### Using the preset filter\n\nYou can use : \n\n+ PRESET_NEGATE\n+ PRESET_GRAYSCALE\n+ PRESET_EDGEDETECT\n+ PRESET_EMBOSS\n+ PRESET_GAUSSIAN_BLUR\n+ PRESET_MEAN_REMOVAL\n+ PRESET_SELECTIVE_BLUR\n+ PRESET_PIXELATE\n+ PRESET_SMOOTH\n+ PRESET_CONTRAST\n+ PRESET_BRIGHTNESS\n+ PRESET_COLORIZE\n\n#### How to create and apply a preset filter\n\n```php\n(new PresetFilter())-\u003ecreate(PresetFunctions::negate())-\u003eprocess((new Image())-\u003eload($stream))-\u003eshow();\n```\n\n#### Using the convolution filter\n\nYou can use preseted convolution or your own convolution filters.\n\n#### How to use a preseted convolution\n\n```php\n(new ConvolutionFilter())-\u003ecreate(ConvolutionFunctions::CONVOLUTION_GAUSSIAN())-\u003eprocess((new Image())-\u003eload($stream))-\u003eshow();\n```\n\n#### How to use your own convolution\n\n```php\n$matrix = [\n-1, 7, -1,\n0, 0, 0,\n1, 7, 1\n];\n\n$convolution = (new Convolution())-\u003ecreate($matrix);;\n$dataSrc = (new ConvolutionFilter())-\u003ecreate($convolution)-\u003eprocess((new Image())-\u003eload($stream))-\u003esrc();\n```\n\n#### Using the lookuptable filter\n\nYou can use preseted lookuptable or your own lookuptable filters.\n\n#### How to use a preseted lookuptable\n\n```php\n$closure = \\Closure::fromCallable([new LookupTableFunctions(), 'LightnessGray']),\n(new LookUpTableFilter())-\u003ecreate((new LookUpTable())-\u003ecreate($closure))-\u003eprocess((new Image())-\u003eload($stream))-\u003esrc();\n```\n\n#### To create a new lookuptable filter, you must create a callback method like this :\n\n```php\nfunction personnal($rgb)\n{\n$r = ($rgb['red'] \u003e 128) ? 255 : 128;\n$g = ($rgb['green'] \u003e 128) ? 255 : 128;\n$b = ($rgb['blue'] \u003e 128) ? 255 : 128;\nreturn [$r, $g, $b];\n}\n\n$closure = \\Closure::fromCallable('personnal');\n$lut = (new LookUpTableFilter())-\u003ecreate((new LookUpTable())-\u003ecreate($closure))-\u003eprocess((new Image())-\u003eload($stream))-\u003esrc();\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasygithdev%2Feasygd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feasygithdev%2Feasygd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feasygithdev%2Feasygd/lists"}