diff --git a/.gitignore b/.gitignore index bdd5ccd..fbeee8f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,12 +6,12 @@ examples/*.gif tmp/ .tmp/ composer.phar -composer.lock composer-test.lock build/artifacts/ artifacts/ docs/_build docs/*.pyc +*.log .idea .DS_STORE .DS_Store diff --git a/.travis.yml b/.travis.yml index 1741e9f..066a61f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,19 +3,28 @@ sudo: false language: php php: - - 5.5 - - 5.6 - - 7.0 - - 7.1 - - hhvm - -matrix: - allow_failures: - - php: hhvm - - fast_finish: true - -install: travis_retry composer install --no-interaction --prefer-source + - 7.0 + - 7.0snapshot + - 7.1 + - 7.1snapshot + - master + +cache: + directories: + - $HOME/.composer/cache/files + +env: + matrix: + - DEPENDENCIES="high" + - DEPENDENCIES="low" + +before_install: + - composer self-update + - composer clear-cache + +install: + - if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest --optimize-autoloader --prefer-stable; fi + - if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest --optimize-autoloader --prefer-stable --prefer-lowest; fi script: make test diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..29d3409 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,88 @@ +# Change Log +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + +## [Unreleased] +### Added +- Feature: `isEllipse()` method support in `Figure` for create ellipses. +- Feature: `isRectangle()` method support in `Figure` for create rectangles. +- `CHANGELOG.md` file. + +### Changed +- `Figure` elements are `PNG` by default. +- Support for `PHP >= 7.0.x` only. +- Update PHPUnit 6.0. +- Update test suite. +- Update README.md. +- Update LICENSE.md. +- Preserve `composer.lock` files. +- Codebase with doc-comments. +- Codebase more standard: `phpcs ./src --standard=PSR2` and `phpcbf -w ./src --standard=PSR2` + +### Fixed +- Better support for `Figure` elements with opacity. (0 to 127) +- Better support for `$image->load(..)` method when load image from path or URL. + +### Removed +- Guzzle dependency removed. + +### Deprecated +- GImage is no longer supported on `PHP <= 5.5` + +## [2.0.1] - 2016-10-20 +### Changed +- Codebase PSR-2 standard. + +### Fixed +- Minor travis fixes. + +## [2.0.0] - 2016-09-29 +### Added +- Codebase with new syntax and namespaces. +- Codebase are now namespaced (`\GImage`). +- Sources clases was renamed to `Image`, `Figure`, `Text`, `Canvas` and `Utils`. + +### Changed +- Make file tests. +- Travis with PHP `7.0` and `7.1`. +- Support for `PHP >= 5.5` + +### Removed +- Cleanup some files. + +### Deprecated +- GImage is no longer supported on `PHP <= 5.3` + +## [1.5.2] - 2016-07-20 +### Added +- Composer suggest package. + +### Changed +- Examples updated. + +## [1.5.1] - 2016-01-12 +### Added +- Support line-height for `GText` class. +Example: +```php +setLineHeight(1.2); +``` +- Composer support. +- API docs. +- Composer badges. + +## [1.5.0] - 2015-11-15 +### Added +- Initial commit. +- PHP `5.3` support. + +[Unreleased]: https://github.com/joseluisq/gimage/compare/v2.0.1...HEAD +[2.0.1]: https://github.com/joseluisq/gimage/compare/v2.0.0...v2.0.1 +[2.0.0]: https://github.com/joseluisq/gimage/compare/v1.5.2...v2.0.0 +[1.5.2]: https://github.com/joseluisq/gimage/compare/v1.5.1...v1.5.2 +[1.5.1]: https://github.com/joseluisq/gimage/compare/v1.5.0...v1.5.1 +[1.5.0]: https://github.com/joseluisq/gimage/tree/1.5.0 diff --git a/license.md b/LICENSE.md similarity index 94% rename from license.md rename to LICENSE.md index 2258754..abbb796 100644 --- a/license.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2016 José Luis Quintana +Copyright (c) 2017 José Luis Quintana Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/readme.md b/README.md similarity index 55% rename from readme.md rename to README.md index 761e748..40bac79 100644 --- a/readme.md +++ b/README.md @@ -2,13 +2,25 @@ [![Build Status](https://travis-ci.org/joseluisq/gimage.svg?branch=master)](https://travis-ci.org/joseluisq/gimage) [![Latest Stable Version](https://poser.pugx.org/joseluisq/gimage/version)](https://packagist.org/packages/joseluisq/gimage) [![Latest Unstable Version](https://poser.pugx.org/joseluisq/gimage/v/unstable)](//packagist.org/packages/joseluisq/gimage) [![Total Downloads](https://poser.pugx.org/joseluisq/gimage/downloads)](https://packagist.org/packages/joseluisq/gimage) [![License](https://poser.pugx.org/joseluisq/gimage/license)](https://packagist.org/packages/joseluisq/gimage) -> A simple PHP library for easy image handling. - -GImage is a simple extended library based on [PHP Image Processing and GD](http://php.net/manual/en/book.image.php) for easy image handling. With GImage you can read, create, crop, resize, rotate, embed text, merge and save your JPG or PNG images easy. GImage require **PHP 5.5** or later and [GD Extension](http://php.net/manual/en/book.image.php). +> A PHP library for easy image handling. ![A simple presentation card with GImage](https://cloud.githubusercontent.com/assets/1700322/18941713/eed7fa34-85d8-11e6-8033-bf787e4aa236.png) -[*View sample code*](#creating-a-simple-presentation-card) +_* Presentation card - [view sample code](#creating-a-simple-presentation-card)_ + +__GImage__ is a simple extended library based on [PHP Image Processing and GD](http://php.net/manual/en/book.image.php) for processing images without stress. For example: +- Load a image from local path or URL. +- Create figures like a rectangles or ellipses with opacity. +- Rotate and crop (proportionally). +- Resize and scale proportionally. +- Embed text with custom TTF fonts. +- Compose a pool of images with Canvas. +- Swap image formats like JPG, PNG and GIF. +- Save file or output on browser. +- Save several copies of an image. + +## Requirements +GImage requires **[PHP 7.x](http://php.net/manual/en/migration70.new-features.php)** and latest [GD Extension](http://php.net/manual/en/book.image.php). ## Install @@ -18,9 +30,11 @@ composer require joseluisq/gimage ## Usage -### Basic +For more examples check out the [./examples](./examples) dir. -Working with external JPG image and output on browser as PNG format. +#### Image + +Working with an external JPG image and output it on browser as PNG format: ```php output(); ``` -### Using a Figure +#### Figure -Creating a simple green rectangle. +Creating a green ellipse: ```php isEllipse() + // Setting a green RGB color ->setBackgroundColor(170, 188, 147) // Creating the figure ->create() - // Outputting JPG image (by default) on the browser. + // Outputting image (PNG Figure by default) on the browser. ->output(); ``` -### Creating a simple presentation card -Creating a simple presentation card with Image, Canvas, Figure and GText. +#### Text + +Creating a rectangle with Text embedded: + +```php +isRectangle() + ->setBackgroundColor(47, 42, 39) + ->create(); + +$text = new Text('My awesome text!'); +$text + ->setWidth(400) + ->setHeight(250) + ->setLineHeight(1.2) + ->setAlign('center') + ->setValign('center') + ->setSize(22) + ->setColor(255, 255, 255) + ->setFontface('./fonts/Lato-Bol.ttf'); + +$canvas = new Canvas($figure); +$canvas + ->append($text) + ->toPNG() + ->draw() + ->save('./text.png'); +``` + +#### Creating a simple presentation card +Presentation card example using `Image`, `Canvas`, `Figure` and `Text`. ```php load('http://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?s=100.jpg') ->setTop(60) ->setLeft(70); -$about_text = new GText("MY AWESOME PRESENTATION CARD GENERATED WITH GIMAGE"); +$about_text = new Text("MY AWESOME PRESENTATION CARD GENERATED WITH GIMAGE"); $about_text ->setSize(16) ->setWidth(300) @@ -91,7 +143,7 @@ $about_text ->setColor(204, 164, 116) ->setFontface('fonts/Lato-Light.ttf'); -$twitter_text = new GText('@username'); +$twitter_text = new Text('@username'); $twitter_text ->setSize(11) ->setWidth(70) @@ -100,12 +152,12 @@ $twitter_text ->setColor(130, 127, 125) ->setFontface('fonts/Lato-Regular.ttf'); -$canvas_figure = new GFigure(550, 250); +$canvas_figure = new Figure(550, 250); $canvas_figure ->setBackgroundColor(47, 42, 39) ->create(); -$avatar_box = new GFigure($avatar_image->getWidth() + 16, $avatar_image +$avatar_box = new Figure($avatar_image->getWidth() + 16, $avatar_image ->getHeight() + 17); $avatar_box ->setBackgroundColor(63, 56, 52) @@ -113,7 +165,7 @@ $avatar_box ->setTop($avatar_image->getTop() - 8) ->create(); -$avatar_box2 = new GFigure($avatar_image->getWidth() + 3, $avatar_image +$avatar_box2 = new Figure($avatar_image->getWidth() + 3, $avatar_image ->getHeight() + 19); $avatar_box2 ->setBackgroundColor(79, 72, 67) @@ -121,26 +173,25 @@ $avatar_box2 ->setTop($avatar_image->getTop() - 9) ->create(); -$avatar_box3 = new GFigure(120, 240); +$avatar_box3 = new Figure(120, 240); $avatar_box3 ->setBackgroundColor(63, 56, 52) ->create(); -$line_vertical = new GFigure(600, 10); +$line_vertical = new Figure(600, 10); $line_vertical ->setBackgroundColor(119, 99, 77) ->setTop(240) ->create(); -$line_horizontal = new GFigure(1, 240); +$line_horizontal = new Figure(1, 240); $line_horizontal ->setBackgroundColor(79, 72, 67) ->setLeft(120) ->create(); -$canvas = new GCanvas(); +$canvas = new Canvas($canvas_figure); $canvas - ->from($canvas_figure) ->append([ $line_horizontal, $avatar_box2, @@ -153,16 +204,19 @@ $canvas ]) ->toPNG() ->draw() - ->save('card.png'); + ->save('./card.png'); ``` -## Contribution -If you would like to contribute [pull requests](https://github.com/joseluisq/gimage/pulls) and [issues](https://github.com/joseluisq/gimage/issues) will be welcome! Feature requests are welcome. Please before sending some feature requests make sure provide as much detail and context as possible. +## Changelog +Check out the [CHANGELOG.md](./CHANGELOG.md) file. ## Documentation Read [API Documentation](http://joseluisq.github.io/gimage/#documentation) +## Contribution +If you would like to contribute [pull requests](https://github.com/joseluisq/gimage/pulls) and [issues](https://github.com/joseluisq/gimage/issues) will be welcome! Feature requests are welcome. Please before sending some feature requests make sure provide as much detail and context as possible. + ## License MIT license -© 2016 [José Luis Quintana](https://git.io/joseluisq) +© 2017 [José Luis Quintana](https://git.io/joseluisq) diff --git a/composer.json b/composer.json index 06a1963..2b0bf2c 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "joseluisq/gimage", - "description": "A simple PHP library for easy image handling.", + "description": "A PHP library for easy image handling.", "type": "library", "license": "MIT", "keywords": [ @@ -10,6 +10,8 @@ "jpg", "jpeg", "resize", + "ellipse", + "rectangle", "crop", "file", "save", @@ -24,11 +26,15 @@ "issues": "https://github.com/joseluisq/gimage/issues" }, "require": { - "php": ">=5.5", - "guzzlehttp/psr7": "^1.3.1" + "php": "^7.0" + }, + "config": { + "platform": { + "php": "7.0.0" + } }, "require-dev": { - "phpunit/phpunit": "^4.0" + "phpunit/phpunit": "^6.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..634c8c8 --- /dev/null +++ b/composer.lock @@ -0,0 +1,1273 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "845a3d6250af7872ec08850f9be21d1e", + "content-hash": "cf110c6cb52baf6e0283428c0fa42690", + "packages": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-06-14 21:17:01" + }, + { + "name": "myclabs/deep-copy", + "version": "1.6.0", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "5a5a9fc8025a08d8919be87d6884d5a92520cefe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/5a5a9fc8025a08d8919be87d6884d5a92520cefe", + "reference": "5a5a9fc8025a08d8919be87d6884d5a92520cefe", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "doctrine/collections": "1.*", + "phpunit/phpunit": "~4.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "homepage": "https://github.com/myclabs/DeepCopy", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2017-01-26 22:05:40" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-12-27 11:43:31" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/type-resolver": "^0.2.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2016-09-30 07:12:33" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.2.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2016-11-25 06:54:22" + }, + { + "name": "phpspec/prophecy", + "version": "v1.6.2", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "6c52c2722f8460122f96f86346600e1077ce22cb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/6c52c2722f8460122f96f86346600e1077ce22cb", + "reference": "6c52c2722f8460122f96f86346600e1077ce22cb", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", + "sebastian/comparator": "^1.1", + "sebastian/recursion-context": "^1.0|^2.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.0", + "phpunit/phpunit": "^4.8 || ^5.6.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2016-11-21 14:58:47" + }, + { + "name": "phpunit/php-code-coverage", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "e7d7a4acca58e45bdfd00221563d131cfb04ba96" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/e7d7a4acca58e45bdfd00221563d131cfb04ba96", + "reference": "e7d7a4acca58e45bdfd00221563d131cfb04ba96", + "shasum": "" + }, + "require": { + "php": "^7.0", + "phpunit/php-file-iterator": "^1.3", + "phpunit/php-text-template": "^1.2", + "phpunit/php-token-stream": "^1.4.2", + "sebastian/code-unit-reverse-lookup": "^1.0", + "sebastian/environment": "^2.0", + "sebastian/version": "^2.0" + }, + "require-dev": { + "ext-xdebug": "^2.5", + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-dom": "*", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2017-02-02 10:35:41" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2016-10-03 07:40:28" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21 13:50:34" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/38e9124049cf1a164f1e4537caf19c99bf1eb260", + "reference": "38e9124049cf1a164f1e4537caf19c99bf1eb260", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4|~5" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2016-05-12 18:03:57" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3b402f65a4cc90abf6e1104e388b896ce209631b", + "reference": "3b402f65a4cc90abf6e1104e388b896ce209631b", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2016-11-15 14:06:22" + }, + { + "name": "phpunit/phpunit", + "version": "6.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "e702506af102d0dc5312dd24b8e97fd6e58ce3ba" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e702506af102d0dc5312dd24b8e97fd6e58ce3ba", + "reference": "e702506af102d0dc5312dd24b8e97fd6e58ce3ba", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "^1.3", + "php": "^7.0", + "phpspec/prophecy": "^1.6.2", + "phpunit/php-code-coverage": "^5.0", + "phpunit/php-file-iterator": "^1.4", + "phpunit/php-text-template": "^1.2", + "phpunit/php-timer": "^1.0.6", + "phpunit/phpunit-mock-objects": "^4.0", + "sebastian/comparator": "^1.2.4", + "sebastian/diff": "^1.2", + "sebastian/environment": "^2.0", + "sebastian/exporter": "^2.0", + "sebastian/global-state": "^1.1", + "sebastian/object-enumerator": "^2.0", + "sebastian/resource-operations": "^1.0", + "sebastian/version": "^2.0" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2", + "phpunit/dbunit": "<3.0" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-xdebug": "*", + "phpunit/php-invoker": "^1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2017-02-08 05:57:26" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "3819745c44f3aff9518fd655f320c4535d541af7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/3819745c44f3aff9518fd655f320c4535d541af7", + "reference": "3819745c44f3aff9518fd655f320c4535d541af7", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^2.0" + }, + "conflict": { + "phpunit/phpunit": "<6.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2017-02-02 10:36:38" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/c36f5e7cfce482fde5bf8d10d41a53591e0198fe", + "reference": "c36f5e7cfce482fde5bf8d10d41a53591e0198fe", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2016-02-13 06:45:14" + }, + { + "name": "sebastian/comparator", + "version": "1.2.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2 || ~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2017-01-29 09:50:25" + }, + { + "name": "sebastian/diff", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", + "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2015-12-08 07:14:41" + }, + { + "name": "sebastian/environment", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2016-11-26 07:53:53" + }, + { + "name": "sebastian/exporter", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2016-11-19 08:54:04" + }, + { + "name": "sebastian/global-state", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2015-10-12 03:26:01" + }, + { + "name": "sebastian/object-enumerator", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35", + "reference": "96f8a3f257b69e8128ad74d3a7fd464bcbaa3b35", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2016-11-19 07:35:10" + }, + { + "name": "sebastian/recursion-context", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2016-11-19 07:33:16" + }, + { + "name": "sebastian/resource-operations", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28 20:34:47" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03 07:35:21" + }, + { + "name": "webmozart/assert", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2016-11-23 20:04:58" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.5" + }, + "platform-dev": [] +} diff --git a/examples/_config.php b/examples/_config.php index 4b26411..a392e3e 100644 --- a/examples/_config.php +++ b/examples/_config.php @@ -1,4 +1,12 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ define('BASE_PATH', dirname(__FILE__)); define('ROOT_PATH', dirname(BASE_PATH)); diff --git a/examples/card.php b/examples/card.php index 30dc6b6..5352115 100644 --- a/examples/card.php +++ b/examples/card.php @@ -1,7 +1,17 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ /** - * Creating a Presentation Card + * Creating a Presentation Card. + * + * @author José Luis Quintana */ namespace GImage\Examples; @@ -76,18 +86,17 @@ ->setLeft(120) ->create(); -$canvas = new Canvas(); +$canvas = new Canvas($canvas_figure); $canvas - ->from($canvas_figure) ->append([ - $line_horizontal, - $avatar_box2, - $avatar_box3, - $avatar_box, - $avatar_image, - $about_text, - $twitter_text, - $line_vertical + $line_horizontal, + $avatar_box2, + $avatar_box3, + $avatar_box, + $avatar_image, + $about_text, + $twitter_text, + $line_vertical ]) ->toPNG() ->draw() diff --git a/examples/crop.php b/examples/crop.php index 0507496..54bf677 100644 --- a/examples/crop.php +++ b/examples/crop.php @@ -1,7 +1,17 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ /** - * Creating a Presentation Card + * Crop an image. + * + * @author Jose Luis Quintana */ namespace GImage\Examples; diff --git a/examples/ellipse.php b/examples/ellipse.php new file mode 100644 index 0000000..b90258e --- /dev/null +++ b/examples/ellipse.php @@ -0,0 +1,31 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Creating an Elipse. + * + * @author Jose Luis Quintana + */ + +namespace GImage\Examples; + +use GImage\Text; +use GImage\Figure; + +require __DIR__ . '/_config.php'; +require __DIR__ . '/../tests/bootstrap.php'; + +$figure = new Figure(300, 200); +$figure + ->isEllipse() + ->setBackgroundColor(255, 0, 0) + ->setOpacity(35) + ->create() + ->save(__DIR__ . '/ellipse.png'); diff --git a/examples/rectangle.php b/examples/rectangle.php new file mode 100644 index 0000000..34e3f77 --- /dev/null +++ b/examples/rectangle.php @@ -0,0 +1,34 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Creating a Rectangle. + * + * @author Jose Luis Quintana + */ + +namespace GImage\Examples; + +use GImage\Text; +use GImage\Figure; +use GImage\Canvas; + +require __DIR__ . '/_config.php'; +require __DIR__ . '/../tests/bootstrap.php'; + +// Tip: By default a Figure is a rectangle + +$figure = new Figure(400, 250); +$figure + ->isRectangle() + ->setBackgroundColor(0, 0, 255) + ->setOpacity(50) + ->create() + ->save(__DIR__ . '/reactangle.png'); diff --git a/examples/rotate.php b/examples/rotate.php index 81f69ce..ec927e9 100644 --- a/examples/rotate.php +++ b/examples/rotate.php @@ -1,7 +1,17 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ /** - * Rotate an image + * Rotate an image. + * + * @author Jose Luis Quintana */ namespace GImage\Examples; diff --git a/examples/text.php b/examples/text.php index 9830d32..ce8471d 100644 --- a/examples/text.php +++ b/examples/text.php @@ -1,7 +1,17 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ /** - * Creating Canvas with Text + * Creating Canvas with Text. + * + * @author Jose Luis Quintana */ namespace GImage\Examples; @@ -18,7 +28,7 @@ ->setBackgroundColor(47, 42, 39) ->create(); -$text = new Text('Output PNG .'); +$text = new Text('Output PNG Text!'); $text ->setWidth(400) ->setHeight(250) diff --git a/src/Canvas.php b/src/Canvas.php index 67f8062..ba24a23 100644 --- a/src/Canvas.php +++ b/src/Canvas.php @@ -1,4 +1,12 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace GImage; @@ -7,21 +15,25 @@ /** * A Canvas represents a rectangular image area on which one can draw images. + * * @package GImage - * @access public - * @version 2.0.0 - * @author José Luis Quintana - * @license https://github.com/joseluisq/gimage/blob/master/license.md - * @property array $list An array of elements (Image, Figure or Text classes) - * @link Github https://github.com/joseluisq/gimage + * @author Jose Luis Quintana + * + * @property array $elementList An array of elements (Image, Figure or Text classes). */ class Canvas extends Image { - private $list = []; + /** + * List of elements. + * + * @var array + */ + private $elementList = []; /** * Constructs a new Canvas. - * @param mixed $element Only Image or Figure class + * + * @param mixed $element Only Image or Figure class. * @access public * @return void */ @@ -32,9 +44,10 @@ public function __construct($element = null) /** * Adds one or more elements to canvas. + * * @param mixed $elements Single or array of Image, Figure, Text classes. * @access public - * @return void + * @return \GImage\Canvas */ public function append($elements) { @@ -43,7 +56,7 @@ public function append($elements) foreach ($elements as $element) { if ($element instanceof Image || $element instanceof Text) { - $this->list[] = $element; + $this->elementList[] = $element; } } } @@ -53,51 +66,22 @@ public function append($elements) /** * Draws the canvas. + * * @access public - * @return void + * @return \GImage\Canvas */ public function draw() { $canvas = $this->resource; if ($canvas) { - $list = $this->list; - - foreach ($list as $element) { + foreach ($this->elementList as $element) { if ($element instanceof Image) { - $simage = $element->getResource(); - imagecopyresampled($canvas, $simage, $element->getLeft(), $element->getTop(), $element->getBoxLeft(), $element->getBoxTop(), $element->getBoxWidth(), $element->getBoxHeight(), $element->getWidth(), $element->getHeight()); - } else { - if ($element instanceof Text) { - $rgbColor = $element->getColor(); - $color = imagecolorallocatealpha($canvas, $rgbColor[0], $rgbColor[1], $rgbColor[2], $element->getOpacity()); - - $linesStr = $element->wrappText(); - $cords = $element->calculateTextBox($element->getSize(), $element->getAngle(), $element->getFontface(), $element->getString()); - - // Alignment - $x = $cords['left'] + $element->getLeft(); - $y = $element->getTop() + $cords['top']; - - if ($element->getAlign() == 'center') { - $x = ($element->getWidth() - $cords['width']) / 2; - } - - if ($element->getValign() == 'center') { - $y = ($element->getHeight() - $cords['height']) / 2; - } - - // Line height - $line_height = $element->getLineHeight() * $element->getSize(); - $size = $element->getSize(); - $angle = $element->getAngle(); - $font = $element->getFontface(); - - foreach ($linesStr as $i => $lineStr) { - $ny = $y + ($line_height * $i); - imagettftext($canvas, $size, $angle, $x, $ny, $color, $font, $lineStr); - } - } + $this->drawImage($element, $canvas); + } + + if ($element instanceof Text) { + $this->drawText($element, $canvas); } } @@ -105,10 +89,67 @@ public function draw() } else { throw new \Exception('' . 'Image or Figure class is not assigned. ' - . 'You can do it using the "Canvas->from($element)" method.' + . 'E.g. "new Canvas($image_or_figure)"' . ''); } return $this; } + + /** + * Draw the an Image or Figure element. + * + * @param \GImage\Image|\GImage\Figure $element Image or Figure element. + * @return void + */ + private function drawImage($element, $canvas) + { + $image = $element->getResource(); + + imagecopyresampled( + $canvas, + $image, + $element->getLeft(), + $element->getTop(), + $element->getBoxLeft(), + $element->getBoxTop(), + $element->getBoxWidth(), + $element->getBoxHeight(), + $element->getWidth(), + $element->getHeight() + ); + } + + /** + * Draw an Text element. + * + * @param \GImage\Text $text Text element. + * @return void + */ + private function drawText(Text $text, $canvas) + { + list($red, $green, $blue) = $text->getColor(); + + $color = imagecolorallocatealpha( + $canvas, + $red, + $green, + $blue, + $text->getOpacity() + ); + + $size = $text->getSize(); + $angle = $text->getAngle(); + $font = $text->getFontface(); + $lineHeight = $text->getLineHeight() * $text->getSize(); + + list($x, $y) = $text->getCords(); + + $lines = $text->wrappText(); + + foreach ($lines as $i => $line) { + $ny = $y + ($lineHeight * $i); + imagettftext($canvas, $size, $angle, $x, $ny, $color, $font, $line); + } + } } diff --git a/src/Figure.php b/src/Figure.php index 1d89d25..d00c6ab 100644 --- a/src/Figure.php +++ b/src/Figure.php @@ -1,4 +1,12 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace GImage; @@ -7,15 +15,13 @@ /** * Class to embed simple graphic into the Canvas. * A Figure can be a Canvas too. + * * @package GImage - * @access public - * @version 0.0.0 - * @author José Luis Quintana - * @license https://github.com/joseluisq/gimage/blob/master/license.md + * @author Jose Luis Quintana + * * @property int $red Red color * @property int $green Green color * @property int $blue Blue color - * @link Github https://github.com/joseluisq/gimage */ class Figure extends Image { @@ -24,77 +30,144 @@ class Figure extends Image protected $red = 0; protected $green = 0; protected $blue = 0; + protected $figureType = 'rectangle'; /** * Sets size for figure. + * * @access public * @param int $width Width. * @param int $height Height. * @return void */ - public function __construct($width = 0, $height = 0) - { - $this->setSize($width, $height); + public function __construct($width = 0, $height = 0) + { + $this->setSize($width, $height); + $this->toPNG(); - parent::__construct(); - } + parent::__construct(); + } /** * Sets size to figure. + * * @access public * @param int $width Width. * @param int $height Height. - * @return void + * @return \GImage\Figure */ - public function setSize($width = 0, $height = 0) - { - if (!empty($width) && !empty($height)) { - $this->width = $this->boxWidth = $width; - $this->height = $this->boxHeight = $height; - } + public function setSize($width = 0, $height = 0) + { + if (!empty($width) && !empty($height)) { + $this->width = $this->boxWidth = $width; + $this->height = $this->boxHeight = $height; + } + + return $this; + } - return $this; - } + /** + * Sets the figure type as 'rectangle'. + * + * @access public + * @return \GImage\Figure + */ + public function isRectangle() + { + $this->figureType = 'rectangle'; + return $this; + } + + /** + * Sets the figure type as 'ellipse'. + * + * @access public + * @return \GImage\Figure + */ + public function isEllipse() + { + $this->figureType = 'ellipse'; + return $this; + } /** * Sets background color. + * * @access public * @param int $red Red. * @param int $green Green. * @param int $blue Blue. - * @return void + * @return \GImage\Figure */ - public function setBackgroundColor($red, $green, $blue) - { - $this->red = $red; - $this->green = $green; - $this->blue = $blue; - - return $this; - } + public function setBackgroundColor($red, $green, $blue) + { + $this->red = $red; + $this->green = $green; + $this->blue = $blue; + return $this; + } /** * Sets background color. + * * @access public - * @return void + * @return array An array with RGB colors. */ - public function getBackgroundColor() - { - return [$this->red, $this->green, $this->blue]; - } + public function getBackgroundColor() + { + return [$this->red, $this->green, $this->blue]; + } /** - * Creates the figure. + * Creates the figure with alpha channel. + * * @access public - * @return void + * @return \GImage\Figure */ - public function create() - { - $figure = imagecreatetruecolor($this->width, $this->height); - $color = imagecolorallocatealpha($figure, $this->red, $this->green, $this->blue, $this->opacity); - imagefilledrectangle($figure, 0, 0, $this->width, $this->height, $color); - $this->resource = $figure; - - return $this; - } + public function create() + { + $figure = imagecreatetruecolor($this->width, $this->height); + imagesavealpha($figure, true); + + $color = imagecolorallocatealpha( + $figure, + $this->red, + $this->green, + $this->blue, + $this->opacity + ); + + $alpha = imagecolorallocatealpha($figure, 255, 255, 255, 127); + + imagefill($figure, 0, 0, $alpha); + imagefill($figure, $this->width - 1, 0, $alpha); + imagefill($figure, 0, $this->height - 1, $alpha); + imagefill($figure, $this->width - 1, $this->height - 1, $alpha); + + if ($this->figureType == 'rectangle') { + imagefilledrectangle( + $figure, + 0, + 0, + $this->width, + $this->height, + $color + ); + } + + + if ($this->figureType == 'ellipse') { + imagefilledellipse( + $figure, + $this->width / 2, + $this->height / 2, + $this->width, + $this->height, + $color + ); + } + + $this->resource = $figure; + return $this; + } } diff --git a/src/Image.php b/src/Image.php index 92b7315..61748fa 100644 --- a/src/Image.php +++ b/src/Image.php @@ -1,16 +1,24 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace GImage; use GImage\Utils; /** - * A simple extended GD class for easy image handling. This is the parent class for GFigure and GCanvas. + * A simple extended GD class for easy image handling. + * This is the parent class for Figure and Canvas. + * * @package GImage - * @access public - * @version 2.0.0 * @author José Luis Quintana - * @license https://github.com/joseluisq/gimage/blob/master/license.md + * * @property string $name * @property string $filename * @property int $width @@ -29,7 +37,6 @@ * @property string $from Default 'local' * @property bool $preserve Default FALSE * @property string $mimetype Default 'image/jpeg' - * @link Github https://github.com/joseluisq/gimage */ class Image { @@ -54,6 +61,7 @@ class Image /** * Loads an image from Image or Figure class. + * * @package GImage * @access public * @param Image $element Image or Figure class. @@ -66,9 +74,10 @@ public function __construct($element = null) /** * Loads an image from Image or Figure class. + * * @access public * @param Image $element Image or Figure class. - * @return void + * @return \GImage\Image */ public function from($element = null) { @@ -98,62 +107,130 @@ public function from($element = null) /** * Loads an image from local o external path. + * * @package GImage * @access public * @param string $filename Path or url of image. - * @return bool + * @return \GImage\Image */ public function load($filename) { $image = null; - if (!empty($filename)) { - $this->filename = $filename; - $this->name = basename($filename); - - if (filter_var($filename, FILTER_VALIDATE_URL)) { - $image = file_get_contents($filename); - - if (!empty($image)) { - $this->from = 'external'; - $this->resource = $image = imagecreatefromstring($image); - $this->type = Utils::getImageType($filename); - $this->extension = Utils::getExtension($filename); - $this->width = $this->boxWidth = imagesx($image); - $this->height = $this->boxHeight = imagesy($image); - } - } else { - if (is_file($filename)) { - $this->from = 'local'; - $this->type = $imageType = Utils::getImageType($filename); - $this->extension = Utils::getExtension($filename); - - switch ($imageType) { - case IMAGETYPE_GIF: - $image = imagecreatefromgif($filename); - break; - - case IMAGETYPE_PNG: - $image = imagecreatefrompng($filename); - break; - - case IMAGETYPE_JPEG: - $image = imagecreatefromjpeg($filename); - break; - } - - $this->resource = $image; - $this->width = $this->boxWidth = imagesx($image); - $this->height = $this->boxHeight = imagesy($image); - } - } + if (empty($filename)) { + return $this; + } + + if (filter_var($filename, FILTER_VALIDATE_URL)) { + $this->loadFromURL($filename); + } elseif (is_file($filename)) { + $this->loadFromFile($filename); } return $this; } + /** + * Load an Image from URL. + * + * @param string $url Image URL + * @return void + */ + private function loadFromURL($url) + { + $image = $this->fetchImageContentFromURL($url); + + if (empty($image)) { + return; + } + + if (Utils::isJPGResource($image)) { + $this->filename = $url; + $this->extension = 'jpg'; + $this->type = IMAGETYPE_JPEG; + } + + if (Utils::isPNGResource($image)) { + $this->filename = $url; + $this->extension = 'png'; + $this->type = IMAGETYPE_PNG; + } + + if (!empty($this->filename)) { + $this->from = 'external'; + $this->resource = imagecreatefromstring($image); + $this->width = $this->boxWidth = imagesx($this->resource); + $this->height = $this->boxHeight = imagesy($this->resource); + } + } + + /** + * Fetch an image string content from URL. + * + * @param string $url Image URL. + * @return String String Data + */ + private function fetchImageContentFromURL($url) + { + $data = null; + + if ($stream = fopen($url, 'r')) { + $data = stream_get_contents($stream); + fclose($stream); + } + + return $data; + } + + /** + * Load an image file from path. + * + * @param string $filepath File path + * @return void + */ + private function loadFromFile($filepath) + { + $this->from = 'local'; + $this->filename = $filepath; + + + if (!is_readable($filepath)) { + return; + } + + $image = null; + $extension = ''; + list($width, $height, $imageType) = getimagesize($filepath); + + switch ($imageType) { + case IMAGETYPE_GIF: + $extension = 'gif'; + $image = imagecreatefromgif($filepath); + break; + + case IMAGETYPE_PNG: + $extension = 'png'; + $image = imagecreatefrompng($filepath); + break; + + case IMAGETYPE_JPEG: + $extension = 'jpg'; + $image = imagecreatefromjpeg($filepath); + break; + } + + if ($image) { + $this->type = $info[2]; + $this->resource = $image; + $this->extension = $extension; + $this->width = $this->boxWidth = $width; + $this->height = $this->boxHeight = $height; + } + } + /** * Gets resource of image. + * * @access public * @return resource */ @@ -164,6 +241,7 @@ public function getResource() /** * Gets filename path of image. + * * @access public * @return string */ @@ -193,7 +271,8 @@ public function getType() } /** - * Gets extension (jpg, png or gif) + * Gets extension (jpg, png or gif). + * * @access public * @return string */ @@ -204,6 +283,7 @@ public function getExtension() /** * Gets quality. + * * @access public * @return int */ @@ -214,6 +294,7 @@ public function getQuality() /** * Gets opacity. + * * @access public * @return int */ @@ -224,6 +305,7 @@ public function getOpacity() /** * Gets height. + * * @access protected * @return int */ @@ -234,6 +316,7 @@ public function getWidth() /** * Gets width. + * * @access public * @return int */ @@ -244,6 +327,7 @@ public function getHeight() /** * Gets top position. + * * @access protected * @return int */ @@ -254,6 +338,7 @@ public function getTop() /** * Gets left position. + * * @access public * @return int */ @@ -264,6 +349,7 @@ public function getLeft() /** * Gets box left position. + * * @access public * @return int */ @@ -274,6 +360,7 @@ public function getBoxLeft() /** * Gets box top position. + * * @access protected * @return int */ @@ -284,6 +371,7 @@ public function getBoxTop() /** * Gets box width. + * * @access public * @return int */ @@ -294,6 +382,7 @@ public function getBoxWidth() /** * Gets box height. + * * @access public * @return int */ @@ -304,6 +393,7 @@ public function getBoxHeight() /** * Gets of from it was loaded the image 'local' or 'external' path. + * * @access public * @return string */ @@ -314,9 +404,10 @@ public function getLoadedFrom() /** * Sets quality for image. + * * @param int $quality Quality value from 0 to 100 * @access public - * @return void + * @return \GImage\Image */ public function setQuality($quality) { @@ -326,9 +417,10 @@ public function setQuality($quality) /** * Sets opacity. + * * @param int $opacity Opacity value from 0 to 127 * @access public - * @return void + * @return \GImage\Image */ public function setOpacity($opacity) { @@ -338,9 +430,10 @@ public function setOpacity($opacity) /** * Sets image resource. + * * @param resource $resource resource. * @access public - * @return void + * @return \GImage\Image */ public function setResource($resource) { @@ -350,9 +443,10 @@ public function setResource($resource) /** * Sets left position of image. + * * @param int $x left. * @access public - * @return void + * @return \GImage\Image */ public function setLeft($x) { @@ -362,9 +456,10 @@ public function setLeft($x) /** * Sets top position of image. + * * @param int $y top. * @access public - * @return void + * @return \GImage\Image */ public function setTop($y) { @@ -374,9 +469,10 @@ public function setTop($y) /** * Sets width of box image. + * * @param int $width width. * @access public - * @return void + * @return \GImage\Image */ public function setBoxWidth($width) { @@ -386,9 +482,10 @@ public function setBoxWidth($width) /** * Sets height of box image. + * * @param int $height height. * @access public - * @return void + * @return \GImage\Image */ public function setBoxHeight($height) { @@ -398,9 +495,10 @@ public function setBoxHeight($height) /** * Sets left position of box image. + * * @param int $x Left position. * @access public - * @return void + * @return \GImage\Image */ public function setBoxLeft($x) { @@ -410,9 +508,10 @@ public function setBoxLeft($x) /** * Sets top position of box image. + * * @param int $y Top position. * @access public - * @return void + * @return \GImage\Image */ public function setBoxTop($y) { @@ -422,6 +521,7 @@ public function setBoxTop($y) /** * Checks if image was loaded from local path. + * * @access public * @return bool */ @@ -432,6 +532,7 @@ public function isLocal() /** * Checks if image was loaded from external url. + * * @access public * @return bool */ @@ -442,6 +543,7 @@ public function isExternal() /** * Checks if image is a JPG. + * * @access public * @return bool */ @@ -452,6 +554,7 @@ public function isJPG() /** * Checks if image is a PNG. + * * @access public * @return bool */ @@ -462,6 +565,7 @@ public function isPNG() /** * Checks if image is a GIF. + * * @access public * @return bool */ @@ -471,64 +575,66 @@ public function isGIF() } /** - * Changes output format to JPG + * Changes output format to JPG. + * * @access public - * @return void + * @return \GImage\Image */ public function toJPG() { $this->extension = 'jpg'; $this->type = IMAGETYPE_JPEG; $this->mimetype = Utils::getMimetypeByImageType(IMAGETYPE_JPEG); - return $this; } /** - * Changes output format to PNG + * Changes output format to PNG. + * * @access public - * @return void + * @return \GvoidvoidvoidImage\Imagevoidvoidvoid */ public function toPNG() { $this->extension = 'png'; $this->type = IMAGETYPE_PNG; $this->mimetype = Utils::getMimetypeByImageType(IMAGETYPE_PNG); - return $this; } /** - * Changes output format to GIT. + * Changes output format to GIF. + * * @access public - * @return void + * @return \GImage\Image */ public function toGIF() { $this->extension = 'gif'; $this->type = IMAGETYPE_GIF; $this->mimetype = Utils::getMimetypeByImageType(IMAGETYPE_GIF); - return $this; } /** * Preserves the resource image when save or output function is called. + * * @access public * @param bool $preserve If it's true will preserve the resource image. - * @return void + * @return \GImage\Image */ public function preserve($preserve = true) { $this->preserve = $preserve; - return $this; } /** * Saves the image to specific path. + * * @access public - * @param string $filename If it's null save function will save the image in load path for default. + * @param string $filename If it's null save function will save the image + * in load path for default. * @return bool True if it is saved successful and False if it is not saved. */ public function save($filename = null) @@ -538,6 +644,7 @@ public function save($filename = null) /** * Outputs the image on browser. + * * @access public * @return bool */ @@ -548,23 +655,24 @@ public function output() /** * Resize image proportionally basing on the height of the image. + * * @access public * @param int $height - * @return void + * @return \GImage\Image */ public function resizeToHeight($height) { $width = $this->getPropWidth($height); $this->resize($width, $height); - return $this; } /** * Resize image proportionally basing on the width of the image. + * * @access public * @param int $width - * @return void + * @return \GImage\Image */ public function resizeToWidth($width) { @@ -576,6 +684,7 @@ public function resizeToWidth($width) /** * Gets proportional width of image from height value. + * * @access public * @param int $height * @return int @@ -583,12 +692,12 @@ public function resizeToWidth($width) public function getPropWidth($height) { $ratio = (int) $height / $this->height; - return $this->width * $ratio; } /** * Gets proportional height of image from width value. + * * @access public * @param int $width * @return int @@ -604,36 +713,36 @@ public function getPropHeight($width) * Scales the image. * @access public * @param int $scale - * @return Image + * @return \GImage\Image */ public function scale($scale) { $width = $this->width * (int) $scale / 100; $height = $this->height * (int) $scale / 100; $this->resize($width, $height); - return $this; } /** * Rotate an image with a given angle. + * * @access public * @param int $angle - * @return Image + * @return \GImage\Image */ public function rotate($angle = 0) { $this->resource = imagerotate($this->resource, $angle, 0); - return $this; } /** * Cuts an image proportionally and centered. + * * @access public * @param int $width Width crop. * @param int $height Height crop. - * @return Image + * @return \GImage\Image */ public function centerCrop($width, $height) { @@ -660,6 +769,7 @@ public function centerCrop($width, $height) /** * Cuts part of image. + * * @access public * @param int $width Width crop. * @param int $height Height crop. @@ -667,7 +777,7 @@ public function centerCrop($width, $height) * @param int $y1 [Optional] y-coordinate of source point. * @param int $dstX [Optional] x-coordinate of destination point. * @param int $dstY [Optional] y-coordinate of destination point. - * @return Image + * @return \GImage\Image */ public function crop($width, $height, $x1 = 0, $y1 = 0, $dstX = 0, $dstY = 0) { @@ -678,6 +788,7 @@ public function crop($width, $height, $x1 = 0, $y1 = 0, $dstX = 0, $dstY = 0) /** * Resizes the image. + * * @access private * @param int $width Image's width. * @param int $height Image's height. @@ -686,7 +797,7 @@ public function crop($width, $height, $x1 = 0, $y1 = 0, $dstX = 0, $dstY = 0) * @param int $dstX [Optional] x-coordinate of destination point. * @param int $dstY [Optional] y-coordinate of destination point. * @param bool $isCrop [Optional] if it's true resize function will crop the image. - * @return Image + * @return \GImage\Image */ private function resize($width, $height, $x1 = 0, $y1 = 0, $dstX = 0, $dstY = 0, $isCrop = false) { @@ -700,7 +811,18 @@ private function resize($width, $height, $x1 = 0, $y1 = 0, $dstX = 0, $dstY = 0, imagesavealpha($simage, true); } - imagecopyresampled($simage, $image, $dstX, $dstY, $x1, $y1, $width, $height, ($isCrop) ? $width : $this->width, ($isCrop) ? $height : $this->height); + imagecopyresampled( + $simage, + $image, + $dstX, + $dstY, + $x1, + $y1, + $width, + $height, + $isCrop ? $width : $this->width, + $isCrop ? $height : $this->height + ); $this->resource = $simage; $this->width = $this->boxWidth = imagesx($this->resource); @@ -712,61 +834,69 @@ private function resize($width, $height, $x1 = 0, $y1 = 0, $dstX = 0, $dstY = 0, /** * Renders the image. + * * @access private * @param string $filename [Optional] Path to save image * @param bool $output [Optional] If it's true render function outputs image. - * @return Image + * @return \GImage\Image */ private function render($filename = null, $output = false) { $image = $this->resource; - if ($image) { - if ($this->filename || $filename || $output) { - $filename = $output ? null : ($this->isExternal() ? (empty($filename) ? $this->name : $filename) : - (empty($filename) ? $this->filename : $filename)); - $quality = $this->quality; - $preserve = $this->preserve; - - if ($output) { - header('Content-type: ' . $this->mimetype); - ob_start(); - } - - if ($this->isJPG()) { - imagejpeg($image, $filename, $quality); - } else { - if ($this->isPNG()) { - if ($quality > 10) { - $quality = 0; - } - - imagealphablending($image, false); - imagesavealpha($image, true); - - imagepng($image, $filename, $quality); - } else { - imagegif($image, $filename); - } - } - - if ($output) { - ob_end_flush(); - } - - if (!$preserve) { - $this->destroy(); - } + if (!$image) { + return $this; + } + + if ($output) { + $filename = null; + } elseif (empty($filename) && $this->isLocal()) { + $filename = $this->filename; + } elseif (empty($filename) && $this->isExternal()) { + $filename = $this->name; + } + + $quality = $this->quality; + + if ($output) { + header('Content-type: ' . $this->mimetype); + ob_start(); + } + + if ($this->isJPG()) { + imagejpeg($image, $filename, $quality); + } + + if ($this->isPNG()) { + if ($quality > 10) { + $quality = 0; } + + imagealphablending($image, false); + imagesavealpha($image, true); + imagepng($image, $filename, $quality); + } + + if ($this->isGIF()) { + imagegif($image, $filename); + } + + if ($output) { + ob_end_flush(); + } + + if (!$this->preserve) { + $this->destroy(); } return $this; } /** - * Destroys resource. + * Destroys the current resource. + * * @access public - * @return Image + * @return \GImage\Image */ public function destroy() { diff --git a/src/Text.php b/src/Text.php index 40163d7..bd08891 100644 --- a/src/Text.php +++ b/src/Text.php @@ -1,20 +1,26 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace GImage; /** * A Text class to embed string into Canvas. + * * @package GImage - * @access public - * @version 2.0.0 - * @author José Luis Quintana - * @license https://github.com/joseluisq/gimage/blob/master/license.md + * @author Jose Luis Quintana + * * @property string $string String text. * @property string $fontface Font face .ttf filename. * @property int $angle Angle for the text. * @property int $opacity Opacity for the text. * @property string $string String text - * @link Github https://github.com/joseluisq/gimage */ class Text { @@ -35,23 +41,25 @@ class Text private $blue = 0; /** - * Sets string text. + * Sets the plain text. + * * @access public - * @param string $string String text. + * @param string $string Plain text. * @return void */ public function __construct($string = '') { - $this->setString($string); + $this->setContent($string); } /** - * Sets string text. + * Sets the plain text. + * * @access public - * @param string $string String text. + * @param string $string Plain text. * @return void */ - public function setString($string) + public function setContent($string) { $this->string = $string; @@ -60,6 +68,7 @@ public function setString($string) /** * Sets RGB color for text. + * * @access public * @param int $red Red color. * @param int $green Green color. @@ -77,6 +86,7 @@ public function setColor($red, $green, $blue) /** * Sets font size for text. + * * @access public * @param int $size Font size. * @return void @@ -90,6 +100,7 @@ public function setSize($size) /** * Sets font face (TTF font) for text. + * * @access public * @param string $fontface Path of TTF font. * @return void @@ -103,6 +114,7 @@ public function setFontface($fontface) /** * Sets text's opacity. + * * @access public * @param int $opacity Opacity value from 0 to 127 * @return void @@ -116,6 +128,7 @@ public function setOpacity($opacity) /** * Sets the horizontal alignment for text. + * * @access public * @param string $align Values supported: none, center * @return void @@ -129,6 +142,7 @@ public function setAlign($align) /** * Sets the vertical alignment for text. + * * @access public * @param string $valign Two values supported: none, center * @return void @@ -142,6 +156,7 @@ public function setValign($valign) /** * Sets text's angle. + * * @access public * @param int $angle Angle * @return void @@ -155,6 +170,7 @@ public function setAngle($angle) /** * Sets box width. + * * @access public * @param int $width Width * @return void @@ -168,6 +184,7 @@ public function setWidth($width) /** * Sets box height. + * * @access public * @param int $height Height * @return void @@ -181,6 +198,7 @@ public function setHeight($height) /** * Sets top position. + * * @access public * @param int $y position * @return void @@ -194,6 +212,7 @@ public function setTop($y) /** * Sets left position. + * * @access public * @param int $x position * @return void @@ -207,6 +226,7 @@ public function setLeft($x) /** * Sets line height. + * * @access public * @param float $lineHeight line-height * @return void @@ -220,6 +240,7 @@ public function setLineHeight($lineHeight) /** * Gets line height. + * * @access public * @return float */ @@ -230,16 +251,26 @@ public function getLineHeight() /** * Wrapps the text. + * * @access public * @return string */ public function wrappText() { - return $this->getWrappedText($this->size, $this->angle, $this->fontface, $this->string, $this->width); + $wrapp = $this->getWrappedText( + $this->size, + $this->angle, + $this->fontface, + $this->string, + $this->width + ); + + return $wrapp; } /** * Gets wrapped text. + * * @access public * @param int $size Font size fot the text. * @param int $angle Angole for the text. @@ -271,7 +302,9 @@ public function getWrappedText($size, $angle, $fontface, $string, $width = 100) } /** - * Calculates the Text box area. Returns an array with left, top, width and height values. + * Calculates bounding box of text using the TrueType font. + * Returns an array with 'left', 'top', 'width' and 'height' values. + * * @author * @access public * @param int $fontSize Font size fot the text. @@ -280,7 +313,7 @@ public function getWrappedText($size, $angle, $fontface, $string, $width = 100) * @param string $text String text. * @return array */ - public function calculateTextBox($fontSize, $fontAngle, $fontFile, $text) + private function getBoundingBox($fontSize, $fontAngle, $fontFile, $text) { $box = imagettfbbox($fontSize, $fontAngle, $fontFile, $text); @@ -333,17 +366,47 @@ public function calculateTextBox($fontSize, $fontAngle, $fontFile, $text) } /** - * Gets string text. + * Get the Text cords ([x, y). + * + * @return array An array with (x, y) cords. + */ + public function getCords() + { + $box = $this->getBoundingBox( + $this->getSize(), + $this->getAngle(), + $this->getFontface(), + $this->getContent() + ); + + $x = $box['left'] + $this->getLeft(); + $y = $this->getTop() + $box['top']; + + if ($this->getAlign() == 'center') { + $x = ($this->getWidth() - $box['width']) / 2; + } + + if ($this->getValign() == 'center') { + $y = ($this->getHeight() - $box['height']) / 2; + } + + return [$x, $y]; + } + + /** + * Gets the plain text. + * * @access public * @return string */ - public function getString() + public function getContent() { return $this->string; } /** * Gets rgb color. + * * @access public * @return array */ @@ -358,6 +421,7 @@ public function getColor() /** * Gets font face. + * * @access public * @return string */ @@ -368,6 +432,7 @@ public function getFontface() /** * Gets font size. + * * @access public * @return int */ @@ -378,6 +443,7 @@ public function getSize() /** * Gets opacity. + * * @access public * @return int */ @@ -388,6 +454,7 @@ public function getOpacity() /** * Gets the horizontal alignment for text. + * * @access public * @return string (none, center) */ @@ -398,6 +465,7 @@ public function getAlign() /** * Gets the vertical alignment for text. + * * @access public * @return string (none, center) */ @@ -408,6 +476,7 @@ public function getValign() /** * Gets angle. + * * @access public * @return int */ @@ -418,6 +487,7 @@ public function getAngle() /** * Gets width. + * * @access public * @return int */ @@ -428,6 +498,7 @@ public function getWidth() /** * Gets height. + * * @access public * @return int */ @@ -438,6 +509,7 @@ public function getHeight() /** * Gets top position. + * * @access public * @return int */ @@ -448,6 +520,7 @@ public function getTop() /** * Gets left position. + * * @access public * @return int */ diff --git a/src/Utils.php b/src/Utils.php index e1d18a5..50c240a 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -1,26 +1,32 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace GImage; /** - * Some util image functions. + * Image utility functions. + * * @package GImage - * @access public - * @version 2.0.0 - * @author José Luis Quintana - * @license https://github.com/joseluisq/gimage/blob/master/license.md - * @property array $mimetypes Mime types for images. - * @property array $typesimages Images types IMAGETYPE_GIF, IMAGETYPE_PNG and IMAGETYPE_JPEG. - * @link Github https://github.com/joseluisq/gimage + * @author Jose Luis Quintana + * + * @property array $mimeTypes Mime types for images. + * @property array $imageTypes Types: IMAGETYPE_GIF, IMAGETYPE_PNG and IMAGETYPE_JPEG. */ class Utils { - private static $mimetypes = [ + private static $mimeTypes = [ IMAGETYPE_GIF => 'image/gif', IMAGETYPE_PNG => 'image/png', IMAGETYPE_JPEG => 'image/jpeg' ]; - private static $typesimages = [ + private static $imageTypes = [ 'gif' => IMAGETYPE_GIF, 'png' => IMAGETYPE_PNG, 'jpg' => IMAGETYPE_JPEG @@ -28,38 +34,42 @@ class Utils /** * Gets image mime types (jpg, png and gif) + * * @access public * @return array */ public static function getMimetypes() { - return self::$mimetypes; + return self::$mimeTypes; } /** * Gets image mimeType by filename. + * * @access public * @param string $filename Image path. * @return string */ public static function getMimetype($filename) { - return self::$_mimetypes[self::getImageType($filename)]; + return self::$mimeTypes[self::getImageType($filename)]; } /** * Gets image mime type by image type (IMAGETYPE_GIF, IMAGETYPE_PNG or IMAGETYPE_JPEG). + * * @access public * @param string $imagetype IMAGETYPE_GIF, IMAGETYPE_PNG or IMAGETYPE_JPEG. * @return string */ public static function getMimetypeByImageType($imagetype) { - return self::$mimetypes[$imagetype]; + return self::$mimeTypes[$imagetype]; } /** * Gets image extension from filename. + * * @access public * @param string $filename Image path. * @return string Return jpg, png or gif extension. @@ -71,17 +81,19 @@ public static function getExtension($filename) /** * Gets image type from filename. + * * @access public * @param string $filename Image path. * @return bool */ public static function getImageType($filename) { - return self::$typesimages[self::getExtension($filename)]; + return self::$imageTypes[self::getExtension($filename)]; } /** * Checks if image path is a JPG. + * * @access public * @param string $filename Image path. * @return bool @@ -93,6 +105,7 @@ public static function isJPG($filename) /** * Checks if image path is a PNG. + * * @access public * @param string $filename Image path. * @return bool @@ -104,6 +117,7 @@ public static function isPNG($filename) /** * Checks if image path is a PNG. + * * @access public * @param string $filename Image path. * @return bool @@ -112,4 +126,30 @@ public static function isGIF($filename) { return (self::getExtension($filename) == 'gif'); } + + /** + * Checks if image resource is a JPG. + * + * @access public + * @param resource $resource Image resource. + * @return bool + */ + public static function isJPGResource($resource) + { + return $resource && (bin2hex($resource[0]) == 'ff' + && bin2hex($resource[1]) == 'd8'); + } + + /** + * Checks if image resource is a PNG. + * + * @access public + * @param resource $resource Image resource. + * @return bool + */ + public static function isPNGResource($resource) + { + return $resource && (bin2hex($resource[0]) == '89' && $resource[1] == 'P' + && $resource[2] == 'N' && $resource[3] == 'G'); + } } diff --git a/tests/GImageTest.php b/tests/GImageTest.php index 6bb1663..6a8043e 100644 --- a/tests/GImageTest.php +++ b/tests/GImageTest.php @@ -1,4 +1,12 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ namespace GImage\Test; @@ -6,6 +14,7 @@ use GImage\Text; use GImage\Figure; use GImage\Canvas; +use PHPUnit\Framework\TestCase; if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); @@ -15,13 +24,12 @@ define('GIMAGE_PATH_TMP', sys_get_temp_dir()); /** - * PHPUnit / GImage Test Class + * GImage Test suite. + * * @package GImage - * @version 2.0.0 - * @author José Luis Quintana - * @license https://github.com/joseluisq/gimage/blob/master/license.md + * @author Jose Luis Quintana */ -class GImageTest extends \PHPUnit_Framework_TestCase +class GImageTest extends TestCase { public function testLoad() { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 7fbf9a1..4c9dd85 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,4 +1,12 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ /** * PHPUnit Autoloader for GImage Library @@ -6,7 +14,8 @@ */ namespace GImage\Test { - date_default_timezone_set('America/Lima'); - require __DIR__ . '/../vendor/autoload.php'; + date_default_timezone_set('America/Lima'); + + require __DIR__ . '/../vendor/autoload.php'; }