├── .buildpath ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .nvmrc ├── .project ├── .settings ├── org.eclipse.php.core.prefs ├── org.eclipse.php.debug.core.Debug_Process_Preferences.prefs └── org.phpsrc.eclipse.pti.tools.phpunit.prefs ├── .travis.yml ├── PharClassLoader.php ├── README.md ├── composer.json ├── examples ├── filters.php ├── generator.php ├── generatorgradient.php ├── index.php ├── monkey.png ├── overlay.php ├── rasterizer.php ├── reflection.php ├── repeater.php ├── rotate.php ├── router.php ├── test.php ├── thumbnail.php └── uglydog.png ├── gulpfile.js ├── package.json ├── phar-bootstrap.php ├── php.ini ├── phpunit.xml ├── src └── imagemanipulation │ ├── .gitattributes │ ├── .gitignore │ ├── Args.php │ ├── Coordinate.php │ ├── ImageBuilder.php │ ├── ImageImageResource.php │ ├── ImageResource.php │ ├── ImageResourceException.php │ ├── ImageType.php │ ├── ImageUtil.php │ ├── PresetFilter.php │ ├── ResourceFactory.php │ ├── color │ ├── Color.php │ ├── ColorFactory.php │ ├── ColorUtil.php │ └── IColor.php │ ├── filter │ ├── FilterException.php │ ├── IImageFilter.php │ ├── ImageFilterBrightness.php │ ├── ImageFilterColorize.php │ ├── ImageFilterComic.php │ ├── ImageFilterContrast.php │ ├── ImageFilterConvolution.php │ ├── ImageFilterDarken.php │ ├── ImageFilterDodge.php │ ├── ImageFilterDuotone.php │ ├── ImageFilterEdgeDetect.php │ ├── ImageFilterEmboss.php │ ├── ImageFilterEmbossColoring.php │ ├── ImageFilterFindEdges.php │ ├── ImageFilterFlip.php │ ├── ImageFilterGammaCorrection.php │ ├── ImageFilterGaussianBlur.php │ ├── ImageFilterGrayScale.php │ ├── ImageFilterHueRotate.php │ ├── ImageFilterMeanRemove.php │ ├── ImageFilterMotionBlur.php │ ├── ImageFilterNegative.php │ ├── ImageFilterNoise.php │ ├── ImageFilterOldCardboard.php │ ├── ImageFilterOpacity.php │ ├── ImageFilterPixelate.php │ ├── ImageFilterRandomBlocks.php │ ├── ImageFilterReplaceColor.php │ ├── ImageFilterReverse.php │ ├── ImageFilterRoundedCorners.php │ ├── ImageFilterScatter.php │ ├── ImageFilterSelectiveBlur.php │ ├── ImageFilterSemiGrayScale.php │ ├── ImageFilterSepia.php │ ├── ImageFilterSepiaFast.php │ ├── ImageFilterSharpen.php │ ├── ImageFilterSmooth.php │ ├── ImageFilterSobel.php │ ├── ImageFilterSobelEdgeDetect.php │ ├── ImageFilterSobelEdgeEnhance.php │ ├── ImageFilterSobelHorizontal.php │ ├── ImageFilterSobelScharr.php │ ├── ImageFilterSobelVertical.php │ ├── ImageFilterTrueColor.php │ └── ImageFilterVignette.php │ ├── generation │ └── ImageGenerator.php │ ├── overlay │ ├── ImageFilterOverlay.php │ └── ImageFilterOverlayWithAlpha.php │ ├── rasterize │ ├── ImageRaster.php │ ├── Rasterizer.php │ ├── Segment.php │ └── strategy │ │ ├── AbstractRasterStrategy.php │ │ ├── CenterRasterStrategy.php │ │ └── GridRasterStrategy.php │ ├── reflection │ └── ImageFilterReflection.php │ ├── repeater │ └── ImageRepeater.php │ ├── rotate │ └── ImageFilterRotate.php │ ├── thumbnail │ ├── Thumbalizer.php │ └── pixelstrategy │ │ ├── CenteredPixelStrategy.php │ │ ├── IPixelStrategy.php │ │ ├── MaxPixelStrategy.php │ │ └── PercentagePixelStrategy.php │ └── watermark │ ├── ImageFilterWatermark.php │ └── WatermarkBuilder.php ├── tests-long ├── ImageFilterTruecolorTest.php └── imagemanipulation │ └── filter │ ├── ImageFilterDuotoneTest.php │ ├── ImageFilterHueRotateTest.php │ └── ImageFilterSobelEdgeDetectTest.php ├── tests ├── .gitignore ├── PHPUnitBootstrap.php ├── imagemanipulation │ ├── ArgsTest.php │ ├── ImageResourceTest.php │ ├── PreconditionsTest.php │ ├── color │ │ ├── ColorFactoryTest.php │ │ ├── ColorTest.php │ │ └── ColorUtilTest.php │ ├── filter │ │ ├── ImageFilterBrightnessTest.php │ │ ├── ImageFilterColorizeTest.php │ │ ├── ImageFilterComicTest.php │ │ ├── ImageFilterContrastTest.php │ │ ├── ImageFilterConvolutionTest.php │ │ ├── ImageFilterDarkenTest.php │ │ ├── ImageFilterDodgeTest.php │ │ ├── ImageFilterEdgeDetectTest.php │ │ ├── ImageFilterEmbossColoringTest.php │ │ ├── ImageFilterEmbossTest.php │ │ ├── ImageFilterFindEdgesTest.php │ │ ├── ImageFilterFlipTest.php │ │ ├── ImageFilterGammaCorrectionTest.php │ │ ├── ImageFilterGaussianBlurTest.php │ │ ├── ImageFilterGrayscaleTest.php │ │ ├── ImageFilterMeanRemoveTest.php │ │ ├── ImageFilterMotionBlurTest.php │ │ ├── ImageFilterNegativeTest.php │ │ ├── ImageFilterNoiseTest.php │ │ ├── ImageFilterRoundedCornersTest.php │ │ ├── ImageFilterSemiGrayscaleTest.php │ │ ├── ImageFilterSepiaFastTest.php │ │ ├── ImageFilterSepiaTest.php │ │ ├── ImageFilterSobelEdgeEnhanceTest.php │ │ ├── ImageFilterSobelHorizontalTest.php │ │ ├── ImageFilterSobelScharrTest.php │ │ ├── ImageFilterSobelTest.php │ │ └── ImageFilterSobelVerticalTest.php │ ├── generation │ │ └── ImageGeneratorTest.php │ ├── overlay │ │ ├── OverlayBuilderTest.php │ │ └── img │ │ │ ├── vignette-24.png │ │ │ ├── vignette-32.png │ │ │ ├── vignette-8.png │ │ │ ├── vignette.gif │ │ │ └── vignette.jpg │ ├── rasterize │ │ ├── ImageRasterTest.php │ │ ├── RasterizerTest.php │ │ ├── SegmentTest.php │ │ └── strategy │ │ │ ├── CenterRasterStrategyTest.php │ │ │ └── GridRasterStrategyTest.php │ ├── reflection │ │ └── ImageFilterReflectionTest.php │ └── thumbnail │ │ ├── ThumbalizerTest.php │ │ └── pixelstrategy │ │ ├── CenteredPixelStrategyTest.php │ │ ├── MaxPixelStrategyTest.php │ │ └── PercentagePixelStrategyTest.php ├── mocks │ └── MockImageResource.php └── test │ ├── ImageFilterTestCase.php │ ├── ImagemanipulationTestCase.php │ ├── sample-rect.jpg │ ├── sample.gif │ ├── sample.jpg │ └── sample.png └── yarn.lock /.buildpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = false 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | 8 | [*.js,*.scss,*.html,*.svg,*.json.*.php] 9 | indent_size = 4 10 | indent_style = space 11 | 12 | [package.json] 13 | indent_size = 4 14 | indent_style = space 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | 45 | tests/cache 46 | node_modules 47 | vendor 48 | examples/tmp 49 | composer.lock 50 | composer.phar 51 | /npm-debug.log 52 | /tmp/ 53 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 6.9.1 2 | 3 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | imagemanipulation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.validation.validationbuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.dltk.core.scriptbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.php.core.PHPNature 21 | 22 | 23 | 24 | 1441884464696 25 | 26 | 30 27 | 28 | org.eclipse.ui.ide.multiFilter 29 | 1.0-name-matches-false-false-node_modules 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /.settings/org.eclipse.php.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | include_path=0;/imagemanipulation 3 | use_asp_tags_as_php=false 4 | -------------------------------------------------------------------------------- /.settings/org.eclipse.php.debug.core.Debug_Process_Preferences.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.php.debug.core.use-project-settings=true 3 | -------------------------------------------------------------------------------- /.settings/org.phpsrc.eclipse.pti.tools.phpunit.prefs: -------------------------------------------------------------------------------- 1 | bootstrap=\\imagemanipulation\\tests\\PHPUnitBootstrap.php 2 | debug_print_output=true 3 | eclipse.preferences.version=1 4 | generate_code_coverage=false 5 | pear_library= 6 | php_executable=PHP 5.4.31 7 | source_file_pattern_folder=imagemanipulation 8 | test_file_pattern_file=%fTest.%e 9 | test_file_pattern_folder=\\%p\\tests\\%d 10 | test_file_super_class=PHPUnit_Framework_TestCase 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - 5.3 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | - 7.0 8 | - hhvm 9 | 10 | matrix: 11 | allow_failures: 12 | - php: 7.0 13 | - php: hhvm 14 | - php: nightly 15 | 16 | sudo: false 17 | 18 | before_install: 19 | - composer self-update 20 | 21 | install: 22 | - travis_retry composer install --no-interaction --prefer-source 23 | 24 | script: ./vendor/phpunit/phpunit/phpunit -c ./phpunit.xml --coverage-text -------------------------------------------------------------------------------- /PharClassLoader.php: -------------------------------------------------------------------------------- 1 | base = 'phar://' . $aPharPath . '/'; 18 | } 19 | 20 | /** 21 | * Register this classloader 22 | */ 23 | public function register(){ 24 | spl_autoload_extensions( ".php" ); 25 | 26 | spl_autoload_register( array($this , 'autoLoad') ); 27 | } 28 | 29 | /** 30 | * the loader implementation 31 | * 32 | * @param string $aClassName The classname including the namespace 33 | * 34 | * @throws \Exception 35 | */ 36 | public function autoLoad( $aClassName ) 37 | { 38 | $path = $this->base . $aClassName . '.php'; 39 | 40 | if (is_file($path)){ 41 | $included = include $path; 42 | if (!$included){ 43 | throw new \Exception('Could not load class ' . $aClassName . ' from ' . $this->base) ; 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "elgervb/imagemanipulation", 3 | "description" : "Library for image manipulation in PHP with GD", 4 | "type" : "library", 5 | "authors" : [{ 6 | "name" : "Elger van Boxtel", 7 | "email" : "elgervb@gmail.com", 8 | "homepage" : "http://elgervanboxtel.nl", 9 | "role" : "developer" 10 | } 11 | ], 12 | "keywords" : [ 13 | "gd", 14 | "images", 15 | "manipulation", 16 | "color utils", 17 | "image filters", 18 | "image overlays", 19 | "image reflection", 20 | "image rotate", 21 | "image thumbnail", 22 | "image watermark" 23 | ], 24 | "homepage" : "https://github.com/elgervb/imagemanipulation", 25 | "license" : [ 26 | "MIT" 27 | ], 28 | "require-dev" : { 29 | "phpunit/phpunit" : "^4.8", 30 | "phpdocumentor/phpdocumentor": "2.*", 31 | "phpmd/phpmd" : "@stable" 32 | }, 33 | "autoload" : { 34 | "psr-0" : { 35 | "imagemanipulation" : [ 36 | "src", 37 | "tests" 38 | ], 39 | "test" : [ 40 | "tests" 41 | ], 42 | "mocks" : [ 43 | "tests" 44 | ] 45 | } 46 | }, 47 | "support" : { 48 | "wiki" : "https://github.com/elgervb/imagemanipulation/wiki", 49 | "source" : "https://github.com/elgervb/imagemanipulation", 50 | "issues" : "https://github.com/elgervb/imagemanipulation/issues", 51 | "email" : "elgervb@gmail.com" 52 | } 53 | } -------------------------------------------------------------------------------- /examples/filters.php: -------------------------------------------------------------------------------- 1 | contrast(10) 6 | ->greyscale() 7 | ->render(70); -------------------------------------------------------------------------------- /examples/generator.php: -------------------------------------------------------------------------------- 1 | render(ImageType::PNG, 80); 8 | -------------------------------------------------------------------------------- /examples/generatorgradient.php: -------------------------------------------------------------------------------- 1 | render(ImageType::PNG, 80); 8 | -------------------------------------------------------------------------------- /examples/index.php: -------------------------------------------------------------------------------- 1 | 2 |
3 |

Original

4 | 5 |
6 | 7 |
8 |

ImageBuilder

9 | 10 |
11 |
12 | 13 |
14 |

Image Generator

15 | 16 |
17 |
18 | 19 |
20 |

Image Generator Gradient

21 | 22 |
23 |
24 | 25 |
26 |

Image Thumbnail

27 | 28 |
29 |
30 | 31 |
32 |

Overlay

33 | 34 |
35 |
36 | 37 |
38 |

Image Repeater

39 | 40 |
41 |
42 | 43 |
44 |

Image Rotation

45 | 46 |
47 |
48 | 49 |
50 |

Reflection

51 | 52 |
53 |
54 | 55 |
56 |

Rasterizer

57 | 58 |
59 |
60 | -------------------------------------------------------------------------------- /examples/monkey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elgervb/imagemanipulation/04375d9f413908e64eb67f75868fa4c6156c2cc2/examples/monkey.png -------------------------------------------------------------------------------- /examples/overlay.php: -------------------------------------------------------------------------------- 1 | filter($overlay); 19 | $resource->render(ImageType::PNG, 80); 20 | 21 | -------------------------------------------------------------------------------- /examples/rasterizer.php: -------------------------------------------------------------------------------- 1 | getSegments() as $i => $segment) { 19 | $check = floor($i / 10) % 2 ? ODD : EVEN; // 10 segments per row 20 | 21 | if ($i % 2 === $check) { 22 | $resource = $rasterizer->createResource($segment); 23 | $resource->filter($filter); 24 | $rasterizer->writeSegment($resource, $segment); 25 | } 26 | } 27 | 28 | $rasterizer->getResource()->render(ImageType::PNG, 80); 29 | -------------------------------------------------------------------------------- /examples/reflection.php: -------------------------------------------------------------------------------- 1 | filter(new ImageFilterReflection(300)); 9 | 10 | $resource->render(ImageType::PNG, 80); 11 | -------------------------------------------------------------------------------- /examples/repeater.php: -------------------------------------------------------------------------------- 1 | create($resource); 14 | 15 | // create a grid of 2 x 2 ugly dogs 16 | $repeater = new ImageRepeater($smallResource, $smallResource->getWidth() * 2, $smallResource->getHeight() * 2); 17 | $repeated = $repeater->apply(); 18 | 19 | $repeated->render(ImageType::PNG, 80); 20 | 21 | -------------------------------------------------------------------------------- /examples/rotate.php: -------------------------------------------------------------------------------- 1 | filter(new ImageFilterRotate(45, '#0190D2')); 11 | 12 | // render the image 13 | $resource->render(ImageType::PNG, 80); 14 | -------------------------------------------------------------------------------- /examples/router.php: -------------------------------------------------------------------------------- 1 | filter($filter); 16 | 17 | $resource->save(__DIR__ . DIRECTORY_SEPARATOR . get_class($filter) . '6.png', ImageType::PNG, 80); 18 | $resource->render(ImageType::PNG, 80); 19 | -------------------------------------------------------------------------------- /examples/thumbnail.php: -------------------------------------------------------------------------------- 1 | create($resource); 15 | 16 | // render the thumb 17 | $thumb->render(ImageType::PNG, 80); -------------------------------------------------------------------------------- /examples/uglydog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elgervb/imagemanipulation/04375d9f413908e64eb67f75868fa4c6156c2cc2/examples/uglydog.png -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | /* global __dirname */ 2 | var gulp = require('gulp'), 3 | notify = require('gulp-notify'), 4 | phpunit = require('gulp-phpunit'), 5 | argv = require('yargs').argv 6 | _ = require('lodash'); 7 | 8 | /** 9 | * Watch sources and tests for changes and run tests 10 | */ 11 | gulp.task('test:watch', function(){ 12 | var path = require('path'); 13 | gulp.watch(['./src/**/*.php', './tests/**/*.php']) 14 | .on("change", function(file) { 15 | var filename = path.basename(file.path, '.php'); 16 | console.log(filename + ' has changed. Running tests...'); 17 | 18 | var options = {debug: false, notify: true, stderr: false, coverageText: 'php://stdout', filter: '/.*'+filename+'.*/i'}; 19 | gulp.src('phpunit.xml') 20 | .pipe(phpunit('', options)) 21 | .on('error', notify.onError(notification('fail', 'phpunit'))) 22 | .pipe(notify(notification('pass', 'phpunit'))); 23 | }); 24 | }); 25 | 26 | 27 | function notification(status, pluginName, override) { 28 | var options = { 29 | title: ( status == 'pass' ) ? 'Tests Passed' : 'Tests Failed', 30 | message: ( status == 'pass' ) ? '\n\nAll tests have passed!\n\n' : '\n\nOne or more tests failed...\n\n', 31 | icon: __dirname + '/node_modules/gulp-' + pluginName +'/assets/test-' + status + '.png' 32 | }; 33 | options = _.merge(options, override); 34 | return options; 35 | } 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "imagemanipulation", 3 | "version": "1.0.0", 4 | "description": "Library for image manipulation in PHP with GD", 5 | "main": "", 6 | "directories": { 7 | "test": "tests" 8 | }, 9 | "scripts": { 10 | "test": "./vendor/phpunit/phpunit/phpunit -c ./phpunit.xml", 11 | "test:coverage": "$npm_package_scripts_test --coverage-text --coverage-html ./tmp/report", 12 | "watch": "gulp test:watch --coverage", 13 | "start": "php -S localhost:4000 -t examples/ -c php.ini examples/router.php", 14 | "docs": "php vendor/bin/phpdoc -d ./src -t ./tmp/docs", 15 | "phpmd": "php vendor/bin/phpmd ./src html cleancode --reportfile ./tmp/phpmd.html", 16 | "postinstall": "composer install --no-interaction --prefer-source" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "https://github.com/elgervb/imagemanipulation.git" 21 | }, 22 | "author": "", 23 | "license": "ISC", 24 | "bugs": { 25 | "url": "https://github.com/elgervb/imagemanipulation/issues" 26 | }, 27 | "homepage": "https://github.com/elgervb/imagemanipulation", 28 | "devDependencies": { 29 | "gulp": "3.9.1", 30 | "gulp-notify": "2.2.0", 31 | "gulp-phpunit": "0.21.4", 32 | "lodash": "4.17.2", 33 | "yargs": "6.4.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /phar-bootstrap.php: -------------------------------------------------------------------------------- 1 | register(); 12 | 13 | __HALT_COMPILER(); -------------------------------------------------------------------------------- /php.ini: -------------------------------------------------------------------------------- 1 | [XDebug] 2 | xdebug.remote_enable = On 3 | xdebug.remote_autostart = On 4 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | 15 | 16 | ./tests/ 17 | 18 | 19 | 20 | 21 | 22 | ./src 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/imagemanipulation/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /src/imagemanipulation/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /src/imagemanipulation/Coordinate.php: -------------------------------------------------------------------------------- 1 | setX( $x ); 32 | $this->setY( $y ); 33 | } 34 | 35 | /** 36 | * Factory method to create a new Coordinate 37 | * 38 | * @param int $x 39 | * @param int $y 40 | * 41 | * @return \imagemanipulation\Coordinate 42 | */ 43 | public static function create($x, $y){ 44 | return new Coordinate($x, $y); 45 | } 46 | 47 | /** 48 | * Returns the x-coordinate of the pixel 49 | * @return int 50 | */ 51 | public function getX() 52 | { 53 | return $this->x; 54 | } 55 | 56 | /** 57 | * Returns the y-coordinate of the pixel 58 | * @return int 59 | */ 60 | public function getY() 61 | { 62 | return $this->y; 63 | } 64 | 65 | /** 66 | * Sets the x-coordinate of the pixel 67 | * 68 | * @param int $x 69 | */ 70 | private function setX( $x ) 71 | { 72 | $this->x = Args::int($x)->required()->min(0)->value(); 73 | } 74 | 75 | /** 76 | * Sets the y-coordinate of the pixel 77 | * 78 | * @param int $y 79 | */ 80 | private function setY( $y ) 81 | { 82 | $this->y = Args::int($y)->required()->min(0)->value(); 83 | } 84 | 85 | public function __toString() { 86 | return '(' . $this->getX() . ', ' . $this->getY() . ')'; 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /src/imagemanipulation/ImageResourceException.php: -------------------------------------------------------------------------------- 1 | getExtension()) { 15 | case 'png': 16 | return ImageType::PNG; 17 | case 'gif': 18 | return ImageType::GIF; 19 | case 'bmp': 20 | return ImageType::BMP; 21 | default: 22 | return ImageType::JPG; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/imagemanipulation/ImageUtil.php: -------------------------------------------------------------------------------- 1 | aWidth and aHeight. 14 | * 15 | * @param int $aWidth The width of the image 16 | * @param int $aHeight The height of the image 17 | * @return resource 18 | */ 19 | public static function createTransparentImage( $width, $height ) 20 | { 21 | $imgRes = self::createImage($width, $height); 22 | $color = ColorFactory::white( 127 ); 23 | 24 | $transparent = self::allocateColor( $imgRes, $color ); 25 | 26 | imagefill( $imgRes, 0, 0, $transparent ); 27 | 28 | return $imgRes; 29 | } 30 | 31 | public static function createImage($width, $height) { 32 | Args::int($width, 'width')->required()->min(0); 33 | Args::int($height, 'height')->required()->min(0); 34 | 35 | $imgRes = imagecreatetruecolor( $width, $height ); 36 | imageantialias( $imgRes, true ); 37 | imagealphablending( $imgRes, true ); 38 | imagesavealpha( $imgRes, true ); 39 | 40 | return $imgRes; 41 | } 42 | 43 | /** 44 | * Returns the allocated color 45 | * 46 | * @param RGBColor $aColor 47 | * @return int 48 | */ 49 | public static function allocateColor( $aImgRes, Color $aColor ) 50 | { 51 | return imagecolorallocatealpha( $aImgRes, $aColor->getRed(), $aColor->getGreen(), $aColor->getBlue(), $aColor->getAlpha() ); 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /src/imagemanipulation/PresetFilter.php: -------------------------------------------------------------------------------- 1 | meanremove()->contrast(50); 12 | } 13 | 14 | public static function light(ImageBuilder $builder) 15 | { 16 | $builder->brightness(10)->colorize('#643200', 10); 17 | } 18 | 19 | public static function boost(ImageBuilder $builder) 20 | { 21 | $builder->contrast(35)->brightness(20); 22 | } 23 | 24 | public static function deep(ImageBuilder $builder) 25 | { 26 | $builder->colorize('#73AaBE', 100)->contrast(20); 27 | } 28 | 29 | public static function grayscaleDark(ImageBuilder $builder) 30 | { 31 | $builder->grayscale()->contrast(15); 32 | } 33 | 34 | public static function sepia(ImageBuilder $builder) 35 | { 36 | $builder->grayscale() 37 | ->brightness(- 10) 38 | ->contrast(20) 39 | ->colorize('#3C1E00'); 40 | } 41 | 42 | public static function retro(ImageBuilder $builder) 43 | { 44 | $builder->noise(40) 45 | ->selectiveBlur() 46 | ->selectiveBlur() 47 | ->colorize('#704214', 65) 48 | ->contrast(20) 49 | ->brightness(10); 50 | } 51 | 52 | public static function vintage(ImageBuilder $builder) 53 | { 54 | $builder->colorize('#FF0000', 125) 55 | ->colorize('#FF9966', 60) 56 | ->gammaCorrection(1.7, 1.0) 57 | ->contrast(20); 58 | } 59 | 60 | public static function blueish(ImageBuilder $builder) 61 | { 62 | $builder->colorize('#222b6d', 60) 63 | ->colorize('#f7daae', 110) 64 | ->gammaCorrection(1.2, 1.0); 65 | } 66 | } -------------------------------------------------------------------------------- /src/imagemanipulation/ResourceFactory.php: -------------------------------------------------------------------------------- 1 | rate = Args::int($rate, 'rate')->required()->min(-255)->max(255)->value(); 25 | } 26 | 27 | /** 28 | * (non-PHPdoc) 29 | * @see \imagemanipulation\filter\IImageFilter::applyFilter() 30 | */ 31 | public function applyFilter( ImageResource $aResource ) 32 | { 33 | if ($this->rate != 0) // 0 means no change 34 | { 35 | imagefilter( $aResource->getResource(), IMG_FILTER_BRIGHTNESS, $this->rate ); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterColorize.php: -------------------------------------------------------------------------------- 1 | color = $aColor; 24 | } 25 | 26 | /** 27 | * Applies the filter to the resource 28 | * 29 | * @param $aResource ImageResource 30 | */ 31 | public function applyFilter( ImageResource $aResource ) 32 | { 33 | imagefilter( $aResource->getResource(), IMG_FILTER_COLORIZE, $this->color->getRed(), $this->color->getGreen(), $this->color->getBlue(), $this->color->getAlpha() ); 34 | } 35 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterComic.php: -------------------------------------------------------------------------------- 1 | opacity = Args::int($opacity,'opacity')->required()->min(0)->max(100)->value(); 19 | } 20 | /** 21 | * Applies the filter to the resource 22 | * 23 | * @param ImageResource $aResource 24 | */ 25 | public function applyFilter( ImageResource $aResource ) 26 | { 27 | //comic effect 28 | $width = $aResource->getX(); 29 | $height = $aResource->getY(); 30 | 31 | /* @var $imgK \imagemanipulation\ImageResource */ 32 | $imgK = $aResource->cloneResource(); 33 | $trueColorFilter = new ImageFilterTrueColor('ffffff', '000000'); 34 | $trueColorFilter->applyFilter($imgK); 35 | 36 | imagecopymerge($aResource->getResource(),$imgK->getResource(),0,0,0,0,$width,$height,$this->opacity); 37 | 38 | imagedestroy($imgK->getResource()); 39 | } 40 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterContrast.php: -------------------------------------------------------------------------------- 1 | level = Args::int($level, 'level')->required()->min(-100)->max(100)->value() * -1; 21 | } 22 | 23 | /** 24 | * Applies contrast to the image. 25 | * 26 | * @param ImageResource $aResource 27 | */ 28 | public function applyFilter( ImageResource $aResource ) 29 | { 30 | if ($this->level != 0) 31 | { 32 | imagefilter( $aResource->getResource(), IMG_FILTER_CONTRAST, $this->level ); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterConvolution.php: -------------------------------------------------------------------------------- 1 | matrix = array(array($aArg1 , $aArg2 , $aArg3) , array($aArg4 , $aArg5 , $aArg6) , array($aArg7 , $aArg8 , $aArg8)); 20 | } 21 | 22 | /** 23 | * 24 | * @see IImageFilter::applyFilter() 25 | */ 26 | public function applyFilter( ImageResource $aResource ) 27 | { 28 | $this->beforeApplyFilter($aResource); 29 | imageconvolution( $aResource->getResource(), $this->matrix, $this->getDivision(), $this->getOffset() ); 30 | $this->afterApplyFilter($aResource); 31 | } 32 | 33 | protected function beforeApplyFilter(ImageResource $aResource) { 34 | // 35 | } 36 | 37 | protected function afterApplyFilter(ImageResource $aResource) { 38 | // 39 | } 40 | 41 | protected function getDivision() { 42 | return $this->computeDiv(); 43 | } 44 | 45 | protected function getOffset() { 46 | return 0; 47 | } 48 | 49 | final protected function computeDiv() 50 | { 51 | return array_sum( $this->matrix[0] ) + array_sum( $this->matrix[1] ) + array_sum( $this->matrix[2] ); 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterDarken.php: -------------------------------------------------------------------------------- 1 | rate = Args::int($rate)->required()->min(-255)->max(255)->value() * -1; 22 | } 23 | 24 | public function applyFilter( ImageResource $aResource ) 25 | { 26 | imagefilter( $aResource->getResource(), IMG_FILTER_BRIGHTNESS, $this->rate ); 27 | } 28 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterDodge.php: -------------------------------------------------------------------------------- 1 | percentage = Args::int($percentage, 'percentage')->required()->min(0)->max(100)->value(); 22 | } 23 | 24 | /** 25 | * Applies the filter to the image resource 26 | * 27 | * @param ImageResource $aResource 28 | */ 29 | public function applyFilter( ImageResource $aResource ) 30 | { 31 | if ($this->percentage == 0) 32 | { 33 | return; // percentage = 0, do nothing ! 34 | } 35 | 36 | $resource = $aResource->getResource(); 37 | 38 | $rgb = 0; 39 | $d = array(); 40 | $s = array(); 41 | $dstx = 0; 42 | $dsty = 0; 43 | $dest = imagecreatetruecolor( $aResource->getX(), $aResource->getY() ); 44 | 45 | for ($i = 0; $i < $aResource->getY(); $i ++) 46 | { 47 | for ($j = 0; $j < $aResource->getX(); $j ++) 48 | { 49 | $rgb = imagecolorat( $dest, $dstx + $j, $dsty + $i ); 50 | $d[0] = ($rgb >> 16) & 0xFF; 51 | $d[1] = ($rgb >> 8) & 0xFF; 52 | $d[2] = $rgb & 0xFF; 53 | 54 | $rgb = imagecolorat( $aResource->getResource(), $j, $i ); 55 | $s[0] = ($rgb >> 16) & 0xFF; 56 | $s[1] = ($rgb >> 8) & 0xFF; 57 | $s[2] = $rgb & 0xFF; 58 | 59 | $d[0] += min( $s[0], 0xFF - $d[0] ) * $this->percentage / 100; 60 | $d[1] += min( $s[1], 0xFF - $d[1] ) * $this->percentage / 100; 61 | $d[2] += min( $s[2], 0xFF - $d[2] ) * $this->percentage / 100; 62 | 63 | imagesetpixel( $resource, $dstx + $j, $dsty + $i, imagecolorallocate( $resource, $d[0], $d[1], $d[2] ) ); 64 | } 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterDuotone.php: -------------------------------------------------------------------------------- 1 | red = Args::int($red)->required()->min(0)->max(255)->value(); 25 | $this->green = Args::int($green)->required()->min(0)->max(255)->value(); 26 | $this->blue = Args::int($blue)->required()->min(0)->max(255)->value(); 27 | } 28 | 29 | /** 30 | * Applies the sepia filter to an image resource 31 | * 32 | * @param ImageResource $aResource 33 | */ 34 | public function applyFilter( ImageResource $aResource ) 35 | { 36 | if($this->red === 0 && $this->green === 0 && $this->blue === 0){ 37 | return; 38 | } 39 | 40 | $res = $aResource->getResource(); 41 | $width = $aResource->getX(); 42 | $height = $aResource->getY(); 43 | 44 | for ($y = 0; $y < $height; $y ++) 45 | { 46 | for ($x = 0; $x < $width; $x ++) 47 | { 48 | $colorIndex = imagecolorat( $res, $x, $y ); 49 | 50 | $dstA = ($colorIndex >> 24) << 1; 51 | $dstR = $colorIndex >> 16 & 0xFF; 52 | $dstG = $colorIndex >> 8 & 0xFF; 53 | $dstB = $colorIndex & 0xFF; 54 | 55 | $newR = min(255, $this->red + $dstR); 56 | $newG = min(255, $this->green + $dstG); 57 | $newB = min(255, $this->blue + $dstB); 58 | 59 | $newColor = imagecolorallocatealpha( $res, $newR, $newG, $newB, $dstA ); 60 | imagesetpixel( $res, $x, $y, $newColor ); 61 | } 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterEdgeDetect.php: -------------------------------------------------------------------------------- 1 | getResource(), IMG_FILTER_EDGEDETECT ); 19 | } 20 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterEmboss.php: -------------------------------------------------------------------------------- 1 | getResource(), IMG_FILTER_EMBOSS ); 14 | } 15 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterEmbossColoring.php: -------------------------------------------------------------------------------- 1 | input = Args::float($input, 'input')->required()->min(0)->value(); 17 | $this->output = Args::float($output, 'output')->required()->min(0)->value(); 18 | } 19 | /** 20 | * Applies the filter to the resource 21 | * 22 | * @param ImageResource $aResource 23 | */ 24 | public function applyFilter( ImageResource $aResource ) 25 | { 26 | imagegammacorrect($aResource->getResource(), $this->input, $this->output); 27 | } 28 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterGaussianBlur.php: -------------------------------------------------------------------------------- 1 | getResource(), IMG_FILTER_GAUSSIAN_BLUR ); 14 | } 15 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterGrayScale.php: -------------------------------------------------------------------------------- 1 | getResource(), IMG_FILTER_GRAYSCALE ); 19 | } 20 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterHueRotate.php: -------------------------------------------------------------------------------- 1 | degrees = Args::int($degrees)->required()->min(0)->value(function($degrees){ 22 | return $degrees > 360 ? $degrees % 360 : $degrees; 23 | }); 24 | } 25 | /** 26 | * Applies the sepia filter to an image resource 27 | * 28 | * @param ImageResource $aResource 29 | */ 30 | public function applyFilter( ImageResource $aResource ) 31 | { 32 | if ($this->degrees === 0){return;} 33 | 34 | $width = $aResource->getX(); 35 | $height = $aResource->getY(); 36 | 37 | // cache calculated colors in a map... 38 | $colorMap = array(); 39 | 40 | for ($x = 0; $x < $width; ++ $x) 41 | { 42 | for ($y = 0; $y < $height; ++ $y) 43 | { 44 | $color = ColorUtil::getColorAt($aResource, Coordinate::create($x, $y)); 45 | if (!isset($colorMap[$color->getColorIndex()])){ 46 | // calculate the new color 47 | $hsl = ColorUtil::rgb2hsl($color->getRed(), $color->getGreen(), $color->getBlue()); 48 | $hsl[0] += $this->degrees; 49 | $rgb = ColorUtil::hsl2rgb($hsl[0], $hsl[1], $hsl[2]); 50 | $newcol = imagecolorallocate( $aResource->getResource(), $rgb[0], $rgb[1], $rgb[2] ); 51 | 52 | $colorMap[$color->getColorIndex()] = $newcol; 53 | } else { 54 | $newcol = $colorMap[$color->getColorIndex()]; 55 | } 56 | 57 | imagesetpixel( $aResource->getResource(), $x, $y, $newcol ); 58 | } 59 | } 60 | 61 | $colorMap = null; 62 | } 63 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterMeanRemove.php: -------------------------------------------------------------------------------- 1 | getResource(), IMG_FILTER_MEAN_REMOVAL ); 14 | } 15 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterMotionBlur.php: -------------------------------------------------------------------------------- 1 | getResource(), IMG_FILTER_NEGATE ); 20 | } 21 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterNoise.php: -------------------------------------------------------------------------------- 1 | noise = Args::int($noise)->required()->min(0)->value(); 17 | } 18 | 19 | /** 20 | * (non-PHPdoc) 21 | * @see \imagemanipulation\filter\IImageFilter::applyFilter() 22 | */ 23 | public function applyFilter( ImageResource $aResource ) 24 | { 25 | if ($this->noise === 0) 26 | { 27 | return; 28 | } 29 | 30 | $resource = $aResource->getResource(); 31 | 32 | $imagex = $aResource->getX(); 33 | $imagey = $aResource->getY(); 34 | 35 | for ($x = 0; $x < $imagex; ++ $x) 36 | { 37 | for ($y = 0; $y < $imagey; ++ $y) 38 | { 39 | if (rand( 0, 1 )) 40 | { 41 | $rgb = imagecolorat( $resource, $x, $y ); 42 | $red = ($rgb >> 16) & 0xFF; 43 | $green = ($rgb >> 8) & 0xFF; 44 | $blue = $rgb & 0xFF; 45 | $modifier = rand( $this->noise * - 1, $this->noise ); 46 | $red += $modifier; 47 | $green += $modifier; 48 | $blue += $modifier; 49 | 50 | if ($red > 255) 51 | $red = 255; 52 | if ($green > 255) 53 | $green = 255; 54 | if ($blue > 255) 55 | $blue = 255; 56 | if ($red < 0) 57 | $red = 0; 58 | if ($green < 0) 59 | $green = 0; 60 | if ($blue < 0) 61 | $blue = 0; 62 | 63 | $newcol = imagecolorallocate( $resource, $red, $green, $blue ); 64 | imagesetpixel( $resource, $x, $y, $newcol ); 65 | } 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterOldCardboard.php: -------------------------------------------------------------------------------- 1 | opacity = Args::int($opacity)->required()->min(0)->max(127)->value(); 21 | } 22 | 23 | /** 24 | * Applies the filter to the resource 25 | * 26 | * @param ImageResource $aResource 27 | */ 28 | public function applyFilter( ImageResource $aResource ) 29 | { 30 | if( !isset( $this->opacity ) ) 31 | return; 32 | 33 | $this->opacity /= 100; 34 | 35 | //get image width and height 36 | $w = $aResource->getX(); 37 | $h = $aResource->getY(); 38 | 39 | //turn alpha blending off 40 | imagealphablending( $aResource->getResource(), false ); 41 | 42 | //find the most opaque pixel in the image (the one with the smallest alpha value) 43 | $minalpha = 127; 44 | for( $x = 0; $x < $w; $x++ ) 45 | { 46 | for( $y = 0; $y < $h; $y++ ) 47 | { 48 | $alpha = ( imagecolorat( $aResource->getResource(), $x, $y ) >> 24 ) & 0xFF; 49 | if( $alpha < $minalpha ) 50 | { $minalpha = $alpha; } 51 | } 52 | } 53 | 54 | //loop through image pixels and modify alpha for each 55 | for( $x = 0; $x < $w; $x++ ) 56 | { 57 | for( $y = 0; $y < $h; $y++ ) 58 | { 59 | //get current alpha value (represents the TANSPARENCY!) 60 | $colorxy = imagecolorat( $aResource->getResource(), $x, $y ); 61 | $alpha = ( $colorxy >> 24 ) & 0xFF; 62 | //calculate new alpha 63 | if( $minalpha !== 127 ) 64 | { $alpha = 127 + 127 * $this->opacity * ( $alpha - 127 ) / ( 127 - $minalpha ); } 65 | else 66 | { $alpha += 127 * $this->opacity; } 67 | //get the color index with new alpha 68 | $alphacolorxy = imagecolorallocatealpha( $aResource->getResource(), ( $colorxy >> 16 ) & 0xFF, ( $colorxy >> 8 ) & 0xFF, $colorxy & 0xFF, $alpha ); 69 | //set pixel with the new color + opacity 70 | if( !imagesetpixel( $aResource->getResource(), $x, $y, $alphacolorxy ) ) 71 | { return; } 72 | } 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterPixelate.php: -------------------------------------------------------------------------------- 1 | blocksize = Args::int($blocksize, 'blocksize')->required()->min(1)->value(); 20 | } 21 | 22 | /** 23 | * (non-PHPdoc) 24 | * @see \imagemanipulation\filter\IImageFilter::applyFilter() 25 | */ 26 | public function applyFilter( ImageResource $aResource ) 27 | { 28 | $resource = $aResource->getResource(); 29 | $imagex = $aResource->getX(); 30 | $imagey = $aResource->getY(); 31 | 32 | for ($x = 0; $x < $imagex; $x += $this->blocksize) 33 | { 34 | for ($y = 0; $y < $imagey; $y += $this->blocksize) 35 | { 36 | // get the pixel colour at the top-left of the square 37 | $thiscol = imagecolorat( $resource, $x, $y ); 38 | 39 | // set the new red, green, and blue values to 0 40 | $newr = 0; 41 | $newg = 0; 42 | $newb = 0; 43 | 44 | // create an empty array for the colours 45 | $colours = array(); 46 | 47 | // cycle through each pixel in the block 48 | for ($k = $x; $k < $x + $this->blocksize; ++ $k) 49 | { 50 | for ($l = $y; $l < $y + $this->blocksize; ++ $l) 51 | { 52 | // if we are outside the valid bounds of the image, use a safe colour 53 | if ($k < 0) 54 | { 55 | $colours[] = $thiscol; 56 | continue; 57 | } 58 | if ($k >= $imagex) 59 | { 60 | $colours[] = $thiscol; 61 | continue; 62 | } 63 | if ($l < 0) 64 | { 65 | $colours[] = $thiscol; 66 | continue; 67 | } 68 | if ($l >= $imagey) 69 | { 70 | $colours[] = $thiscol; 71 | continue; 72 | } 73 | 74 | // if not outside the image bounds, get the colour at this pixel 75 | $colours[] = imagecolorat( $resource, $k, $l ); 76 | } 77 | } 78 | 79 | // cycle through all the colours we can use for sampling 80 | foreach ($colours as $colour) 81 | { 82 | // add their red, green, and blue values to our master numbers 83 | $newr += ($colour >> 16) & 0xFF; 84 | $newg += ($colour >> 8) & 0xFF; 85 | $newb += $colour & 0xFF; 86 | } 87 | 88 | // now divide the master numbers by the number of valid samples to get an average 89 | $numelements = count( $colours ); 90 | $newr /= $numelements; 91 | $newg /= $numelements; 92 | $newb /= $numelements; 93 | 94 | // and use the new numbers as our colour 95 | $newcol = imagecolorallocate( $resource, $newr, $newg, $newb ); 96 | imagefilledrectangle( $resource, $x, $y, $x + $this->blocksize - 1, $y + $this->blocksize - 1, $newcol ); 97 | } 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterRandomBlocks.php: -------------------------------------------------------------------------------- 1 | nrOfBlocks = Args::int($numberOfBlocks)->required()->min(1)->value(); 30 | $this->blockSize = Args::int($blockSize)->required()->min(0)->value(); 31 | // TODO blockcolor can be Object and string... add check to args 32 | 33 | $this->blockColor = $blockColor instanceof Color ? $blockColor : new Color($blockColor); 34 | } 35 | /** 36 | * Applies the filter to the resource 37 | * 38 | * @param ImageResource $aResource 39 | */ 40 | public function applyFilter( ImageResource $aResource ) 41 | { 42 | $width=$aResource->getX(); 43 | $height=$aResource->getY(); 44 | $blockImg=imagecreate(1, 1); 45 | 46 | imagecolorallocatealpha($blockImg, $this->blockColor->getRed(), $this->blockColor->getGreen(), $this->blockColor->getBlue(), $this->blockColor->getAlpha()); 47 | 48 | for($i=0;$i<=$this->nrOfBlocks;$i++) 49 | { 50 | $xPos=rand(0,$width-$this->blockSize-1); 51 | $yPos=rand(0,$height-$this->blockSize-1); 52 | imagecopy($aResource->getResource(), $blockImg, $xPos, $yPos , $xPos, $yPos , $this->blockSize , $this->blockSize); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterReplaceColor.php: -------------------------------------------------------------------------------- 1 | search = $aSearches; 22 | $this->replace = $aReplace instanceof Color ? $aReplace : new Color($aReplace); 23 | } 24 | 25 | /** 26 | * Applies the filter to the resource 27 | * 28 | * @param ImageResource $aResource 29 | */ 30 | public function applyFilter( ImageResource $aResource ) 31 | { 32 | $dest = $aResource->getResource(); 33 | if (imageistruecolor($dest)) { 34 | imagetruecolortopalette($dest, false, 256); 35 | } 36 | 37 | foreach ($this->search as $search){ 38 | $searchRgb = new Color($search); 39 | $index = imagecolorclosest ( $aResource->getResource(), $searchRgb->getRed(), $searchRgb->getGreen(), $searchRgb->getBlue() ); // get White COlor 40 | imagecolorset($aResource->getResource(), $index, $this->replace->getRed(), $this->replace->getGreen(), $this->replace->getBlue()); // SET NEW COLOR 41 | } 42 | 43 | $aResource->setResource($dest); 44 | } 45 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterReverse.php: -------------------------------------------------------------------------------- 1 | getX(); 13 | $y = $aResource->getY(); 14 | $resource = $aResource->getResource(); 15 | 16 | // Create a new image 17 | $ip = imagecreatetruecolor( $x, $y ); 18 | 19 | // Loop through the whole height of the image 20 | for ($i = 0; $i < $y; $i ++) 21 | { 22 | // Loop through the whole width of the image 23 | for ($j = 0; $j < $x; $j ++) 24 | { 25 | // Get the pixel color ( $this->img->x - 1 needs to be there because of the imagestart @ 0,0 ;) ) 26 | $c = imagecolorat( $resource, ($x - 1) - $j, $i ); 27 | 28 | // Get the rgb values from color $c 29 | $r = ($c >> 16) & 0xFF; 30 | $g = ($c >> 8) & 0xFF; 31 | $b = $c & 0xFF; 32 | 33 | // Set the color 34 | $clr = imagecolorallocate( $ip, $r, $g, $b ); 35 | 36 | // Set the pixel color in the new image 37 | imagesetpixel( $ip, $j, $i, $clr ); 38 | } 39 | } 40 | 41 | $aResource->setResource( imagecreatetruecolor( $x, $y ) ); 42 | imagecopy( $aResource->getResource(), $ip, 0, 0, 0, 0, $x, $y ); 43 | } 44 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterRoundedCorners.php: -------------------------------------------------------------------------------- 1 | radius = Args::int($radius, 'radius')->required()->min(0)->max(360)->value(); 18 | 19 | $this->color = $color ? $color : new Color('ffffff'); 20 | } 21 | 22 | /** 23 | * (non-PHPdoc) 24 | * @see \imagemanipulation\filter\IImageFilter::applyFilter() 25 | */ 26 | public function applyFilter( ImageResource $resource ) 27 | { 28 | if ($this->radius === 0) 29 | { 30 | return; 31 | } 32 | 33 | $source_image = $resource->getResource(); 34 | $source_width = $resource->getX(); 35 | $source_height = $resource->getY(); 36 | 37 | $corner_image = imagecreatetruecolor($this->radius,$this->radius); 38 | $clear_colour = imagecolorallocate($corner_image,0,0,0); 39 | imagecolortransparent($corner_image,$clear_colour); 40 | 41 | $solid_colour = imagecolorallocate($corner_image, $this->color->getRed(), $this->color->getGreen(), $this->color->getBlue()); 42 | 43 | imagefill($corner_image,0,0,$solid_colour); 44 | imagefilledellipse($corner_image,$this->radius,$this->radius,$this->radius * 2,$this->radius * 2,$clear_colour); 45 | 46 | /* 47 | * render the top-left, bottom-left, bottom-right, top-right corners by rotating and copying the mask 48 | */ 49 | imagecopymerge($source_image,$corner_image,0,0,0,0,$this->radius,$this->radius,100); 50 | 51 | $corner_image = imagerotate($corner_image, 90, 0); 52 | imagecopymerge($source_image,$corner_image,0,$source_height - $this->radius,0,0,$this->radius,$this->radius,100); 53 | 54 | $corner_image = imagerotate($corner_image, 90, 0); 55 | imagecopymerge($source_image,$corner_image,$source_width - $this->radius, $source_height - $this->radius,0,0,$this->radius,$this->radius,100); 56 | 57 | $corner_image = imagerotate($corner_image, 90, 0); 58 | imagecopymerge($source_image,$corner_image,$source_width - $this->radius,0,0,0,$this->radius,$this->radius,100); 59 | } 60 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterScatter.php: -------------------------------------------------------------------------------- 1 | Default 10 | * 11 | *

Rate = 10

12 | * 13 | *

Rate = 20

14 | * 15 | * 16 | *@see http://www.tuxradar.com/practicalphp/11/2/23 17 | */ 18 | class ImageFilterScatter implements IImageFilter 19 | { 20 | private $offset; 21 | 22 | /** 23 | * 24 | * @param number $aOffset 25 | */ 26 | public function __construct( $offset = 4 ) 27 | { 28 | $this->offset = Args::int($offset, 'offset')->required()->min(1)->value(); 29 | } 30 | /** 31 | * Applies the sepia filter to an image resource 32 | * 33 | * @param ImageResource $aResource 34 | */ 35 | public function applyFilter( ImageResource $aResource ) 36 | { 37 | if ($this->offset === 0) 38 | { 39 | return; 40 | } 41 | 42 | $resource = $aResource->getResource(); 43 | 44 | $imagex = imagesx( $resource ); 45 | $imagey = imagesy( $resource ); 46 | 47 | for ($x = 0; $x < $imagex; ++ $x) 48 | { 49 | for ($y = 0; $y < $imagey; ++ $y) 50 | { 51 | $distx = rand( $this->offset * - 1, $this->offset ); 52 | $disty = rand( $this->offset * - 1, $this->offset ); 53 | 54 | if ($x + $distx >= $imagex) 55 | continue; 56 | if ($x + $distx < 0) 57 | continue; 58 | if ($y + $disty >= $imagey) 59 | continue; 60 | if ($y + $disty < 0) 61 | continue; 62 | 63 | $oldcol = imagecolorat( $resource, $x, $y ); 64 | $newcol = imagecolorat( $resource, $x + $distx, $y + $disty ); 65 | imagesetpixel( $resource, $x, $y, $newcol ); 66 | imagesetpixel( $resource, $x + $distx, $y + $disty, $oldcol ); 67 | } 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterSelectiveBlur.php: -------------------------------------------------------------------------------- 1 | getResource(), IMG_FILTER_SELECTIVE_BLUR ); 14 | } 15 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterSemiGrayScale.php: -------------------------------------------------------------------------------- 1 | percentage = Args::int($percentage, 'percentage')->required()->min(0)->max(100)->value(); 20 | } 21 | 22 | /** 23 | * Applies the filter to the resource 24 | * 25 | * @param ImageResource $aResource 26 | */ 27 | public function applyFilter(ImageResource $aResource) 28 | { 29 | if ($this->percentage === 0) { 30 | return $aResource; 31 | } else if ($this->percentage === 100) { 32 | $filter = new ImageFilterGrayScale(); 33 | $filter->applyFilter($aResource); 34 | } else { 35 | $clone = $aResource->cloneResource(); 36 | $filter = new ImageFilterGrayScale(); 37 | $filter->applyFilter($clone); 38 | 39 | $overlayFilter = new ImageFilterOverlay($clone, $this->percentage); // grayscale clone 40 | $overlayFilter->applyFilter($aResource); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterSepia.php: -------------------------------------------------------------------------------- 1 | darken = Args::int($darken, 'darken')->required()->min(0)->value(); 26 | } 27 | 28 | /** 29 | * Applies the sepia filter to an image resource 30 | * 31 | * @param ImageResource $aResource 32 | */ 33 | public function applyFilter( ImageResource $aResource ) 34 | { 35 | $dstImg = $aResource->getResource(); 36 | $imgX = $aResource->getX(); 37 | $imgY = $aResource->getY(); 38 | $previous = array("index" => -1, "result" => 0); 39 | 40 | for ($y = 0; $y < $imgY; $y ++) 41 | { 42 | for ($x = 0; $x < $imgX; $x ++) 43 | { 44 | $dstRGB = imagecolorat( $dstImg, $x, $y ); 45 | if ($previous["index"] === $dstRGB) { 46 | $newRGB = $previous["result"]; 47 | } else { 48 | $dstR = $dstRGB >> 16 & 0xFF; 49 | $dstG = $dstRGB >> 8 & 0xFF; 50 | $dstB = $dstRGB & 0xFF; 51 | 52 | $newR = ($dstR * 0.393 + $dstG * 0.769 + $dstB * 0.189) - $this->darken; 53 | $newG = ($dstR * 0.349 + $dstG * 0.686 + $dstB * 0.168) - $this->darken; 54 | $newB = ($dstR * 0.272 + $dstG * 0.534 + $dstB * 0.131) - $this->darken; 55 | 56 | $newR = ($newR > 255) ? 255 : (($newR < 0) ? 0 : $newR); 57 | $newG = ($newG > 255) ? 255 : (($newG < 0) ? 0 : $newG); 58 | $newB = ($newB > 255) ? 255 : (($newB < 0) ? 0 : $newB); 59 | 60 | $newRGB = imagecolorallocate( $dstImg, $newR, $newG, $newB ); 61 | 62 | $previous["index"] = $dstRGB; 63 | $previous["result"] = $newRGB; 64 | } 65 | 66 | imagesetpixel( $dstImg, $x, $y, $newRGB ); 67 | } 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterSepiaFast.php: -------------------------------------------------------------------------------- 1 | opacity = Args::int($darken, 'darken')->required()->min(0)->value(function($opacity){ 21 | return 127 - min(array($opacity + 30, 127)); 22 | }); 23 | } 24 | 25 | /** 26 | * Applies the sepia filter to an image resource 27 | * 28 | * @param ImageResource $aResource 29 | */ 30 | public function applyFilter( ImageResource $aResource ) 31 | { 32 | imagefilter($aResource->getResource(), IMG_FILTER_GRAYSCALE); 33 | imagefilter( $aResource->getResource(), IMG_FILTER_CONTRAST, -5 ); 34 | imagefilter($aResource->getResource(), IMG_FILTER_COLORIZE, 100,50,0, $this->opacity); 35 | } 36 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterSharpen.php: -------------------------------------------------------------------------------- 1 | rate = Args::int($rate, 'rate')->required()->min(0)->value(); 28 | } 29 | 30 | /** 31 | * Applies the filter to an image resource 32 | * 33 | * @param ImageResource $aResource 34 | */ 35 | public function applyFilter( ImageResource $aResource ) 36 | { 37 | assert( '$this->rate !== null' ); 38 | 39 | imagefilter( $aResource->getResource(), IMG_FILTER_SMOOTH, $this->rate ); 40 | } 41 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterSobel.php: -------------------------------------------------------------------------------- 1 | filter(new ImageFilterGrayScale()); 19 | } 20 | 21 | protected function afterApplyFilter(ImageResource $aResource) { 22 | $aResource->filter(new ImageFilterNegative()); 23 | } 24 | 25 | protected function getDivision() { 26 | return .2; 27 | } 28 | 29 | protected function getOffset() { 30 | return 512; 31 | } 32 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterSobelEdgeDetect.php: -------------------------------------------------------------------------------- 1 | getResource(); 21 | // this will be the final image, same width and height of the original 22 | $final = imagecreatetruecolor($aResource->getX(), $aResource->getY()); 23 | // looping through ALL pixels!! 24 | for($x=1;$x<$aResource->getX()-1;$x++){ 25 | for($y=1;$y<$aResource->getY()-1;$y++){ 26 | // getting gray value of all surrounding pixels 27 | $pixel_up = $this->getLuminance(imagecolorat($starting_img,$x,$y-1)); 28 | $pixel_down = $this->getLuminance(imagecolorat($starting_img,$x,$y+1)); 29 | $pixel_left = $this->getLuminance(imagecolorat($starting_img,$x-1,$y)); 30 | $pixel_right = $this->getLuminance(imagecolorat($starting_img,$x+1,$y)); 31 | $pixel_up_left = $this->getLuminance(imagecolorat($starting_img,$x-1,$y-1)); 32 | $pixel_up_right = $this->getLuminance(imagecolorat($starting_img,$x+1,$y-1)); 33 | $pixel_down_left = $this->getLuminance(imagecolorat($starting_img,$x-1,$y+1)); 34 | $pixel_down_right = $this->getLuminance(imagecolorat($starting_img,$x+1,$y+1)); 35 | 36 | // appliying convolution mask 37 | $conv_x = ($pixel_up_right+($pixel_right*2)+$pixel_down_right)-($pixel_up_left+($pixel_left*2)+$pixel_down_left); 38 | $conv_y = ($pixel_up_left+($pixel_up*2)+$pixel_up_right)-($pixel_down_left+($pixel_down*2)+$pixel_down_right); 39 | 40 | // calculating the distance 41 | $gray = (int)sqrt($conv_x*$conv_x+$conv_y+$conv_y); 42 | 43 | // inverting the distance not to get the negative image 44 | $gray = 255-$gray; 45 | 46 | // adjusting distance if it's greater than 255 or less than zero (out of color range) 47 | if($gray > 255){ 48 | $gray = 255; 49 | } 50 | if($gray < 0){ 51 | $gray = 0; 52 | } 53 | 54 | // creation of the new gray 55 | $new_gray = imagecolorallocate($final,$gray,$gray,$gray); 56 | 57 | // adding the gray pixel to the new image 58 | imagesetpixel($final,$x,$y,$new_gray); 59 | } 60 | } 61 | imagedestroy($starting_img); 62 | $aResource->setResource($final); 63 | 64 | set_time_limit($orig_time_limit); 65 | } 66 | 67 | /** 68 | * Get the luminance value 69 | */ 70 | private function getLuminance($pixel){ 71 | $pixel = sprintf('%06x',$pixel); 72 | $red = hexdec(substr($pixel,0,2))*0.30; 73 | $green = hexdec(substr($pixel,2,2))*0.59; 74 | $blue = hexdec(substr($pixel,4))*0.11; 75 | return $red+$green+$blue; 76 | } 77 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterSobelEdgeEnhance.php: -------------------------------------------------------------------------------- 1 | filter(new ImageFilterGrayScale()); 19 | } 20 | 21 | protected function afterApplyFilter(ImageResource $aResource) { 22 | $aResource->filter(new ImageFilterNegative()); 23 | } 24 | 25 | protected function getDivision() { 26 | return -.5; 27 | } 28 | 29 | protected function getOffset() { 30 | return 0; 31 | } 32 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterSobelScharr.php: -------------------------------------------------------------------------------- 1 | filter(new ImageFilterGrayScale()); 18 | } 19 | 20 | protected function getDivision() { 21 | return .2; 22 | } 23 | 24 | protected function getOffset() { 25 | return 2048; 26 | } 27 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterSobelVertical.php: -------------------------------------------------------------------------------- 1 | filter(new ImageFilterGrayScale()); 18 | } 19 | 20 | protected function afterApplyFilter(ImageResource $aResource) { 21 | $aResource->filter(new ImageFilterNegative()); 22 | } 23 | 24 | protected function getDivision() { 25 | return .01; 26 | } 27 | 28 | protected function getOffset() { 29 | return 0; 30 | } 31 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterTrueColor.php: -------------------------------------------------------------------------------- 1 | lowcolor = $aLowColor instanceof Color ? $aLowColor : new Color($aLowColor); 21 | $this->highcolor = $aHighColor instanceof Color ? $aHighColor : new Color($aHighColor); 22 | } 23 | /** 24 | * Applies the filter to the resource 25 | * 26 | * @param ImageResource $aResource 27 | */ 28 | public function applyFilter( ImageResource $aResource ) 29 | { 30 | //comic effect 31 | $width = $aResource->getX(); 32 | $height = $aResource->getY(); 33 | 34 | $imgK=imagecreatetruecolor($width,$height); 35 | 36 | $lowR = $this->lowcolor->getRed(); 37 | $lowG = $this->lowcolor->getGreen(); 38 | $lowB = $this->lowcolor->getBlue(); 39 | 40 | $highR = $this->highcolor->getRed(); 41 | $highG = $this->highcolor->getGreen(); 42 | $highB = $this->highcolor->getBlue(); 43 | 44 | for($y=0;$y<$height;$y++){ 45 | for($x=0;$x<$width;$x++){ 46 | $rgb = imagecolorat($aResource->getResource(), $x, $y); 47 | $r = ($rgb >> 16) & 0xFF; 48 | $g = ($rgb >> 8) & 0xFF; 49 | $b = $rgb & 0xFF; 50 | $bw=$r+$g+$b>300?imagecolorallocate($imgK,$lowR,$lowG,$lowB):imagecolorallocate($imgK,$highR,$highG,$highB); 51 | imagesetpixel($imgK,$x,$y,$bw); 52 | } 53 | } 54 | 55 | $aResource->setResource($imgK); 56 | } 57 | } -------------------------------------------------------------------------------- /src/imagemanipulation/filter/ImageFilterVignette.php: -------------------------------------------------------------------------------- 1 | width = $aResource->getX(); 22 | $this->height = $aResource->getY(); 23 | $im = $aResource->getResource(); 24 | 25 | for($x = 0; $x < $this->width; ++$x){ 26 | for($y = 0; $y < $this->height; ++$y){ 27 | $index = imagecolorat($im, $x, $y); 28 | $rgb = imagecolorsforindex($im, $index); 29 | $this->vignetteToPixel($x, $y, $rgb); 30 | $color = imagecolorallocate($im, $rgb['red'], $rgb['green'], $rgb['blue']); 31 | 32 | imagesetpixel($im, $x, $y, $color); 33 | } 34 | } 35 | } 36 | 37 | private function vignetteToPixel($x, $y, &$rgb){ 38 | $sharp = 0.4; // 0 - 10 small is sharpnes, 39 | $level = 0.7; // 0 - 1 small is brighter 40 | 41 | $l = sin(M_PI / $this->width * $x) * sin(M_PI / $this->height * $y); 42 | $l = pow($l, $sharp); 43 | 44 | $l = 1 - $level * (1 - $l); 45 | 46 | $rgb['red'] *= $l; 47 | $rgb['green'] *= $l; 48 | $rgb['blue'] *= $l; 49 | } 50 | } -------------------------------------------------------------------------------- /src/imagemanipulation/generation/ImageGenerator.php: -------------------------------------------------------------------------------- 1 | required()->min(1); 22 | Args::int($height, 'height')->required()->min(1); 23 | 24 | $res = new ImageResource( imagecreatetruecolor($width, $height) ); 25 | $color = ImageUtil::allocateColor($res->getResource(), $color); 26 | imagefill($res->getResource(), 0, 0, $color); 27 | $res->saveAlpha(); 28 | 29 | return $res; 30 | } 31 | 32 | /** 33 | * Generate a gradient image 34 | * 35 | * @param int $width The new image width in pixels 36 | * @param int $height The new image height in pixels 37 | * @param int $start The start of the gradient in pixels 38 | * @param Color $src_color The start image color 39 | * @param Color $dest_color The end image color 40 | * 41 | * @return \imagemanipulation\ImageResource 42 | */ 43 | public static function gradient($width, $height, $start, Color $src_color, Color $dest_color){ 44 | Args::int($width, 'width')->required()->min(1); 45 | Args::int($height, 'height')->required()->min(1); 46 | 47 | $res = self::create($width, $height, $src_color); 48 | $img = $res->getResource(); 49 | 50 | $srcA = $src_color->getAlpha(); 51 | $srcR = $src_color->getRed(); 52 | $srcG = $src_color->getGreen(); 53 | $srcB = $src_color->getBlue(); 54 | 55 | $destA = $dest_color->getAlpha(); 56 | $destR = $dest_color->getRed(); 57 | $destG = $dest_color->getGreen(); 58 | $destB = $dest_color->getBlue(); 59 | 60 | $incA = ($destA - $srcA) / ($width - $start); 61 | $incR = ($destR - $srcR) / ($width - $start); 62 | $incG = ($destG - $srcG) / ($width - $start); 63 | $incB = ($destB - $srcB) / ($width - $start); 64 | 65 | for ($i=$start;$i<$width;$i++){ 66 | $srcA += $incA; 67 | $srcB += $incB; 68 | $srcG += $incG; 69 | $srcR += $incR; 70 | imagefilledrectangle($img, $i, 0, $i, $height, 71 | imagecolorallocatealpha($img, $srcR, $srcG, $srcB, $srcA) 72 | ); 73 | } 74 | 75 | return $res; 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /src/imagemanipulation/overlay/ImageFilterOverlay.php: -------------------------------------------------------------------------------- 1 | startX = Args::int($startX, 'startX')->required()->min(0)->value(); 33 | $this->startY = Args::int($startY, 'startY')->required()->min(0)->value(); 34 | $this->opacity = Args::int($opacity, 'opacity')->required()->min(1)->max(100)->value(); 35 | $this->fill = Args::bool($fill, 'fill')->required()->value(); 36 | 37 | $this->overlay = $overlay; 38 | } 39 | 40 | /** 41 | * (non-PHPdoc) 42 | * @see \imagemanipulation\filter\IImageFilter::applyFilter() 43 | */ 44 | public function applyFilter(ImageResource $aResource) 45 | { 46 | $placeholder = imagecreatetruecolor($aResource->getX(), $aResource->getY()); 47 | imagealphablending($placeholder, false); 48 | imagesavealpha($placeholder,true); 49 | 50 | $destWidth = $this->fill ? $aResource->getX() : $this->overlay->getX(); 51 | $destHeight = $this->fill ? $aResource->getY() : $this->overlay->getY(); 52 | 53 | imagecopyresized($placeholder, $this->overlay->getResource(), 0, 0, 0, 0, $destWidth, $destHeight, $this->overlay->getX(), $this->overlay->getY()); 54 | imagecopymerge($aResource->getResource(), $placeholder, $this->startX, $this->startY, 0, 0, $destWidth, $destHeight, $this->opacity); 55 | } 56 | } -------------------------------------------------------------------------------- /src/imagemanipulation/overlay/ImageFilterOverlayWithAlpha.php: -------------------------------------------------------------------------------- 1 | overlay = $aOverlay; 30 | $this->startX = $startX; 31 | $this->startY = $startY; 32 | $this->fill = $fill; 33 | } 34 | 35 | /** 36 | * (non-PHPdoc) 37 | * @see \imagemanipulation\filter\IImageFilter::applyFilter() 38 | */ 39 | public function applyFilter(ImageResource $aResource) 40 | { 41 | $destWidth = $this->fill ? $aResource->getX() : $this->overlay->getX(); 42 | $destHeight = $this->fill ? $aResource->getY() : $this->overlay->getY(); 43 | 44 | imagealphablending($this->overlay->getResource(), false); 45 | imagesavealpha($this->overlay->getResource(), false); 46 | 47 | imagecopyresized($this->overlay->getResource(), $this->overlay->getResource(), 0, 0, 0, 0, $destWidth, $destHeight, $this->overlay->getX(), $this->overlay->getY()); 48 | 49 | imagealphablending($aResource->getResource(), true); 50 | imagesavealpha($aResource->getResource(), true); 51 | 52 | imagecopyresampled($aResource->getResource(), $this->overlay->getResource(), $this->startX, $this->startY, 0, 0, $destWidth, $destHeight, $destWidth, $destHeight); 53 | } 54 | } -------------------------------------------------------------------------------- /src/imagemanipulation/rasterize/ImageRaster.php: -------------------------------------------------------------------------------- 1 | segments = new \ArrayObject(); 15 | } 16 | 17 | /** 18 | * 19 | * @param Segment $segment 20 | */ 21 | public function addSegment(Segment $segment) { 22 | $this->segments->append($segment); 23 | } 24 | 25 | /** 26 | * 27 | * @return number 28 | */ 29 | public function count() { 30 | return $this->segments->count(); 31 | } 32 | 33 | /** 34 | * 35 | * @return \ArrayObject 36 | */ 37 | public function getSegments() { 38 | return $this->segments; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/imagemanipulation/rasterize/Rasterizer.php: -------------------------------------------------------------------------------- 1 | resource = new ImageImageResource($image); 26 | $this->raster = $strategy->createRaster($this->resource); 27 | } 28 | 29 | /** 30 | * Returns all the segments 31 | * @return ArrayObject 32 | */ 33 | public function getSegments() { 34 | return $this->raster->getSegments(); 35 | } 36 | 37 | /** 38 | * Apply a filter on the location of a segment 39 | * 40 | * @param IImageFilter $filter the filter to apply 41 | * @param Segment $segment the location to apply the filter on 42 | * 43 | * @return Rasterizer for chaining 44 | */ 45 | public function filter(IImageFilter $filter, Segment $segment) { 46 | $resource = $this->createResource($segment); 47 | 48 | $resource->filter($filter); 49 | 50 | $this->writeSegment($resource, $segment); 51 | 52 | return $this; 53 | } 54 | 55 | /** 56 | * Create a new resource from the location of the segment 57 | * 58 | * @param Segment $segment 59 | * 60 | * @return \imagemanipulation\ImageResource 61 | */ 62 | public function createResource(Segment $segment) { 63 | $resource = new ImageResource(ImageUtil::createImage($segment->getWidth(), $segment->getHeight())); 64 | 65 | imagecopy( 66 | $resource->getResource(), $this->resource->getResource(), 67 | 0 ,0, // dest img 68 | $segment->getCoordinate()->getX(), $segment->getCoordinate()->getY(), // src img 69 | $segment->getWidth(), $segment->getHeight() // src dimensions 70 | ); 71 | 72 | return $resource; 73 | } 74 | 75 | /** 76 | * Write the resource back to it's owner 77 | * @param ImageResource $resource 78 | * @param Segment $segment 79 | * @throws ImageResourceException when segment's dimensions do not match resource dimensions 80 | */ 81 | public function writeSegment(ImageResource $resource, Segment $segment) { 82 | if ($resource->getWidth() !== $segment->getWidth() || $resource->getHeight() !== $segment->getHeight()) { 83 | throw new ImageResourceException("Dimensions of resource and segment differ"); 84 | } 85 | 86 | imagecopy( 87 | $this->resource->getResource(), $resource->getResource(), 88 | $segment->getCoordinate()->getX(), $segment->getCoordinate()->getY(), // dest img 89 | 0, 0, // src img 90 | $segment->getWidth(), $segment->getHeight() // src dimensions 91 | ); 92 | } 93 | 94 | /** 95 | * Returns the underlying resource of the whole image 96 | * 97 | * @return \imagemanipulation\ImageImageResource 98 | */ 99 | public function getResource() { 100 | return $this->resource; 101 | } 102 | } -------------------------------------------------------------------------------- /src/imagemanipulation/rasterize/Segment.php: -------------------------------------------------------------------------------- 1 | coordinate = new Coordinate($x, $y); 14 | $this->width = $width; 15 | $this->height = $height; 16 | } 17 | 18 | public function getCoordinate() { 19 | return $this->coordinate; 20 | } 21 | 22 | public function getHeight() { 23 | return $this->height; 24 | } 25 | 26 | public function getWidth() { 27 | return $this->width; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/imagemanipulation/rasterize/strategy/AbstractRasterStrategy.php: -------------------------------------------------------------------------------- 1 | min(1)->max(100)->required(); 23 | Args::int($height, 'height')->min(1)->max(100)->required(); 24 | } else { 25 | Args::int($width, 'width')->min(1)->required(); 26 | Args::int($height, 'height')->min(1)->required(); 27 | } 28 | 29 | $this->width = $width; 30 | $this->height = $height; 31 | $this->isPercentage = $isPercentage; 32 | } 33 | 34 | public function createRaster(ImageResource $resource) { 35 | if ($this->isPercentage) { 36 | $this->calculatePercentage($resource); 37 | } 38 | 39 | $raster = new ImageRaster(); 40 | $segment = new Segment($resource->getWidth() - ($this->width / 2), $resource->getHeight() - ($this->height / 2), $this->width, $this->height); 41 | $raster->addSegment($segment); 42 | 43 | return $raster; 44 | } 45 | 46 | private function calculatePercentage(ImageResource $resource) { 47 | assert ($this->isPercentage === true); 48 | 49 | $this->height = ($resource->getHeight() / 100) * $this->height; 50 | $this->width = ($resource->getWidth() / 100) * $this->width; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/imagemanipulation/rasterize/strategy/GridRasterStrategy.php: -------------------------------------------------------------------------------- 1 | min(1)->max(100)->required(); 18 | Args::int($height, 'height')->min(1)->max(100)->required(); 19 | } else { 20 | Args::int($width, 'width')->min(1)->required(); 21 | Args::int($height, 'height')->min(1)->required(); 22 | } 23 | 24 | $this->width = $width; 25 | $this->height = $height; 26 | $this->isPercentage = $isPercentage; 27 | } 28 | 29 | public function createRaster(ImageResource $resource) { 30 | if ($this->isPercentage) { 31 | $this->calculatePercentage($resource); 32 | } 33 | 34 | $raster = new ImageRaster(); 35 | $x = $y = 0; 36 | 37 | while ($x <= $resource->getWidth() && $y <= $resource->getHeight()) { 38 | $segment = new Segment($x, $y, min(array($this->width, $resource->getWidth() - $x)), min(array($this->height, $resource->getHeight() - $y))); 39 | $raster->addSegment($segment); 40 | 41 | // new row 42 | if ($x + $this->width >= $resource->getWidth()) { 43 | $x = 0; 44 | $y += $this->height; 45 | } else { 46 | $x += $this->width; 47 | } 48 | 49 | if ($y >= $resource->getHeight()) { 50 | return $raster; 51 | } 52 | } 53 | 54 | return $raster; 55 | } 56 | 57 | private function calculatePercentage(ImageResource $resource) { 58 | assert ($this->isPercentage === true); 59 | 60 | $this->height = (int) round(($resource->getHeight() / 100) * $this->height); 61 | $this->width = (int) round(($resource->getWidth() / 100) * $this->width); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/imagemanipulation/reflection/ImageFilterReflection.php: -------------------------------------------------------------------------------- 1 | height = Args::int($height, 'height')->required()->min(1)->value(); 29 | $this->startOpacity = Args::int($startOpacity, 'Start Opacity')->required()->min(0)->max(100)->value(); 30 | $this->includeOriginal = Args::bool($includeOriginal, 'includeOriginal')->required()->value(); 31 | $this->backgroundColor = $backgroundColor instanceof Color ? $backgroundColor : new Color($backgroundColor); 32 | $this->divLineHeight = Args::int($divLineHeight, 'divLineHeight')->required()->min(0)->value(); 33 | } 34 | /** 35 | * Applies the filter to the resource 36 | * 37 | * @param ImageResource $aResource 38 | */ 39 | public function applyFilter( ImageResource $aResource ) 40 | { 41 | $width = $aResource->getWidth(); 42 | $height = $aResource->getHeight(); 43 | 44 | $lineRes = imagecreatetruecolor($width, 1); 45 | $bgc = imagecolorallocatealpha($lineRes,$this->backgroundColor->getRed(), $this->backgroundColor->getGreen(), $this->backgroundColor->getBlue(), $this->backgroundColor->getAlpha() ); // Background color 46 | imagefilledrectangle($lineRes, 0, 0, $width, 1, $bgc); 47 | 48 | $rotated = $aResource->cloneResource(); 49 | $rotateFilter = new ImageFilterRotate(180, $this->backgroundColor); 50 | $rotateFilter->applyFilter($rotated); 51 | 52 | $bg = imagecreatetruecolor($width, $this->height); 53 | imagecopyresampled($bg, $rotated->getResource(), 0, 0, 0, 0, $width, $height, $width, $height); 54 | $im = $bg; 55 | $bg = imagecreatetruecolor($width, $this->height); 56 | for ($x = 0; $x < $width; $x++) { 57 | imagecopy($bg, $im, $x, 0, $width-$x, 0, 1, $this->height); 58 | } 59 | $im = $bg; 60 | 61 | $in = 100 / $this->height; 62 | for($i = 0; $i <= $this->height; $i++){ 63 | imagecopymerge($im, $lineRes, 0, $i, 0, 0, $width, 1, $this->startOpacity); 64 | if ($this->startOpacity < 100) $this->startOpacity += $in; 65 | } 66 | imagecopymerge($im, $lineRes, 0, 0, 0, 0, $width, $this->divLineHeight, 100); // Divider 67 | 68 | if ($this->includeOriginal) { 69 | // we need to include the original 70 | $mergeWidth = imagesx($im) + $aResource->getWidth(); 71 | $mergeHeight = imagesy($im) + $aResource->getHeight(); 72 | $imMerge = imagecreatetruecolor($width, $mergeHeight); 73 | imagecopy($imMerge, $aResource->getResource(), 0, 0, 0, 0, $width, $height); 74 | imagecopy($imMerge, $im, 0, $aResource->getHeight(), 0, 0, $width, $height); 75 | $aResource->setResource($imMerge); 76 | } else { 77 | $aResource->setResource($im); 78 | } 79 | 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /src/imagemanipulation/repeater/ImageRepeater.php: -------------------------------------------------------------------------------- 1 | resource = $aResource; 16 | $this->width= Args::int($width, 'width')->required()->min(0)->value(); 17 | $this->height=Args::int($height, 'height')->required()->min(0)->value(); 18 | } 19 | 20 | public function apply(){ 21 | $res = ImageUtil::createTransparentImage($this->width, $this->height); 22 | 23 | $horizontal = 0; 24 | $vertical = 0; 25 | 26 | while ($horizontal < $this->width && $vertical < $this->height){ 27 | 28 | $width = min( 500, $this->width - $horizontal); 29 | $height = min( 500, $this->height - $vertical); 30 | 31 | $result = imagecopy($res, $this->resource->getResource(), $horizontal, $vertical, 0, 0, $width, $height); 32 | if (!$result) throw new \Exception ('Could not copy image'); 33 | 34 | $horizontal += $this->resource->getX(); 35 | if ($horizontal >= $this->width){ 36 | $horizontal = 0; 37 | $vertical += $this->resource->getY(); 38 | } 39 | } 40 | 41 | return new ImageResource($res); 42 | } 43 | } -------------------------------------------------------------------------------- /src/imagemanipulation/rotate/ImageFilterRotate.php: -------------------------------------------------------------------------------- 1 | angle = Args::int($angle, 'angle')->required()->min(-360)->max(360)->value(function($val){ 35 | return $val < 0 ? 360 - $val : $val; 36 | }); 37 | 38 | if ($bgColor === null) 39 | { 40 | $this->bgColor = ColorFactory::white(); 41 | } 42 | else 43 | { 44 | $this->bgColor = $bgColor instanceof Color ? $bgColor : new Color($bgColor); 45 | } 46 | 47 | } 48 | 49 | /** 50 | * Applies the filter to the image resource 51 | * 52 | * @param ImageResource $aResource 53 | */ 54 | public function applyFilter( ImageResource $aResource ) 55 | { 56 | if ($this->angle == 0 || $this->angle == 360) 57 | { 58 | return; 59 | } 60 | 61 | imageantialias($aResource->getResource(), true); 62 | 63 | $aResource->setResource( imagerotate( $aResource->getResource(), $this->angle, $this->bgColor->getColorIndex(), $this->bgColor->getAlpha() ) ); 64 | 65 | $new_imgres = imagecreatetruecolor( $aResource->getX(), $aResource->getY() ); 66 | $success = imagecopy( $new_imgres, $aResource->getResource(), 0, 0, 0, 0, $aResource->getX(), $aResource->getY() ); 67 | 68 | if (! $success) 69 | { 70 | throw new FilterException( self::$filterType ); 71 | } 72 | 73 | imagedestroy( $new_imgres ); 74 | } 75 | } -------------------------------------------------------------------------------- /src/imagemanipulation/thumbnail/Thumbalizer.php: -------------------------------------------------------------------------------- 1 | strategy = $aStrategy; 26 | } 27 | 28 | /** 29 | * Create the thumbnail 30 | * 31 | * @param $aResource ImageResource The image resource of the original image 32 | * 33 | * @return ImageResource The image resource of the thumbnail 34 | */ 35 | public function create( ImageResource $aResource ) 36 | { 37 | // The original PHP image resource 38 | $origImgRes = $aResource->getResource(); 39 | 40 | // Create a new image resource 41 | $newResource = clone $aResource; 42 | 43 | $this->strategy->init( $aResource ); 44 | $originalBegin = $this->strategy->getSourceBegin( $newResource ); 45 | $originalEnd = $this->strategy->getSourceEnd( $newResource ); 46 | $targetBegin = $this->strategy->getDestinationBegin( $aResource ); 47 | $targetEnd = $this->strategy->getDestinationEnd( $newResource ); 48 | 49 | // no change, return original 50 | if ($originalBegin == $targetBegin && $originalEnd == $targetEnd) 51 | { 52 | return $aResource; 53 | } 54 | 55 | $aResource->setResource( imagecreatetruecolor( $targetEnd->getX(), $targetEnd->getY() ) ); 56 | 57 | imagecolortransparent( $aResource->getResource(), imagecolorallocate( $newResource->getResource(), 0, 0, 0 ) ); 58 | imagealphablending( $aResource->getResource(), false ); 59 | imageantialias( $aResource->getResource(), true ); 60 | 61 | imagecopyresampled( $aResource->getResource(), $newResource->getResource(), $targetBegin->getX(), $targetBegin->getY(), $originalBegin->getX(), $originalBegin->getY(), $targetEnd->getX(), $targetEnd->getY(), $originalEnd->getX(), $originalEnd->getY() ); 62 | 63 | $aResource->setResource($aResource->getResource()); 64 | $newResource->destroy(); 65 | 66 | return $aResource; 67 | } 68 | } -------------------------------------------------------------------------------- /src/imagemanipulation/thumbnail/pixelstrategy/IPixelStrategy.php: -------------------------------------------------------------------------------- 1 | maxWidth = Args::int($maxWidth, 'maxWidth')->required()->min(0)->value(); 32 | $this->maxHeight = Args::int($maxHeight, 'maxHeight')->required()->min(0)->value(); 33 | } 34 | 35 | /** 36 | * @see IPixelStrategy::getDestinationBegin() 37 | * 38 | * @param ImageResource $aResource 39 | * 40 | * @return imagemanipulation\Coordinate 41 | */ 42 | public function getDestinationBegin( ImageResource $aResource ) 43 | { 44 | return new Coordinate( 0, 0 ); 45 | } 46 | 47 | /** 48 | * @see IPixelStrategy::getDestinationEnd() 49 | * 50 | * @param ImageResource $aResource 51 | * @return imagemanipulation\Coordinate 52 | */ 53 | public function getDestinationEnd( ImageResource $aResource ) 54 | { 55 | $x = $aResource->getX(); 56 | $y = $aResource->getY(); 57 | $factor = 1; 58 | 59 | if ($x > $this->maxWidth && $y > $this->maxHeight) 60 | { 61 | if ($x - $this->maxWidth > $y - $this->maxHeight) 62 | { 63 | $factor = ($this->maxWidth / $x); 64 | } 65 | else 66 | { 67 | $factor = ($this->maxHeight / $y); 68 | } 69 | } 70 | else { 71 | if ($x > $this->maxWidth) 72 | { 73 | if ($x - $this->maxWidth > $y - $this->maxHeight) 74 | { 75 | $factor = ($this->maxWidth / $x); 76 | } 77 | else 78 | { 79 | $factor = ($this->maxHeight / $y); 80 | } 81 | } 82 | elseif ($y > $this->maxHeight) 83 | { 84 | if ($x - $this->maxWidth > $y - $this->maxHeight) 85 | { 86 | $factor = ($this->maxWidth / $x); 87 | } 88 | else 89 | { 90 | $factor = ($this->maxHeight / $y); 91 | } 92 | } 93 | } 94 | return new Coordinate( (int) ($x * $factor), (int) ($y * $factor) ); 95 | } 96 | 97 | /** 98 | * @see IPixelStrategy::getSourceBegin() 99 | * 100 | * @param ImageResource $aResource 101 | * @return imagemanipulation\Coordinate 102 | */ 103 | public function getSourceBegin( ImageResource $aResource ) 104 | { 105 | return new Coordinate( 0, 0 ); 106 | } 107 | 108 | /** 109 | * @see IPixelStrategy::getSourceEnd() 110 | * 111 | * @param ImageResource $aResource 112 | * @return imagemanipulation\Coordinate 113 | */ 114 | public function getSourceEnd( ImageResource $aResource ) 115 | { 116 | return new Coordinate( $aResource->getX(), $aResource->getY() ); 117 | } 118 | 119 | /** 120 | * Initializes the pixel strategy 121 | * 122 | * @param ImageResource $aResource 123 | */ 124 | public function init( ImageResource $aResource ) 125 | { 126 | // 127 | } 128 | } -------------------------------------------------------------------------------- /src/imagemanipulation/thumbnail/pixelstrategy/PercentagePixelStrategy.php: -------------------------------------------------------------------------------- 1 | percentage = Args::int($percentage, 'percentage')->required()->min(0)->value(); 28 | } 29 | 30 | /** 31 | * @see IPixelStrategy::getDestinationBegin() 32 | * 33 | * @param ImageResource $aResource 34 | * 35 | * @return imagemanipulation\Coordinate 36 | */ 37 | public function getDestinationBegin( ImageResource $aResource ) 38 | { 39 | return new Coordinate( 0, 0 ); 40 | } 41 | 42 | /** 43 | * @see IPixelStrategy::getDestinationEnd() 44 | * 45 | * @param ImageResource $aResource 46 | * @return imagemanipulation\Coordinate 47 | */ 48 | public function getDestinationEnd( ImageResource $aResource ) 49 | { 50 | $x = $aResource->getX() * ($this->percentage / 100); 51 | $y = $aResource->getY() * ($this->percentage / 100); 52 | 53 | return new Coordinate( (int) $x, (int) $y ); 54 | } 55 | 56 | /** 57 | * @see IPixelStrategy::getSourceBegin() 58 | * 59 | * @param ImageResource $aResource 60 | * @return imagemanipulation\Coordinate 61 | */ 62 | public function getSourceBegin( ImageResource $aResource ) 63 | { 64 | return new Coordinate( 0, 0 ); 65 | } 66 | 67 | /** 68 | * @see IPixelStrategy::getSourceEnd() 69 | * 70 | * @param ImageResource $aResource 71 | * @return imagemanipulation\Coordinate 72 | */ 73 | public function getSourceEnd( ImageResource $aResource ) 74 | { 75 | return new Coordinate( $aResource->getX(), $aResource->getY() ); 76 | } 77 | 78 | /** 79 | * Initializes the pixel strategy 80 | * 81 | * @param ImageResource $aResource 82 | */ 83 | public function init( ImageResource $aResource ) 84 | { 85 | // 86 | } 87 | } -------------------------------------------------------------------------------- /src/imagemanipulation/watermark/WatermarkBuilder.php: -------------------------------------------------------------------------------- 1 | watermark, $this->position, $this->opacity); 23 | } 24 | 25 | public function opacity($aOpacity){ 26 | $this->opacity = $aOpacity; 27 | return $this; 28 | } 29 | 30 | public function positionBottom(){ 31 | $this->position = ImageFilterWatermark::POS_BOTTOM; 32 | return $this; 33 | } 34 | public function positionBottomLeft(){ 35 | $this->position = ImageFilterWatermark::POS_BOTTOM_LEFT; 36 | return $this; 37 | } 38 | public function positionBottomRight(){ 39 | $this->position = ImageFilterWatermark::POS_BOTTOM_RIGHT; 40 | return $this; 41 | } 42 | public function positionCenter(){ 43 | $this->position = ImageFilterWatermark::POS_CENTER; 44 | return $this; 45 | } 46 | public function positionLeft(){ 47 | $this->position = ImageFilterWatermark::POS_LEFT; 48 | return $this; 49 | } 50 | public function positionRight(){ 51 | $this->position = ImageFilterWatermark::POS_RIGHT; 52 | return $this; 53 | } 54 | public function positionTop(){ 55 | $this->position = ImageFilterWatermark::POS_TOP; 56 | return $this; 57 | } 58 | public function positionTopLeft(){ 59 | $this->position = ImageFilterWatermark::POS_TOP_LEFT; 60 | return $this; 61 | } 62 | public function positionTopRight(){ 63 | $this->position = ImageFilterWatermark::POS_TOP_RIGHT; 64 | return $this; 65 | } 66 | 67 | public function watermark(\SplFileInfo $aWatermark){ 68 | assert('$aWatermark->isFile()'); 69 | $this->watermark = $aWatermark; 70 | return $this; 71 | } 72 | /* (non-PHPdoc) 73 | * @see \imagemanipulation\filter\IImageFilter::applyFilter() 74 | */ 75 | public function applyFilter(ImageResource $aResource) { 76 | $filter = $this->build(); 77 | $filter->applyFilter($aResource); 78 | } 79 | } -------------------------------------------------------------------------------- /tests-long/ImageFilterTruecolorTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 10 | $res = $this->applyFilter(new ImageFilterTrueColor('dddddd', '999999'), $original, __METHOD__); 11 | 12 | $this->assertColorQ1($res, '999999'); 13 | $this->assertColorQ2($res, '999999'); 14 | $this->assertColorQ3($res, '999999'); 15 | $this->assertColorQ4($res, 'dddddd'); 16 | } 17 | public function testJpg(){ 18 | $original = $this->getOriginalImage(ImageType::JPG); 19 | $res = $this->applyFilter(new ImageFilterTrueColor('dddddd', '999999'), $original, __METHOD__); 20 | 21 | $this->assertColorQ1($res, '999999'); 22 | $this->assertColorQ2($res, '999999'); 23 | $this->assertColorQ3($res, '999999'); 24 | $this->assertColorQ4($res, 'dddddd'); 25 | } 26 | public function testPng(){ 27 | $original = $this->getOriginalImage(ImageType::PNG); 28 | $res = $this->applyFilter(new ImageFilterTrueColor('dddddd', '999999'), $original, __METHOD__); 29 | 30 | $this->assertColorQ1($res, '999999'); 31 | $this->assertColorQ2($res, '999999'); 32 | $this->assertColorQ3($res, '999999'); 33 | $this->assertColorQ4($res, 'dddddd'); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /tests-long/imagemanipulation/filter/ImageFilterDuotoneTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 12 | $res = $this->applyFilter(new ImageFilterDuotone(255,0,0), $original, __METHOD__); 13 | 14 | $this->assertColorQ1($res, 'ff0000'); 15 | $this->assertColorQ2($res, 'ffff00'); 16 | $this->assertColorQ3($res, 'ff00ff'); 17 | $this->assertColorQ4($res, 'ffffff'); 18 | } 19 | public function testJpgRed(){ 20 | $original = $this->getOriginalImage(ImageType::JPG); 21 | $res = $this->applyFilter(new ImageFilterDuotone(255,0,0), $original, __METHOD__); 22 | 23 | $this->assertColorQ1($res, 'ff0000'); 24 | $this->assertColorQ2($res, 'ffff01'); 25 | $this->assertColorQ3($res, 'ff00fe'); 26 | $this->assertColorQ4($res, 'ffffff'); 27 | } 28 | public function testPngRed(){ 29 | $original = $this->getOriginalImage(ImageType::PNG); 30 | $res = $this->applyFilter(new ImageFilterDuotone(255,0,0), $original, __METHOD__); 31 | 32 | $this->assertColorQ1($res, 'ff0000'); 33 | $this->assertColorQ2($res, 'ffff00'); 34 | $this->assertColorQ3($res, 'ff00ff'); 35 | $this->assertColorQ4($res, 'ffffff'); 36 | } 37 | 38 | public function testGifRedImageBuilder(){ 39 | $original = $this->getOriginalImage(ImageType::GIF); 40 | $res = ImageBuilder::create($original)->duotone(255,0,0)->toResource(); 41 | 42 | $this->assertColorQ1($res, 'ff0000'); 43 | $this->assertColorQ2($res, 'ffff00'); 44 | $this->assertColorQ3($res, 'ff00ff'); 45 | $this->assertColorQ4($res, 'ffffff'); 46 | } 47 | } -------------------------------------------------------------------------------- /tests-long/imagemanipulation/filter/ImageFilterHueRotateTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 11 | $res = $this->applyFilter(new ImageFilterHueRotate(), $original, __METHOD__); 12 | 13 | $this->assertColorQ1($res, 'ffff00'); 14 | $this->assertColorQ2($res, '0000ff'); 15 | $this->assertColorQ3($res, 'ff0000'); 16 | $this->assertColorQ4($res, 'ffffff'); 17 | } 18 | public function testJpg(){ 19 | $original = $this->getOriginalImage(ImageType::JPG); 20 | $res = $this->applyFilter(new ImageFilterHueRotate(), $original, __METHOD__); 21 | 22 | $this->assertColorQ1($res, 'ffff00'); 23 | $this->assertColorQ2($res, '0000ff'); 24 | $this->assertColorQ3($res, 'ff0000'); 25 | $this->assertColorQ4($res, 'ffffff'); 26 | } 27 | public function testPng(){ 28 | $original = $this->getOriginalImage(ImageType::PNG); 29 | $res = $this->applyFilter(new ImageFilterHueRotate(), $original, __METHOD__); 30 | 31 | $this->assertColorQ1($res, 'ffff00'); 32 | $this->assertColorQ2($res, '0000ff'); 33 | $this->assertColorQ3($res, 'ff0000'); 34 | $this->assertColorQ4($res, 'ffffff'); 35 | } 36 | } -------------------------------------------------------------------------------- /tests-long/imagemanipulation/filter/ImageFilterSobelEdgeDetectTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 14 | $res = $this->applyFilter(new ImageFilterSobelEdgeDetect(), $original, __METHOD__); 15 | 16 | $this->assertColorQ1($res, 'ffffff'); 17 | $this->assertColorQ2($res, '000000'); 18 | $this->assertColorQ3($res, 'ffffff'); 19 | $this->assertColorQ4($res, 'ffffff'); 20 | } 21 | public function testJpg(){ 22 | $original = $this->getOriginalImage(ImageType::JPG); 23 | $res = $this->applyFilter(new ImageFilterSobelEdgeDetect(), $original, __METHOD__); 24 | 25 | $this->assertColorQ1($res, 'ffffff'); 26 | $this->assertColorQ2($res, '000000'); 27 | $this->assertColorQ3($res, 'ffffff'); 28 | $this->assertColorQ4($res, 'ffffff'); 29 | } 30 | public function testPng(){ 31 | $original = $this->getOriginalImage(ImageType::PNG); 32 | $res = $this->applyFilter(new ImageFilterSobelEdgeDetect(), $original, __METHOD__); 33 | 34 | $this->assertColorQ1($res, 'ffffff'); 35 | $this->assertColorQ2($res, '000000'); 36 | $this->assertColorQ3($res, 'ffffff'); 37 | $this->assertColorQ4($res, 'ffffff'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | /cache/ 2 | -------------------------------------------------------------------------------- /tests/PHPUnitBootstrap.php: -------------------------------------------------------------------------------- 1 | max(21); 8 | 9 | $this->assertTrue($result instanceof ArgumentChecker); 10 | } 11 | public function testIntMaxEquals(){ 12 | $result = Args::int(20)->max(20); 13 | $this->assertTrue($result instanceof ArgumentChecker); 14 | } 15 | public function testIntMaxAbove(){ 16 | try{ 17 | Args::int(20)->max(19); 18 | $this->fail("Exception expected"); 19 | }catch(\InvalidArgumentException $ex){ 20 | $this->assertNotNull($ex->getMessage()); 21 | } 22 | } 23 | 24 | public function testIntRequiredOk(){ 25 | $result = Args::int(20)->required(); 26 | $this->assertTrue($result instanceof ArgumentChecker); 27 | } 28 | public function Int(){ 29 | $result = Args::int(0)->required(); 30 | $this->assertTrue($result instanceof ArgumentChecker); 31 | } 32 | public function testIntRequiredFail(){ 33 | try{ 34 | Args::int(null)->required(); 35 | $this->fail("Exception expected"); 36 | }catch(\InvalidArgumentException $ex){ 37 | $this->assertNotNull($ex->getMessage()); 38 | } 39 | } 40 | public function test__ConstructNull(){ 41 | $result = Args::int(null); 42 | $this->assertTrue($result instanceof ArgumentChecker); 43 | } 44 | 45 | public function testIntMinBelow(){ 46 | try{ 47 | Args::int(20)->min(21); 48 | $this->fail("Exception expected"); 49 | }catch(\InvalidArgumentException $ex){ 50 | $this->assertNotNull($ex->getMessage()); 51 | } 52 | } 53 | public function testIntMinEquals(){ 54 | $result = Args::int(20)->min(20); 55 | $this->assertTrue($result instanceof ArgumentChecker); 56 | } 57 | public function testIntMinAbove(){ 58 | $result = Args::int(20)->min(19); 59 | $this->assertTrue($result instanceof ArgumentChecker); 60 | } 61 | } -------------------------------------------------------------------------------- /tests/imagemanipulation/ImageResourceTest.php: -------------------------------------------------------------------------------- 1 | res = new ImageResource( imagecreatefrompng( __DIR__ . '/../test/sample.png' ) ); 27 | 28 | } 29 | 30 | /** 31 | * Cleans up the environment after running a test. 32 | */ 33 | protected function tearDown() 34 | { 35 | $this->res = null; 36 | 37 | parent::tearDown(); 38 | } 39 | 40 | /** 41 | * Tests ImageResource->cloneResource() 42 | */ 43 | public function testCloneResource() 44 | { 45 | $clone = $this->res->cloneResource(); 46 | $this->assertNotEquals( $this->res, $clone, 'Checking objects not the same' ); 47 | 48 | $this->assertEquals( $this->res->getWidth(), $clone->getWidth(), 'Checking width' ); 49 | $this->assertEquals( $this->res->getHeight(), $clone->getHeight(), 'Checking height' ); 50 | 51 | $this->assertTrue( is_resource( $clone->getResource() ) ); 52 | $this->assertNotEquals( $this->res->getResource(), $clone->getResource() ); 53 | 54 | } 55 | 56 | /** 57 | * Tests ImageResource->getResource() 58 | */ 59 | public function testGetResource() 60 | { 61 | $this->assertTrue(is_resource($this->res->getResource())); 62 | } 63 | 64 | /** 65 | * Tests ImageResource->getResource() 66 | */ 67 | public function testDestroy() 68 | { 69 | $this->assertTrue(is_resource($this->res->getResource())); 70 | $this->res->destroy(); 71 | 72 | $this->assertNull($this->res->getResource()); 73 | } 74 | 75 | public function testGetSize() { 76 | $size = $this->res->getSize(); 77 | 78 | $this->assertEquals(1386, $size); 79 | } 80 | 81 | /** 82 | * Tests ImageResource->getX() 83 | */ 84 | public function testGetWidth() 85 | { 86 | $this->assertEquals( $this->res->getWidth(), 600, 'Checking width' ); 87 | } 88 | 89 | /** 90 | * Tests ImageResource->getY() 91 | */ 92 | public function testGetHeight() 93 | { 94 | $this->assertEquals( $this->res->getHeight(), 600, 'Checking height' ); 95 | } 96 | 97 | /** 98 | * Tests ImageResource->setResource() 99 | */ 100 | public function testSetResource() 101 | { 102 | $clone = $this->res->cloneResource(); 103 | $originalRes = $this->res->getResource(); 104 | $this->res->setResource( $clone->getResource() ); 105 | 106 | $this->assertNotEquals( $originalRes, $this->res->getResource() ); 107 | } 108 | 109 | /** 110 | * Tests ImageResource->setResource() 111 | */ 112 | public function testSetResourceFail() 113 | { 114 | try{ 115 | $this->res->setResource(false); 116 | $this->fail('Expected an exception'); 117 | } 118 | catch (ImageResourceException $ex){ 119 | $this->assertNotNull($ex->getMessage()); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /tests/imagemanipulation/PreconditionsTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(function_exists('gd_info'), "Check that function gd_info exists"); 13 | } 14 | 15 | public function testGDVersion(){ 16 | $info = gd_info(); 17 | $string = $info['GD Version']; // bundled (2.1.0 compatible) 18 | 19 | $match = preg_match("/.*([0-9]+\.[0-9]+\.[0-9]+).*/", $string, $matches); 20 | $this->assertNotFalse($match, "version REGEX not OK for versionstring: " . $string); 21 | 22 | $version = explode('.', $matches[1]); 23 | 24 | $this->assertGreaterThanOrEqual(2, (int) $version[0]); 25 | } 26 | 27 | public function testPngSupport(){ 28 | 29 | $info = gd_info(); 30 | 31 | $this->assertTrue($info['PNG Support'], "Check PNG Support"); 32 | } 33 | 34 | public function testJpgSupport(){ 35 | 36 | $info = gd_info(); 37 | 38 | $this->assertTrue($info['JPEG Support'], "Check Jpeg Support"); 39 | } 40 | 41 | public function testGifSupport(){ 42 | 43 | $info = gd_info(); 44 | 45 | $this->assertTrue($info['GIF Read Support'], "Check GIF Read Support"); 46 | $this->assertTrue($info['GIF Create Support'], "Check GIF Create Support"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/imagemanipulation/color/ColorFactoryTest.php: -------------------------------------------------------------------------------- 1 | assertColor(ColorFactory::black(), "000000"); 14 | } 15 | 16 | public function testBlue(){ 17 | $this->assertColor(ColorFactory::blue(), "0000ff"); 18 | } 19 | 20 | public function testGreen(){ 21 | $this->assertColor(ColorFactory::green(), "00ff00"); 22 | } 23 | 24 | public function testRed(){ 25 | $this->assertColor(ColorFactory::red(), "ff0000"); 26 | } 27 | 28 | public function testWhite(){ 29 | $this->assertColor(ColorFactory::white(), "ffffff"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/imagemanipulation/color/ColorTest.php: -------------------------------------------------------------------------------- 1 | __construct() 30 | */ 31 | public function test__constructHexShort() 32 | { 33 | $this->checkColorDDD( new Color('ddd', 127) ); 34 | } 35 | 36 | /** 37 | * Tests Color->__construct() 38 | */ 39 | public function test__constructHexShortHash() 40 | { 41 | $this->checkColorDDD( new Color('#ddd', 127) ); 42 | } 43 | 44 | /** 45 | * Tests Color->__construct() 46 | */ 47 | public function test__constructHexLongHash() 48 | { 49 | $this->checkColorDDD( new Color('#dddddd', 127) ); 50 | } 51 | /** 52 | * Tests Color->__construct() 53 | */ 54 | public function test__constructHexLong() 55 | { 56 | $this->checkColorDDD( new Color('dddddd', 127) ); 57 | } 58 | /** 59 | * Tests Color->__construct() 60 | */ 61 | public function test__constructRGB() 62 | { 63 | $this->checkColorDDD( new Color('rgb(221,221,221)', 127) ); 64 | } 65 | 66 | /** 67 | * Tests Color->__construct() 68 | */ 69 | public function test__constructRGBA() 70 | { 71 | $this->checkColorDDD( new Color('rgb(221,221,221,127)', 128) ); 72 | } 73 | 74 | /** 75 | * Tests Color->__construct() 76 | */ 77 | public function test__constructIndex() 78 | { 79 | $this->checkColorDDD( new Color(2145246685) ); 80 | } 81 | 82 | /** 83 | * Tests Color->__construct() 84 | */ 85 | public function test__constructArray() 86 | { 87 | $this->checkColorDDD( new Color(array(221, 221, 221, 127)) ); 88 | } 89 | 90 | /** 91 | * Check 92 | */ 93 | public function testCreateColorIndexNoAlpah(){ 94 | 95 | $this->assertEquals("16777215", Color::createColorIndex(255, 255, 255)); 96 | } 97 | 98 | private function checkColorDDD(Color $aColor){ 99 | $this->assertEquals(221, $aColor->getRed(), 'Checking red'); 100 | $this->assertEquals(221, $aColor->getGreen(), 'Checking green'); 101 | $this->assertEquals(221, $aColor->getBlue(), 'Checking blue'); 102 | $this->assertEquals(127, $aColor->getAlpha(), 'Checking alpha'); 103 | $this->assertEquals('dddddd', $aColor->getHexColor(), 'Checking hex color code'); 104 | $this->assertEquals(2145246685, $aColor->getColorIndex(), 'Checking color index'); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /tests/imagemanipulation/color/ColorUtilTest.php: -------------------------------------------------------------------------------- 1 | getImageRes($this->getOriginalImage(ImageType::JPG), __METHOD__); 17 | $color = ColorUtil::average($res); 18 | 19 | $this->assertEquals("070707", $color->getHexColor(), "Colors are not the same. Average color is " . $color->getHexColor()); 20 | } 21 | 22 | public function testGetColorAt(){ 23 | $res = $this->getImageRes($this->getOriginalImage(ImageType::JPG), __METHOD__); 24 | 25 | $color = ColorUtil::getColorAt($res, Coordinate::create(20,20)); 26 | $this->assertColor($color, 'fe0000'); 27 | } 28 | 29 | public function testRgb2hsl(){ 30 | $this->assertEquals( array(0, 0, 100), ColorUtil::rgb2hsl(255, 255,255), "Error converting rgb white into hsl"); 31 | $this->assertEquals( array(0, 0, 0), ColorUtil::rgb2hsl(0, 0, 0), "Error converting rgb black into hsl" ); 32 | $this->assertEquals( array(120, 100, 50), ColorUtil::rgb2hsl(0, 255, 0), "Error converting rgb green into hsl" ); 33 | $this->assertEquals( array(240, 100, 50), ColorUtil::rgb2hsl(0, 0, 255), "Error converting rgb blue into hsl" ); 34 | } 35 | 36 | public function testhsl2Rgb(){ 37 | $this->assertEquals( array(255, 255,255), ColorUtil::hsl2rgb(0, 0, 100), "Error converting hsl into rgb white "); 38 | $this->assertEquals( array(0, 0, 0), ColorUtil::hsl2rgb(0, 0, 0), "Error converting hsl into rgb black into hsl" ); 39 | $this->assertEquals( array(0, 255, 0), ColorUtil::hsl2rgb(120, 100, 50), "Error converting hsl into rgb green" ); 40 | $this->assertEquals( array(0, 0, 255), ColorUtil::hsl2rgb(240, 100, 50), "Error converting hsl into rgb blue" ); 41 | } 42 | 43 | public function testHex2hsl(){ 44 | $this->assertEquals( array(0, 0, 100), ColorUtil::hex2hsl('ffffff'), "Error converting hex white into hsl"); 45 | $this->assertEquals( array(0, 0, 100), ColorUtil::hex2hsl('#ffffff'), "Error converting hex #white into hsl"); 46 | $this->assertEquals( array(0, 0, 0), ColorUtil::hex2hsl('000000'), "Error converting hex black into hsl" ); 47 | $this->assertEquals( array(120, 100, 50), ColorUtil::hex2hsl('00ff00'), "Error converting hex green into hsl" ); 48 | $this->assertEquals( array(240, 100, 50), ColorUtil::hex2hsl('0000ff'), "Error converting hex blue into hsl" ); 49 | } 50 | 51 | public function testInt2rgba(){ 52 | $this->assertEquals(array(255,255,255,16), ColorUtil::int2rgba('285212671')); 53 | } 54 | 55 | public function testRgba2Int(){ 56 | $this->assertEquals('285212671', ColorUtil::rgba2int(255,255,255,16)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterBrightnessTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 12 | $res = $this->applyFilter(new ImageFilterBrightness(255), $original, __METHOD__); 13 | 14 | $this->assertColorQ1($res, self::WHITE); 15 | $this->assertColorQ2($res, self::WHITE); 16 | $this->assertColorQ3($res, self::WHITE); 17 | $this->assertColorQ4($res, self::WHITE); 18 | } 19 | 20 | public function testJpgLight(){ 21 | $original = $this->getOriginalImage(ImageType::JPG); 22 | $res = $this->applyFilter(new ImageFilterBrightness(255), $original, __METHOD__); 23 | 24 | $this->assertColorQ1($res, self::WHITE); 25 | $this->assertColorQ2($res, self::WHITE); 26 | $this->assertColorQ3($res, self::WHITE); 27 | $this->assertColorQ4($res, self::WHITE); 28 | } 29 | public function testPngLight(){ 30 | $original = $this->getOriginalImage(ImageType::PNG); 31 | $res = $this->applyFilter(new ImageFilterBrightness(255), $original, __METHOD__); 32 | 33 | $this->assertColorQ1($res, self::WHITE); 34 | $this->assertColorQ2($res, self::WHITE); 35 | $this->assertColorQ3($res, self::WHITE); 36 | $this->assertColorQ4($res, self::WHITE); 37 | } 38 | 39 | public function testGifMedium(){ 40 | $original = $this->getOriginalImage(ImageType::GIF); 41 | $res = $this->applyFilter(new ImageFilterBrightness(127), $original, __METHOD__); 42 | 43 | $this->assertColorQ1($res, 'ff7f7f'); 44 | $this->assertColorQ2($res, '7fff7f'); 45 | $this->assertColorQ3($res, '7f7fff'); 46 | $this->assertColorQ4($res, self::WHITE); 47 | } 48 | public function testJpgMedium(){ 49 | $original = $this->getOriginalImage(ImageType::JPG); 50 | $res = $this->applyFilter(new ImageFilterBrightness(127), $original, __METHOD__); 51 | 52 | $this->assertColorQ1($res, 'ff7f7f'); 53 | $this->assertColorQ2($res, '7fff80'); // just slightly different as from GIF & PNG 54 | $this->assertColorQ3($res, '7f7fff'); 55 | $this->assertColorQ4($res, self::WHITE); 56 | } 57 | public function testPngMedium(){ 58 | $original = $this->getOriginalImage(ImageType::PNG); 59 | $res = $this->applyFilter(new ImageFilterBrightness(127), $original, __METHOD__); 60 | 61 | $this->assertColorQ1($res, 'ff7f7f'); 62 | $this->assertColorQ2($res, '7fff7f'); 63 | $this->assertColorQ3($res, '7f7fff'); 64 | $this->assertColorQ4($res, self::WHITE); // 65 | } 66 | 67 | public function testGifDark(){ 68 | $original = $this->getOriginalImage(ImageType::GIF); 69 | $res = $this->applyFilter(new ImageFilterBrightness(-255), $original, __METHOD__); 70 | 71 | $this->assertColorQ1($res, self::BLACK); 72 | $this->assertColorQ2($res, self::BLACK); 73 | $this->assertColorQ3($res, self::BLACK); 74 | $this->assertColorQ4($res, self::BLACK); 75 | } 76 | public function testJpgDark(){ 77 | $original = $this->getOriginalImage(ImageType::JPG); 78 | $res = $this->applyFilter(new ImageFilterBrightness(-255), $original, __METHOD__); 79 | 80 | $this->assertColorQ1($res, self::BLACK); 81 | $this->assertColorQ2($res, self::BLACK); 82 | $this->assertColorQ3($res, self::BLACK); 83 | $this->assertColorQ4($res, self::BLACK); 84 | } 85 | public function testPngDark(){ 86 | $original = $this->getOriginalImage(ImageType::PNG); 87 | $res = $this->applyFilter(new ImageFilterBrightness(-255), $original, __METHOD__); 88 | 89 | $this->assertColorQ1($res, self::BLACK); 90 | $this->assertColorQ2($res, self::BLACK); 91 | $this->assertColorQ3($res, self::BLACK); 92 | $this->assertColorQ4($res, self::BLACK); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterColorizeTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 13 | $res = $this->applyFilter(new ImageFilterColorize( ColorFactory::red() ), $original, __METHOD__); 14 | 15 | $this->assertColorQ1($res, self::RED); // unchanged 16 | $this->assertColorQ2($res, 'ffff00'); 17 | $this->assertColorQ3($res, 'ff00ff'); 18 | $this->assertColorQ4($res, self::WHITE); 19 | } 20 | public function testJpgRed(){ 21 | $original = $this->getOriginalImage(ImageType::JPG); 22 | $res = $this->applyFilter(new ImageFilterColorize(ColorFactory::red()), $original, __METHOD__); 23 | 24 | $this->assertColorQ1($res, self::RED); // unchanged 25 | $this->assertColorQ2($res, 'ffff01'); 26 | $this->assertColorQ3($res, 'ff00fe'); 27 | $this->assertColorQ4($res, self::WHITE); 28 | } 29 | public function testPngRed(){ 30 | $original = $this->getOriginalImage(ImageType::PNG); 31 | $res = $this->applyFilter(new ImageFilterColorize(ColorFactory::red()), $original, __METHOD__); 32 | 33 | $this->assertColorQ1($res, self::RED); // unchanged 34 | $this->assertColorQ2($res, 'ffff00'); 35 | $this->assertColorQ3($res, 'ff00ff'); 36 | $this->assertColorQ4($res, self::WHITE); 37 | } 38 | 39 | public function testGifBlue(){ 40 | $original = $this->getOriginalImage(ImageType::GIF); 41 | $res = $this->applyFilter(new ImageFilterColorize( ColorFactory::blue() ), $original, __METHOD__); 42 | 43 | $this->assertColorQ1($res, 'ff00ff'); 44 | $this->assertColorQ2($res, '00ffff'); 45 | $this->assertColorQ3($res, self::BLUE); // unchanged 46 | $this->assertColorQ4($res, self::WHITE); 47 | } 48 | public function testJpgBlue(){ 49 | $original = $this->getOriginalImage(ImageType::JPG); 50 | $res = $this->applyFilter(new ImageFilterColorize(ColorFactory::blue()), $original, __METHOD__); 51 | 52 | $this->assertColorQ1($res, 'fe00ff'); 53 | $this->assertColorQ2($res, '00ffff'); 54 | $this->assertColorQ3($res, self::BLUE);// unchanged 55 | $this->assertColorQ4($res, self::WHITE); 56 | } 57 | public function testPngBlue(){ 58 | $original = $this->getOriginalImage(ImageType::PNG); 59 | $res = $this->applyFilter(new ImageFilterColorize(ColorFactory::blue()), $original, __METHOD__); 60 | 61 | $this->assertColorQ1($res, 'ff00ff'); 62 | $this->assertColorQ2($res, '00ffff'); 63 | $this->assertColorQ3($res, self::BLUE); // unchanged 64 | $this->assertColorQ4($res, self::WHITE); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterComicTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 11 | // $res = $this->applyFilter(new ImageFilterComic( 50 ), $original, __METHOD__); 12 | 13 | // $this->assertColorQ1($res, '7f0000'); 14 | // $this->assertColorQ2($res, '007f00'); 15 | // $this->assertColorQ3($res, '00007f'); 16 | // $this->assertColorQ4($res, self::WHITE); 17 | // } 18 | 19 | public function testJpg50Opacity(){ 20 | $original = $this->getOriginalImage(ImageType::JPG); 21 | $res = $this->applyFilter(new ImageFilterComic( 50 ), $original, __METHOD__); 22 | 23 | $this->assertColorQ1($res, '7f0000'); 24 | $this->assertColorQ2($res, '007f00'); 25 | $this->assertColorQ3($res, '00007f'); 26 | $this->assertColorQ4($res, self::WHITE); 27 | } 28 | 29 | // public function testPng50Opacity(){ 30 | // $original = $this->getOriginalImage(ImageType::PNG); 31 | // $res = $this->applyFilter(new ImageFilterComic( 50 ), $original, __METHOD__); 32 | 33 | // $this->assertColorQ1($res, '7f0000'); 34 | // $this->assertColorQ2($res, '007f00'); 35 | // $this->assertColorQ3($res, '00007f'); 36 | // $this->assertColorQ4($res, self::WHITE); 37 | // } 38 | } -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterConvolutionTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 12 | $res = $this->applyFilter(new ImageFilterConvolution(0,0,0,0,1,0,0,0,0), $original, __METHOD__); 13 | 14 | $this->assertColorQ1($res, 'ff0000'); 15 | $this->assertColorQ2($res, '00ff00'); 16 | $this->assertColorQ3($res, '0000ff'); 17 | $this->assertColorQ4($res, self::WHITE); 18 | } 19 | public function testJpgNoChange(){ 20 | $original = $this->getOriginalImage(ImageType::JPG); 21 | $res = $this->applyFilter(new ImageFilterConvolution(0,0,0,0,1,0,0,0,0), $original, __METHOD__); 22 | 23 | $this->assertColorQ1($res, 'fe0000'); 24 | $this->assertColorQ2($res, '00ff01'); 25 | $this->assertColorQ3($res, '0000fe'); 26 | $this->assertColorQ4($res, self::WHITE); 27 | } 28 | public function testPngNoChange(){ 29 | $original = $this->getOriginalImage(ImageType::PNG); 30 | $res = $this->applyFilter(new ImageFilterConvolution(0,0,0,0,1,0,0,0,0), $original, __METHOD__); 31 | 32 | $this->assertColorQ1($res, 'ff0000'); 33 | $this->assertColorQ2($res, '00ff00'); 34 | $this->assertColorQ3($res, '0000ff'); 35 | $this->assertColorQ4($res, self::WHITE); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterDarkenTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 12 | $res = $this->applyFilter(new ImageFilterDarken(255), $original, __METHOD__); 13 | 14 | $this->assertColorQ1($res, self::BLACK); 15 | $this->assertColorQ2($res, self::BLACK); 16 | $this->assertColorQ3($res, self::BLACK); 17 | $this->assertColorQ4($res, self::BLACK); 18 | } 19 | public function testJpgLight(){ 20 | $original = $this->getOriginalImage(ImageType::JPG); 21 | $res = $this->applyFilter(new ImageFilterDarken(255), $original, __METHOD__); 22 | 23 | $this->assertColorQ1($res, self::BLACK); 24 | $this->assertColorQ2($res, self::BLACK); 25 | $this->assertColorQ3($res, self::BLACK); 26 | $this->assertColorQ4($res, self::BLACK); 27 | } 28 | public function testPngLight(){ 29 | $original = $this->getOriginalImage(ImageType::PNG); 30 | $res = $this->applyFilter(new ImageFilterDarken(255), $original, __METHOD__); 31 | 32 | $this->assertColorQ1($res, self::BLACK); 33 | $this->assertColorQ2($res, self::BLACK); 34 | $this->assertColorQ3($res, self::BLACK); 35 | $this->assertColorQ4($res, self::BLACK); 36 | } 37 | 38 | public function testGifMedium(){ 39 | $original = $this->getOriginalImage(ImageType::GIF); 40 | $res = $this->applyFilter(new ImageFilterDarken(127), $original, __METHOD__); 41 | 42 | $this->assertColorQ1($res, '800000'); 43 | $this->assertColorQ2($res, '008000'); 44 | $this->assertColorQ3($res, '000080'); 45 | $this->assertColorQ4($res, '808080'); 46 | } 47 | public function testJpgMedium(){ 48 | $original = $this->getOriginalImage(ImageType::JPG); 49 | $res = $this->applyFilter(new ImageFilterDarken(127), $original, __METHOD__); 50 | 51 | $this->assertColorQ1($res, '7f0000'); 52 | $this->assertColorQ2($res, '008000'); // just slightly different as from GIF & PNG 53 | $this->assertColorQ3($res, '00007f'); 54 | $this->assertColorQ4($res, '808080'); 55 | } 56 | public function testPngMedium(){ 57 | $original = $this->getOriginalImage(ImageType::PNG); 58 | $res = $this->applyFilter(new ImageFilterDarken(127), $original, __METHOD__); 59 | 60 | $this->assertColorQ1($res, '800000'); 61 | $this->assertColorQ2($res, '008000'); 62 | $this->assertColorQ3($res, '000080'); 63 | $this->assertColorQ4($res, '808080'); // 64 | } 65 | 66 | public function testGifDark(){ 67 | $original = $this->getOriginalImage(ImageType::GIF); 68 | $res = $this->applyFilter(new ImageFilterDarken(-255), $original, __METHOD__); 69 | 70 | $this->assertColorQ1($res, self::WHITE); 71 | $this->assertColorQ2($res, self::WHITE); 72 | $this->assertColorQ3($res, self::WHITE); 73 | $this->assertColorQ4($res, self::WHITE); 74 | } 75 | public function testJpgDark(){ 76 | $original = $this->getOriginalImage(ImageType::JPG); 77 | $res = $this->applyFilter(new ImageFilterDarken(-255), $original, __METHOD__); 78 | 79 | $this->assertColorQ1($res, self::WHITE); 80 | $this->assertColorQ2($res, self::WHITE); 81 | $this->assertColorQ3($res, self::WHITE); 82 | $this->assertColorQ4($res, self::WHITE); 83 | } 84 | public function testPngDark(){ 85 | $original = $this->getOriginalImage(ImageType::PNG); 86 | $res = $this->applyFilter(new ImageFilterDarken(-255), $original, __METHOD__); 87 | 88 | $this->assertColorQ1($res, self::WHITE); 89 | $this->assertColorQ2($res, self::WHITE); 90 | $this->assertColorQ3($res, self::WHITE); 91 | $this->assertColorQ4($res, self::WHITE); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterDodgeTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 12 | $res = $this->applyFilter(new ImageFilterDodge(0), $original, __METHOD__); 13 | 14 | $this->assertColorQ1($res, 'ff0000'); 15 | $this->assertColorQ2($res, '00ff00'); 16 | $this->assertColorQ3($res, '0000ff'); 17 | $this->assertColorQ4($res, 'ffffff'); 18 | } 19 | public function testJpgLight(){ 20 | $original = $this->getOriginalImage(ImageType::JPG); 21 | $res = $this->applyFilter(new ImageFilterDodge(0), $original, __METHOD__); 22 | 23 | $this->assertColorQ1($res, 'fe0000'); 24 | $this->assertColorQ2($res, '00ff01'); 25 | $this->assertColorQ3($res, '0000fe'); 26 | $this->assertColorQ4($res, 'ffffff'); 27 | } 28 | public function testPngLight(){ 29 | $original = $this->getOriginalImage(ImageType::PNG); 30 | $res = $this->applyFilter(new ImageFilterDodge(0), $original, __METHOD__); 31 | 32 | $this->assertColorQ1($res, 'ff0000'); 33 | $this->assertColorQ2($res, '00ff00'); 34 | $this->assertColorQ3($res, '0000ff'); 35 | $this->assertColorQ4($res, 'ffffff'); 36 | } 37 | 38 | // TODO disabled for now, as these take too much time 39 | // public function testGifMedium(){ 40 | // $original = $this->getOriginalImage(ImageType::GIF); 41 | // $res = $this->applyFilter(new ImageFilterDodge(50), $original, __METHOD__); 42 | 43 | // $this->assertColorQ1($res, '7f0000'); 44 | // $this->assertColorQ2($res, '007f00'); 45 | // $this->assertColorQ3($res, '00007f'); 46 | // $this->assertColorQ4($res, '7f7f7f'); 47 | // } 48 | // public function testJpgMedium(){ 49 | // $original = $this->getOriginalImage(ImageType::JPG); 50 | // $res = $this->applyFilter(new ImageFilterDodge(50), $original, __METHOD__); 51 | 52 | // $this->assertColorQ1($res, '7f0000'); 53 | // $this->assertColorQ2($res, '007f00'); // just slightly different as from GIF & PNG 54 | // $this->assertColorQ3($res, '00007f'); 55 | // $this->assertColorQ4($res, '7f7f7f'); 56 | // } 57 | // public function testPngMedium(){ 58 | // $original = $this->getOriginalImage(ImageType::PNG); 59 | // $res = $this->applyFilter(new ImageFilterDodge(50), $original, __METHOD__); 60 | 61 | // $this->assertColorQ1($res, '7f0000'); 62 | // $this->assertColorQ2($res, '007f00'); 63 | // $this->assertColorQ3($res, '00007f'); 64 | // $this->assertColorQ4($res, '7f7f7f'); // 65 | // } 66 | 67 | // public function testGifDark(){ 68 | // $original = $this->getOriginalImage(ImageType::GIF); 69 | // $res = $this->applyFilter(new ImageFilterDodge(99), $original, __METHOD__); 70 | 71 | // $this->assertColorQ1($res, 'fc0000'); 72 | // $this->assertColorQ2($res, '00fc00'); 73 | // $this->assertColorQ3($res, '0000fc'); 74 | // $this->assertColorQ4($res, 'fcfcfc'); 75 | // } 76 | // public function testJpgDark(){ 77 | // $original = $this->getOriginalImage(ImageType::JPG); 78 | // $res = $this->applyFilter(new ImageFilterDodge(99), $original, __METHOD__); 79 | 80 | // $this->assertColorQ1($res, 'fb0000'); 81 | // $this->assertColorQ2($res, '00fc00'); 82 | // $this->assertColorQ3($res, '0000fb'); 83 | // $this->assertColorQ4($res, 'fcfcfc'); 84 | // } 85 | // public function testPngDark(){ 86 | // $original = $this->getOriginalImage(ImageType::PNG); 87 | // $res = $this->applyFilter(new ImageFilterDodge(99), $original, __METHOD__); 88 | 89 | // $this->assertColorQ1($res, 'fc0000'); 90 | // $this->assertColorQ2($res, '00fc00'); 91 | // $this->assertColorQ3($res, '0000fc'); 92 | // $this->assertColorQ4($res, 'fcfcfc'); 93 | // } 94 | } 95 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterEdgeDetectTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 17 | $res = $this->applyFilter(new ImageFilterEdgeDetect(), $original, __METHOD__); 18 | 19 | $this->assertColorQ1($res, '7f7f7f'); 20 | $this->assertColorQ2($res, '7f7f7f'); 21 | $this->assertColorQ3($res, '7f7f7f'); 22 | $this->assertColorQ4($res, '7f7f7f'); 23 | } 24 | public function testJpg(){ 25 | $original = $this->getOriginalImage(ImageType::JPG); 26 | $res = $this->applyFilter(new ImageFilterEdgeDetect(), $original, __METHOD__); 27 | 28 | $this->assertColorQ1($res, '7f7f7f'); 29 | $this->assertColorQ2($res, '7f7f7f'); 30 | $this->assertColorQ3($res, '7f7f7f'); 31 | $this->assertColorQ4($res, '7f7f7f'); 32 | } 33 | public function testPng(){ 34 | $original = $this->getOriginalImage(ImageType::PNG); 35 | $res = $this->applyFilter(new ImageFilterEdgeDetect(), $original, __METHOD__); 36 | 37 | $this->assertColorQ1($res, '7f7f7f'); 38 | $this->assertColorQ2($res, '7f7f7f'); 39 | $this->assertColorQ3($res, '7f7f7f'); 40 | $this->assertColorQ4($res, '7f7f7f'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterEmbossColoringTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 15 | $res = $this->applyFilter(new ImageFilterEmbossColoring(), $original, __METHOD__); 16 | 17 | $this->assertColorQ1($res, self::RED); 18 | $this->assertColorQ2($res, self::GREEN); 19 | $this->assertColorQ3($res, self::BLUE); 20 | $this->assertColorQ4($res, self::WHITE); 21 | } 22 | public function testJpg(){ 23 | $original = $this->getOriginalImage(ImageType::JPG); 24 | $res = $this->applyFilter(new ImageFilterEmbossColoring(), $original, __METHOD__); 25 | 26 | $this->assertColorQ1($res, 'fe0000'); 27 | $this->assertColorQ2($res, '00ff01'); 28 | $this->assertColorQ3($res, '0000fe'); 29 | $this->assertColorQ4($res, self::WHITE); 30 | } 31 | public function testPng(){ 32 | $original = $this->getOriginalImage(ImageType::PNG); 33 | $res = $this->applyFilter(new ImageFilterEmbossColoring(), $original, __METHOD__); 34 | 35 | $this->assertColorQ1($res, self::RED); 36 | $this->assertColorQ2($res, self::GREEN); 37 | $this->assertColorQ3($res, self::BLUE); 38 | $this->assertColorQ4($res, self::WHITE); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterEmbossTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 16 | $res = $this->applyFilter(new ImageFilterEmboss(), $original, __METHOD__); 17 | 18 | $this->assertColorQ1($res, '7f7f7f'); 19 | $this->assertColorQ2($res, '7f7f7f'); 20 | $this->assertColorQ3($res, '7f7f7f'); 21 | $this->assertColorQ4($res, '7f7f7f'); 22 | } 23 | public function testJpg(){ 24 | $original = $this->getOriginalImage(ImageType::JPG); 25 | $res = $this->applyFilter(new ImageFilterEmboss(), $original, __METHOD__); 26 | 27 | $this->assertColorQ1($res, '7f7f7f'); 28 | $this->assertColorQ2($res, '7f7f7f'); 29 | $this->assertColorQ3($res, '7f7f7f'); 30 | $this->assertColorQ4($res, '7f7f7f'); 31 | } 32 | public function testPng(){ 33 | $original = $this->getOriginalImage(ImageType::PNG); 34 | $res = $this->applyFilter(new ImageFilterEmboss(), $original, __METHOD__); 35 | 36 | $this->assertColorQ1($res, '7f7f7f'); 37 | $this->assertColorQ2($res, '7f7f7f'); 38 | $this->assertColorQ3($res, '7f7f7f'); 39 | $this->assertColorQ4($res, '7f7f7f'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterFindEdgesTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 16 | $res = $this->applyFilter(new ImageFilterFindEdges(), $original, __METHOD__); 17 | 18 | $this->assertColorQ1($res, 'ff0000'); 19 | $this->assertColorQ2($res, '00ff00'); 20 | $this->assertColorQ3($res, '0000ff'); 21 | $this->assertColorQ4($res, 'ffffff'); 22 | } 23 | public function testJpg(){ 24 | $original = $this->getOriginalImage(ImageType::JPG); 25 | $res = $this->applyFilter(new ImageFilterFindEdges(), $original, __METHOD__); 26 | 27 | $this->assertColorQ1($res, 'fe0000'); 28 | $this->assertColorQ2($res, '00ff01'); 29 | $this->assertColorQ3($res, '0000fe'); 30 | $this->assertColorQ4($res, 'ffffff'); 31 | } 32 | public function testPng(){ 33 | $original = $this->getOriginalImage(ImageType::PNG); 34 | $res = $this->applyFilter(new ImageFilterFindEdges(), $original, __METHOD__); 35 | 36 | $this->assertColorQ1($res, 'ff0000'); 37 | $this->assertColorQ2($res, '00ff00'); 38 | $this->assertColorQ3($res, '0000ff'); 39 | $this->assertColorQ4($res, 'ffffff'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterFlipTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 16 | $res = $this->applyFilter(new ImageFilterFlip(true, false), $original, __METHOD__); 17 | 18 | $this->assertColorQ1($res, '00ff00'); 19 | $this->assertColorQ2($res, 'ff0000'); 20 | $this->assertColorQ3($res, 'ffffff'); 21 | $this->assertColorQ4($res, '0000ff'); 22 | } 23 | public function testJpgHorizontal(){ 24 | $original = $this->getOriginalImage(ImageType::JPG); 25 | $res = $this->applyFilter(new ImageFilterFlip(true, false), $original, __METHOD__); 26 | 27 | $this->assertColorQ1($res, '00ff01'); 28 | $this->assertColorQ2($res, 'fe0000'); 29 | $this->assertColorQ3($res, 'ffffff'); 30 | $this->assertColorQ4($res, '0000fe'); 31 | } 32 | public function testPngHorizontal(){ 33 | $original = $this->getOriginalImage(ImageType::PNG); 34 | $res = $this->applyFilter(new ImageFilterFlip(true, false), $original, __METHOD__); 35 | 36 | $this->assertColorQ1($res, '00ff00'); 37 | $this->assertColorQ2($res, 'ff0000'); 38 | $this->assertColorQ3($res, 'ffffff'); 39 | $this->assertColorQ4($res, '0000ff'); 40 | } 41 | 42 | public function testGifVertical(){ 43 | $original = $this->getOriginalImage(ImageType::GIF); 44 | $res = $this->applyFilter(new ImageFilterFlip(false,true), $original, __METHOD__); 45 | 46 | $this->assertColorQ1($res, '0000ff'); 47 | $this->assertColorQ2($res, 'ffffff'); 48 | $this->assertColorQ3($res, 'ff0000'); 49 | $this->assertColorQ4($res, '00ff00'); 50 | } 51 | public function testJpgVertical(){ 52 | $original = $this->getOriginalImage(ImageType::JPG); 53 | $res = $this->applyFilter(new ImageFilterFlip(false,true), $original, __METHOD__); 54 | 55 | $this->assertColorQ1($res, '0000fe'); 56 | $this->assertColorQ2($res, 'ffffff'); 57 | $this->assertColorQ3($res, 'fe0000'); 58 | $this->assertColorQ4($res, '00ff01'); 59 | } 60 | public function testPngVertical(){ 61 | $original = $this->getOriginalImage(ImageType::PNG); 62 | $res = $this->applyFilter(new ImageFilterFlip(false,true), $original, __METHOD__); 63 | 64 | $this->assertColorQ1($res, '0000ff'); 65 | $this->assertColorQ2($res, 'ffffff'); 66 | $this->assertColorQ3($res, 'ff0000'); 67 | $this->assertColorQ4($res, '00ff00'); 68 | } 69 | 70 | public function testGifBoth(){ 71 | $original = $this->getOriginalImage(ImageType::GIF); 72 | $res = $this->applyFilter(new ImageFilterFlip(true, true), $original, __METHOD__); 73 | 74 | $this->assertColorQ1($res, 'ffffff'); 75 | $this->assertColorQ2($res, '0000ff'); 76 | $this->assertColorQ3($res, '00ff00'); 77 | $this->assertColorQ4($res, 'ff0000'); 78 | } 79 | public function testJpgBoth(){ 80 | $original = $this->getOriginalImage(ImageType::JPG); 81 | $res = $this->applyFilter(new ImageFilterFlip(true, true), $original, __METHOD__); 82 | 83 | $this->assertColorQ1($res, 'ffffff'); 84 | $this->assertColorQ2($res, '0000fe'); 85 | $this->assertColorQ3($res, '00ff01'); 86 | $this->assertColorQ4($res, 'fe0000'); 87 | } 88 | public function testPngBoth(){ 89 | $original = $this->getOriginalImage(ImageType::PNG); 90 | $res = $this->applyFilter(new ImageFilterFlip(true, true), $original, __METHOD__); 91 | 92 | $this->assertColorQ1($res, 'ffffff'); 93 | $this->assertColorQ2($res, '0000ff'); 94 | $this->assertColorQ3($res, '00ff00'); 95 | $this->assertColorQ4($res, 'ff0000'); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterGammaCorrectionTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 11 | $res = $this->applyFilter(new ImageFilterGammaCorrection(), $original, __METHOD__); 12 | 13 | $this->assertColorQ1($res, 'ff0000'); 14 | $this->assertColorQ2($res, '00ff00'); 15 | $this->assertColorQ3($res, '0000ff'); 16 | $this->assertColorQ4($res, 'ffffff'); 17 | } 18 | public function testJpg(){ 19 | $original = $this->getOriginalImage(ImageType::JPG); 20 | $res = $this->applyFilter(new ImageFilterGammaCorrection(), $original, __METHOD__); 21 | 22 | $this->assertColorQ1($res, 'fe0000'); 23 | $this->assertColorQ2($res, '00ff07'); 24 | $this->assertColorQ3($res, '0000fe'); 25 | $this->assertColorQ4($res, 'ffffff'); 26 | } 27 | public function testPng(){ 28 | $original = $this->getOriginalImage(ImageType::PNG); 29 | $res = $this->applyFilter(new ImageFilterGammaCorrection(), $original, __METHOD__); 30 | 31 | $this->assertColorQ1($res, 'ff0000'); 32 | $this->assertColorQ2($res, '00ff00'); 33 | $this->assertColorQ3($res, '0000ff'); 34 | $this->assertColorQ4($res, 'ffffff'); 35 | } 36 | } -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterGaussianBlurTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage( ImageType::GIF ); 13 | $res = $this->applyFilter( new ImageFilterGaussianBlur(), $original, __METHOD__ ); 14 | 15 | $this->assertColorQ1( $res, 'ff0000' ); 16 | $this->assertColorQ2( $res, '00ff00' ); 17 | $this->assertColorQ3( $res, '0000ff' ); 18 | $this->assertColorQ4( $res, 'ffffff' ); 19 | } 20 | 21 | public function testJpg() 22 | { 23 | $original = $this->getOriginalImage( ImageType::JPG ); 24 | $res = $this->applyFilter( new ImageFilterGaussianBlur(), $original, __METHOD__ ); 25 | 26 | $this->assertColorQ1( $res, 'fe0000' ); 27 | $this->assertColorQ2( $res, '00ff01' ); 28 | $this->assertColorQ3( $res, '0000fe' ); 29 | $this->assertColorQ4( $res, 'ffffff' ); 30 | } 31 | public function testPng() 32 | { 33 | $original = $this->getOriginalImage( ImageType::PNG ); 34 | $res = $this->applyFilter( new ImageFilterGaussianBlur(), $original, __METHOD__ ); 35 | 36 | $this->assertColorQ1( $res, 'ff0000' ); 37 | $this->assertColorQ2( $res, '00ff00' ); 38 | $this->assertColorQ3( $res, '0000ff' ); 39 | $this->assertColorQ4( $res, 'ffffff' ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterGrayscaleTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage( ImageType::GIF ); 13 | $res = $this->applyFilter( new ImageFilterGrayScale(), $original, __METHOD__ ); 14 | 15 | $this->assertColorQ1( $res, '4c4c4c' ); 16 | $this->assertColorQ2( $res, '959595' ); 17 | $this->assertColorQ3( $res, '1d1d1d' ); 18 | $this->assertColorQ4( $res, 'ffffff' ); 19 | } 20 | public function testJpg() 21 | { 22 | $original = $this->getOriginalImage( ImageType::JPG ); 23 | $res = $this->applyFilter( new ImageFilterGrayScale(), $original, __METHOD__ ); 24 | 25 | $this->assertColorQ1( $res, '4b4b4b' ); 26 | $this->assertColorQ2( $res, '959595' ); 27 | $this->assertColorQ3( $res, '1c1c1c' ); 28 | $this->assertColorQ4( $res, 'ffffff' ); 29 | } 30 | public function testPng() 31 | { 32 | $original = $this->getOriginalImage( ImageType::PNG ); 33 | $res = $this->applyFilter( new ImageFilterGrayScale(), $original, __METHOD__ ); 34 | 35 | $this->assertColorQ1( $res, '4c4c4c' ); 36 | $this->assertColorQ2( $res, '959595' ); 37 | $this->assertColorQ3( $res, '1d1d1d' ); 38 | $this->assertColorQ4( $res, 'ffffff' ); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterMeanRemoveTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage( ImageType::GIF ); 13 | $res = $this->applyFilter( new ImageFilterMeanRemove(), $original, __METHOD__ ); 14 | 15 | $this->assertColorQ1( $res, 'ff0000' ); 16 | $this->assertColorQ2( $res, '00ff00' ); 17 | $this->assertColorQ3( $res, '0000ff' ); 18 | $this->assertColorQ4( $res, 'ffffff' ); 19 | } 20 | public function testJpg() 21 | { 22 | $original = $this->getOriginalImage( ImageType::JPG ); 23 | $res = $this->applyFilter( new ImageFilterMeanRemove(), $original, __METHOD__ ); 24 | 25 | $this->assertColorQ1( $res, 'fe0000' ); // slightly other color due to mean remove on jpg 26 | $this->assertColorQ2( $res, '00ff01' ); 27 | $this->assertColorQ3( $res, '0000fe' ); 28 | $this->assertColorQ4( $res, 'ffffff' ); 29 | } 30 | public function testPng() 31 | { 32 | $original = $this->getOriginalImage( ImageType::PNG ); 33 | $res = $this->applyFilter( new ImageFilterMeanRemove(), $original, __METHOD__ ); 34 | 35 | $this->assertColorQ1( $res, 'ff0000' ); 36 | $this->assertColorQ2( $res, '00ff00' ); 37 | $this->assertColorQ3( $res, '0000ff' ); 38 | $this->assertColorQ4( $res, 'ffffff' ); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterMotionBlurTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage( ImageType::GIF ); 12 | $res = $this->applyFilter( new ImageFilterMotionBlur(), $original, __METHOD__ ); 13 | 14 | $this->assertColorQ1( $res, 'ff0000' ); 15 | $this->assertColorQ2( $res, '00ff00' ); 16 | $this->assertColorQ3( $res, '0000ff' ); 17 | $this->assertColorQ4( $res, 'ffffff' ); 18 | } 19 | public function testJpg() 20 | { 21 | $original = $this->getOriginalImage( ImageType::JPG ); 22 | $res = $this->applyFilter( new ImageFilterMotionBlur(), $original, __METHOD__ ); 23 | 24 | $this->assertColorQ1( $res, 'fe0000' ); 25 | $this->assertColorQ2( $res, '00ff01' ); 26 | $this->assertColorQ3( $res, '0000fe' ); 27 | $this->assertColorQ4( $res, 'ffffff' ); 28 | } 29 | public function testPng() 30 | { 31 | $original = $this->getOriginalImage( ImageType::PNG ); 32 | $res = $this->applyFilter( new ImageFilterMotionBlur(), $original, __METHOD__ ); 33 | 34 | $this->assertColorQ1( $res, 'ff0000' ); 35 | $this->assertColorQ2( $res, '00ff00' ); 36 | $this->assertColorQ3( $res, '0000ff' ); 37 | $this->assertColorQ4( $res, 'ffffff' ); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterNegativeTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 12 | $res = $this->applyFilter(new ImageFilterNegative(), $original, __METHOD__); 13 | 14 | $this->assertColorQ1($res, '00ffff'); 15 | $this->assertColorQ2($res, 'ff00ff'); 16 | $this->assertColorQ3($res, 'ffff00'); 17 | $this->assertColorQ4($res, self::BLACK); 18 | } 19 | public function testJpg(){ 20 | $original = $this->getOriginalImage(ImageType::JPG); 21 | $res = $this->applyFilter(new ImageFilterNegative(), $original, __METHOD__); 22 | 23 | $this->assertColorQ1($res, '01ffff'); 24 | $this->assertColorQ2($res, 'ff00fe'); 25 | $this->assertColorQ3($res, 'ffff01'); 26 | $this->assertColorQ4($res, self::BLACK); 27 | } 28 | public function testPng(){ 29 | $original = $this->getOriginalImage(ImageType::PNG); 30 | $res = $this->applyFilter(new ImageFilterNegative(), $original, __METHOD__); 31 | 32 | $this->assertColorQ1($res, '00ffff'); 33 | $this->assertColorQ2($res, 'ff00ff'); 34 | $this->assertColorQ3($res, 'ffff00'); 35 | $this->assertColorQ4($res, self::BLACK); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterNoiseTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 11 | $res = $this->applyFilter(new ImageFilterNoise(), $original, __METHOD__); 12 | 13 | // due to the random nature we cannot check coloring 14 | $this->assertEquals(600, $res->getX()); 15 | $this->assertEquals(600, $res->getY()); 16 | } 17 | public function testJpg(){ 18 | $original = $this->getOriginalImage(ImageType::JPG); 19 | $res = $this->applyFilter(new ImageFilterNoise(), $original, __METHOD__); 20 | 21 | // due to the random nature we cannot check coloring 22 | $this->assertEquals(600, $res->getX()); 23 | $this->assertEquals(600, $res->getY()); 24 | } 25 | public function testPng(){ 26 | $original = $this->getOriginalImage(ImageType::PNG); 27 | $res = $this->applyFilter(new ImageFilterNoise(), $original, __METHOD__); 28 | 29 | // due to the random nature we cannot check coloring 30 | $this->assertEquals(600, $res->getX()); 31 | $this->assertEquals(600, $res->getY()); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterRoundedCornersTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 12 | $res = $this->applyFilter(new ImageFilterRoundedCorners(100), $original, __METHOD__); 13 | 14 | $this->assertColorQ1($res, 'ffffff'); 15 | $this->assertColorQ2($res, 'ffffff'); 16 | $this->assertColorQ3($res, 'ffffff'); 17 | $this->assertColorQ4($res, 'ffffff'); 18 | } 19 | public function testJpgDefault(){ 20 | $original = $this->getOriginalImage(ImageType::JPG); 21 | $res = $this->applyFilter(new ImageFilterRoundedCorners(100), $original, __METHOD__); 22 | 23 | $this->assertColorQ1($res, 'ffffff'); 24 | $this->assertColorQ2($res, 'ffffff'); 25 | $this->assertColorQ3($res, 'ffffff'); 26 | $this->assertColorQ4($res, 'ffffff'); 27 | } 28 | public function testPngDefault(){ 29 | $original = $this->getOriginalImage(ImageType::PNG); 30 | $res = $this->applyFilter(new ImageFilterRoundedCorners(100), $original, __METHOD__); 31 | 32 | $this->assertColorQ1($res, 'ffffff'); 33 | $this->assertColorQ2($res, 'ffffff'); 34 | $this->assertColorQ3($res, 'ffffff'); 35 | $this->assertColorQ4($res, 'ffffff'); 36 | } 37 | 38 | 39 | public function testGifDarkCorner(){ 40 | $original = $this->getOriginalImage(ImageType::GIF); 41 | $res = $this->applyFilter(new ImageFilterRoundedCorners(100, new Color('ff00ff')), $original, __METHOD__); 42 | 43 | $this->assertColorQ1($res, 'ff00ff'); 44 | $this->assertColorQ2($res, 'ff00ff'); 45 | $this->assertColorQ3($res, 'ff00ff'); 46 | $this->assertColorQ4($res, 'ff00ff'); 47 | } 48 | public function testJpgDarkCorner(){ 49 | $original = $this->getOriginalImage(ImageType::JPG); 50 | $res = $this->applyFilter(new ImageFilterRoundedCorners(100, new Color('ff00ff')), $original, __METHOD__); 51 | 52 | $this->assertColorQ1($res, 'ff00ff'); 53 | $this->assertColorQ2($res, 'ff00ff'); 54 | $this->assertColorQ3($res, 'ff00ff'); 55 | $this->assertColorQ4($res, 'ff00ff'); 56 | } 57 | public function testPngDarkCorner(){ 58 | $original = $this->getOriginalImage(ImageType::PNG); 59 | $res = $this->applyFilter(new ImageFilterRoundedCorners(100, new Color('ff00ff')), $original, __METHOD__); 60 | 61 | $this->assertColorQ1($res, 'ff00ff'); 62 | $this->assertColorQ2($res, 'ff00ff'); 63 | $this->assertColorQ3($res, 'ff00ff'); 64 | $this->assertColorQ4($res, 'ff00ff'); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterSepiaFastTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 11 | $res = $this->applyFilter(new ImageFilterSepiaFast(80), $original, __METHOD__); 12 | 13 | $this->assertColorQ1($res, '9c7146'); 14 | $this->assertColorQ2($res, 'edc297'); 15 | $this->assertColorQ3($res, '683d12'); 16 | $this->assertColorQ4($res, 'ffffff'); 17 | } 18 | public function testJpgLight(){ 19 | $original = $this->getOriginalImage(ImageType::JPG); 20 | $res = $this->applyFilter(new ImageFilterSepiaFast(80), $original, __METHOD__); 21 | 22 | $this->assertColorQ1($res, '9b7045'); 23 | $this->assertColorQ2($res, 'edc297'); 24 | $this->assertColorQ3($res, '673c11'); 25 | $this->assertColorQ4($res, 'ffffff'); 26 | } 27 | public function testPngLight(){ 28 | $original = $this->getOriginalImage(ImageType::PNG); 29 | $res = $this->applyFilter(new ImageFilterSepiaFast(80), $original, __METHOD__); 30 | 31 | $this->assertColorQ1($res, '9c7146'); 32 | $this->assertColorQ2($res, 'edc297'); 33 | $this->assertColorQ3($res, '683d12'); 34 | $this->assertColorQ4($res, 'ffffff'); 35 | } 36 | 37 | public function testGifDefault(){ 38 | $original = $this->getOriginalImage(ImageType::GIF); 39 | $res = $this->applyFilter(new ImageFilterSepiaFast(), $original, __METHOD__); 40 | 41 | $this->assertColorQ1($res, '695746'); 42 | $this->assertColorQ2($res, 'baa897'); 43 | $this->assertColorQ3($res, '352312'); 44 | $this->assertColorQ4($res, 'ffffff'); 45 | } 46 | public function testJpgDefault(){ 47 | $original = $this->getOriginalImage(ImageType::JPG); 48 | $res = $this->applyFilter(new ImageFilterSepiaFast(), $original, __METHOD__); 49 | 50 | $this->assertColorQ1($res, '685645'); 51 | $this->assertColorQ2($res, 'baa897'); 52 | $this->assertColorQ3($res, '342211'); 53 | $this->assertColorQ4($res, 'ffffff'); 54 | } 55 | public function testPngDefault(){ 56 | $original = $this->getOriginalImage(ImageType::PNG); 57 | $res = $this->applyFilter(new ImageFilterSepiaFast(), $original, __METHOD__); 58 | 59 | $this->assertColorQ1($res, '695746'); 60 | $this->assertColorQ2($res, 'baa897'); 61 | $this->assertColorQ3($res, '352312'); 62 | $this->assertColorQ4($res, 'ffffff'); // 63 | } 64 | 65 | public function testGifDark(){ 66 | $original = $this->getOriginalImage(ImageType::GIF); 67 | $res = $this->applyFilter(new ImageFilterSepiaFast(0), $original, __METHOD__); 68 | 69 | $this->assertColorQ1($res, '5d5146'); 70 | $this->assertColorQ2($res, 'aea297'); 71 | $this->assertColorQ3($res, '291d12'); 72 | $this->assertColorQ4($res, 'ffffff'); 73 | } 74 | public function testJpgDark(){ 75 | $original = $this->getOriginalImage(ImageType::JPG); 76 | $res = $this->applyFilter(new ImageFilterSepiaFast(0), $original, __METHOD__); 77 | 78 | $this->assertColorQ1($res, '5c5045'); 79 | $this->assertColorQ2($res, 'aea297'); 80 | $this->assertColorQ3($res, '281c11'); 81 | $this->assertColorQ4($res, 'ffffff'); 82 | } 83 | public function testPngDark(){ 84 | $original = $this->getOriginalImage(ImageType::PNG); 85 | $res = $this->applyFilter(new ImageFilterSepiaFast(0), $original, __METHOD__); 86 | 87 | $this->assertColorQ1($res, '5d5146'); 88 | $this->assertColorQ2($res, 'aea297'); 89 | $this->assertColorQ3($res, '291d12'); 90 | $this->assertColorQ4($res, 'ffffff'); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterSepiaTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 11 | $res = $this->applyFilter(new ImageFilterSepia(80), $original, __METHOD__); 12 | 13 | $this->assertColorQ1($res, '140800'); 14 | $this->assertColorQ2($res, '745e38'); 15 | $this->assertColorQ3($res, '000000'); 16 | $this->assertColorQ4($res, 'ffe29e'); 17 | } 18 | public function testJpgLight(){ 19 | $original = $this->getOriginalImage(ImageType::JPG); 20 | $res = $this->applyFilter(new ImageFilterSepia(80), $original, __METHOD__); 21 | 22 | $this->assertColorQ1($res, '130800'); 23 | $this->assertColorQ2($res, '745f38'); 24 | $this->assertColorQ3($res, '000000'); 25 | $this->assertColorQ4($res, 'ffe29e'); 26 | } 27 | public function testPngLight(){ 28 | $original = $this->getOriginalImage(ImageType::PNG); 29 | $res = $this->applyFilter(new ImageFilterSepia(80), $original, __METHOD__); 30 | 31 | $this->assertColorQ1($res, '140800'); 32 | $this->assertColorQ2($res, '745e38'); 33 | $this->assertColorQ3($res, '000000'); 34 | $this->assertColorQ4($res, 'ffe29e'); 35 | } 36 | 37 | public function testGifDefault(){ 38 | $original = $this->getOriginalImage(ImageType::GIF); 39 | $res = $this->applyFilter(new ImageFilterSepia(), $original, __METHOD__); 40 | 41 | $this->assertColorQ1($res, '554936'); 42 | $this->assertColorQ2($res, 'b59f79'); 43 | $this->assertColorQ3($res, '211b12'); 44 | $this->assertColorQ4($res, 'ffffdf'); 45 | } 46 | public function testJpgDefault(){ 47 | $original = $this->getOriginalImage(ImageType::JPG); 48 | $res = $this->applyFilter(new ImageFilterSepia(), $original, __METHOD__); 49 | 50 | $this->assertColorQ1($res, '544936'); 51 | $this->assertColorQ2($res, 'b5a079'); 52 | $this->assertColorQ3($res, '211b12'); 53 | $this->assertColorQ4($res, 'ffffdf'); 54 | } 55 | public function testPngDefault(){ 56 | $original = $this->getOriginalImage(ImageType::PNG); 57 | $res = $this->applyFilter(new ImageFilterSepia(), $original, __METHOD__); 58 | 59 | $this->assertColorQ1($res, '554936'); 60 | $this->assertColorQ2($res, 'b59f79'); 61 | $this->assertColorQ3($res, '211b12'); 62 | $this->assertColorQ4($res, 'ffffdf'); // 63 | } 64 | 65 | public function testGifDark(){ 66 | $original = $this->getOriginalImage(ImageType::GIF); 67 | $res = $this->applyFilter(new ImageFilterSepia(0), $original, __METHOD__); 68 | 69 | $this->assertColorQ1($res, '645845'); 70 | $this->assertColorQ2($res, 'c4ae88'); 71 | $this->assertColorQ3($res, '302a21'); 72 | $this->assertColorQ4($res, 'ffffee'); 73 | } 74 | public function testJpgDark(){ 75 | $original = $this->getOriginalImage(ImageType::JPG); 76 | $res = $this->applyFilter(new ImageFilterSepia(0), $original, __METHOD__); 77 | 78 | $this->assertColorQ1($res, '635845'); 79 | $this->assertColorQ2($res, 'c4af88'); 80 | $this->assertColorQ3($res, '302a21'); 81 | $this->assertColorQ4($res, 'ffffee'); 82 | } 83 | public function testPngDark(){ 84 | $original = $this->getOriginalImage(ImageType::PNG); 85 | $res = $this->applyFilter(new ImageFilterSepia(0), $original, __METHOD__); 86 | 87 | $this->assertColorQ1($res, '645845'); 88 | $this->assertColorQ2($res, 'c4ae88'); 89 | $this->assertColorQ3($res, '302a21'); 90 | $this->assertColorQ4($res, 'ffffee'); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterSobelEdgeEnhanceTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 15 | $res = $this->applyFilter(new ImageFilterSobelEdgeEnhance(), $original, __METHOD__); 16 | 17 | $this->assertColorQ1($res, self::BLACK); 18 | $this->assertColorQ2($res, self::BLACK); 19 | $this->assertColorQ3($res, self::BLACK); 20 | $this->assertColorQ4($res, self::BLACK); 21 | } 22 | public function testJpg(){ 23 | $original = $this->getOriginalImage(ImageType::JPG); 24 | $res = $this->applyFilter(new ImageFilterSobelEdgeEnhance(), $original, __METHOD__); 25 | 26 | $this->assertColorQ1($res, self::BLACK); 27 | $this->assertColorQ2($res, self::BLACK); 28 | $this->assertColorQ3($res, self::BLACK); 29 | $this->assertColorQ4($res, self::BLACK); 30 | } 31 | public function testPng(){ 32 | $original = $this->getOriginalImage(ImageType::PNG); 33 | $res = $this->applyFilter(new ImageFilterSobelEdgeEnhance(), $original, __METHOD__); 34 | 35 | $this->assertColorQ1($res, self::BLACK); 36 | $this->assertColorQ2($res, self::BLACK); 37 | $this->assertColorQ3($res, self::BLACK); 38 | $this->assertColorQ4($res, self::BLACK); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterSobelHorizontalTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 14 | $res = $this->applyFilter(new ImageFilterSobelHorizontal(), $original, __METHOD__); 15 | 16 | $this->assertColorQ1($res, 'ffffff'); 17 | $this->assertColorQ2($res, 'ffffff'); 18 | $this->assertColorQ3($res, 'ffffff'); 19 | $this->assertColorQ4($res, 'ffffff'); 20 | } 21 | public function testJpg(){ 22 | $original = $this->getOriginalImage(ImageType::JPG); 23 | $res = $this->applyFilter(new ImageFilterSobelHorizontal(), $original, __METHOD__); 24 | 25 | $this->assertColorQ1($res, 'ffffff'); 26 | $this->assertColorQ2($res, 'ffffff'); 27 | $this->assertColorQ3($res, 'ffffff'); 28 | $this->assertColorQ4($res, 'ffffff'); 29 | } 30 | public function testPng(){ 31 | $original = $this->getOriginalImage(ImageType::PNG); 32 | $res = $this->applyFilter(new ImageFilterSobelHorizontal(), $original, __METHOD__); 33 | 34 | $this->assertColorQ1($res, 'ffffff'); 35 | $this->assertColorQ2($res, 'ffffff'); 36 | $this->assertColorQ3($res, 'ffffff'); 37 | $this->assertColorQ4($res, 'ffffff'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterSobelScharrTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 14 | $res = $this->applyFilter(new ImageFilterSobelScharr(), $original, __METHOD__); 15 | 16 | $this->assertColorQ1($res, '000000'); 17 | $this->assertColorQ2($res, '000000'); 18 | $this->assertColorQ3($res, 'ffffff'); 19 | $this->assertColorQ4($res, '000000'); 20 | } 21 | public function testJpg(){ 22 | $original = $this->getOriginalImage(ImageType::JPG); 23 | $res = $this->applyFilter(new ImageFilterSobelScharr(), $original, __METHOD__); 24 | 25 | $this->assertColorQ1($res, '000000'); 26 | $this->assertColorQ2($res, '000000'); 27 | $this->assertColorQ3($res, 'ffffff'); 28 | $this->assertColorQ4($res, '000000'); 29 | } 30 | public function testPng(){ 31 | $original = $this->getOriginalImage(ImageType::PNG); 32 | $res = $this->applyFilter(new ImageFilterSobelScharr(), $original, __METHOD__); 33 | 34 | $this->assertColorQ1($res, '000000'); 35 | $this->assertColorQ2($res, '000000'); 36 | $this->assertColorQ3($res, 'ffffff'); 37 | $this->assertColorQ4($res, '000000'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterSobelTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 14 | $res = $this->applyFilter(new ImageFilterSobel(), $original, __METHOD__); 15 | 16 | $this->assertColorQ1($res, '7b7b7b'); 17 | $this->assertColorQ2($res, 'ffffff'); 18 | $this->assertColorQ3($res, '000000'); 19 | $this->assertColorQ4($res, 'ffffff'); 20 | } 21 | public function testJpg(){ 22 | $original = $this->getOriginalImage(ImageType::JPG); 23 | $res = $this->applyFilter(new ImageFilterSobel(), $original, __METHOD__); 24 | 25 | $this->assertColorQ1($res, '767676'); 26 | $this->assertColorQ2($res, 'ffffff'); 27 | $this->assertColorQ3($res, '000000'); 28 | $this->assertColorQ4($res, 'ffffff'); 29 | } 30 | public function testPng(){ 31 | $original = $this->getOriginalImage(ImageType::PNG); 32 | $res = $this->applyFilter(new ImageFilterSobel(), $original, __METHOD__); 33 | 34 | $this->assertColorQ1($res, '7b7b7b'); 35 | $this->assertColorQ2($res, 'ffffff'); 36 | $this->assertColorQ3($res, '000000'); 37 | $this->assertColorQ4($res, 'ffffff'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/imagemanipulation/filter/ImageFilterSobelVerticalTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 14 | $res = $this->applyFilter(new ImageFilterSobelVertical(), $original, __METHOD__); 15 | 16 | $this->assertColorQ1($res, 'ffffff'); 17 | $this->assertColorQ2($res, 'ffffff'); 18 | $this->assertColorQ3($res, 'ffffff'); 19 | $this->assertColorQ4($res, 'ffffff'); 20 | } 21 | public function testJpg(){ 22 | $original = $this->getOriginalImage(ImageType::JPG); 23 | $res = $this->applyFilter(new ImageFilterSobelVertical(), $original, __METHOD__); 24 | 25 | $this->assertColorQ1($res, 'ffffff'); 26 | $this->assertColorQ2($res, 'ffffff'); 27 | $this->assertColorQ3($res, 'ffffff'); 28 | $this->assertColorQ4($res, 'ffffff'); 29 | } 30 | public function testPng(){ 31 | $original = $this->getOriginalImage(ImageType::PNG); 32 | $res = $this->applyFilter(new ImageFilterSobelVertical(), $original, __METHOD__); 33 | 34 | $this->assertColorQ1($res, 'ffffff'); 35 | $this->assertColorQ2($res, 'ffffff'); 36 | $this->assertColorQ3($res, 'ffffff'); 37 | $this->assertColorQ4($res, 'ffffff'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/imagemanipulation/generation/ImageGeneratorTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($width, $res->getWidth()); 19 | $this->assertEquals($height, $res->getHeight()); 20 | 21 | $this->assertEquals($color, ColorUtil::getColorAt($res, Coordinate::create(0,0))->getHexColor()); 22 | $this->assertEquals($color, ColorUtil::getColorAt($res, Coordinate::create($width/2,$height/2))->getHexColor()); 23 | $this->assertEquals($color, ColorUtil::getColorAt($res, Coordinate::create($width-1,$height-1))->getHexColor()); 24 | } 25 | 26 | public function testGradient() { 27 | $width = 250; 28 | $height = 750; 29 | $startColor = 'ffffff'; 30 | $endColor = '000000'; 31 | 32 | $res = ImageGenerator::gradient($width, $height, 1, new Color($startColor), new Color($endColor)); 33 | 34 | $this->assertEquals($width, $res->getWidth()); 35 | $this->assertEquals($height, $res->getHeight()); 36 | 37 | $this->assertEquals($startColor, ColorUtil::getColorAt($res, Coordinate::create(0,0))->getHexColor()); 38 | $this->assertEquals('7e7e7e', ColorUtil::getColorAt($res, Coordinate::create($width/2,$height/2))->getHexColor()); 39 | $this->assertEquals($endColor, ColorUtil::getColorAt($res, Coordinate::create($width - 1, $height - 1))->getHexColor()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/imagemanipulation/overlay/img/vignette-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elgervb/imagemanipulation/04375d9f413908e64eb67f75868fa4c6156c2cc2/tests/imagemanipulation/overlay/img/vignette-24.png -------------------------------------------------------------------------------- /tests/imagemanipulation/overlay/img/vignette-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elgervb/imagemanipulation/04375d9f413908e64eb67f75868fa4c6156c2cc2/tests/imagemanipulation/overlay/img/vignette-32.png -------------------------------------------------------------------------------- /tests/imagemanipulation/overlay/img/vignette-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elgervb/imagemanipulation/04375d9f413908e64eb67f75868fa4c6156c2cc2/tests/imagemanipulation/overlay/img/vignette-8.png -------------------------------------------------------------------------------- /tests/imagemanipulation/overlay/img/vignette.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elgervb/imagemanipulation/04375d9f413908e64eb67f75868fa4c6156c2cc2/tests/imagemanipulation/overlay/img/vignette.gif -------------------------------------------------------------------------------- /tests/imagemanipulation/overlay/img/vignette.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elgervb/imagemanipulation/04375d9f413908e64eb67f75868fa4c6156c2cc2/tests/imagemanipulation/overlay/img/vignette.jpg -------------------------------------------------------------------------------- /tests/imagemanipulation/rasterize/ImageRasterTest.php: -------------------------------------------------------------------------------- 1 | addSegment(new Segment(0, 0, 100, 100)); 9 | $raster->addSegment(new Segment(100, 0, 100, 100)); 10 | $raster->addSegment(new Segment(0, 100, 100, 100)); 11 | $raster->addSegment(new Segment(100, 100, 100, 100)); 12 | 13 | return $raster; 14 | } 15 | 16 | public function testCount() { 17 | $raster = $this->createRaster(); 18 | 19 | $this->assertEquals(4, $raster->count()); 20 | } 21 | } -------------------------------------------------------------------------------- /tests/imagemanipulation/rasterize/RasterizerTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::PNG); 16 | $filter = new ImageFilterGrayScale(); 17 | 18 | $rasterizer = new Rasterizer($image, new GridRasterStrategy(25, 25, true)); 19 | $segments = $rasterizer->getSegments(); 20 | $rasterizer->filter($filter, $segments->offsetGet(0)); 21 | $rasterizer->filter($filter, $segments->offsetGet(5)); 22 | 23 | $originalColor = "ff0000"; 24 | $filteredColor = "4c4c4c"; 25 | 26 | $color = ColorUtil::getColorAt($rasterizer->getResource(), Coordinate::create(50, 50)); 27 | $this->assertEquals($filteredColor, $color->getHexColor()); 28 | 29 | $color = ColorUtil::getColorAt($rasterizer->getResource(), Coordinate::create(160, 50)); 30 | $this->assertEquals($originalColor, $color->getHexColor()); 31 | 32 | $color = ColorUtil::getColorAt($rasterizer->getResource(), Coordinate::create(50, 160)); 33 | $this->assertEquals($originalColor, $color->getHexColor()); 34 | 35 | $color = ColorUtil::getColorAt($rasterizer->getResource(), Coordinate::create(160, 160)); 36 | $this->assertEquals($filteredColor, $color->getHexColor()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/imagemanipulation/rasterize/SegmentTest.php: -------------------------------------------------------------------------------- 1 | segment = new Segment(0, 10, 100, 110); 13 | } 14 | 15 | public function testXY() { 16 | $this->assertEquals(100, $this->segment->getWidth()); 17 | $this->assertEquals(110, $this->segment->getHeight()); 18 | } 19 | 20 | public function testCoordinate() { 21 | $this->assertEquals(0, $this->segment->getCoordinate()->getX()); 22 | $this->assertEquals(10, $this->segment->getCoordinate()->getY()); 23 | } 24 | } -------------------------------------------------------------------------------- /tests/imagemanipulation/rasterize/strategy/CenterRasterStrategyTest.php: -------------------------------------------------------------------------------- 1 | createRaster(new MockImageResource(200, 200)); 12 | 13 | $this->assertEquals(1, $raster->count()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /tests/imagemanipulation/rasterize/strategy/GridRasterStrategyTest.php: -------------------------------------------------------------------------------- 1 | createRaster(new MockImageResource(200, 200)); 12 | 13 | $this->assertEquals(4, $raster->count()); 14 | } 15 | 16 | public function testFit4Percentage() { 17 | $strategy = new GridRasterStrategy(50, 50, true); 18 | 19 | $raster = $strategy->createRaster(new MockImageResource(200, 200)); 20 | 21 | $this->assertEquals(4, $raster->count()); 22 | } 23 | 24 | public function testFit1() { 25 | $strategy = new GridRasterStrategy(100, 100); 26 | 27 | $raster = $strategy->createRaster(new MockImageResource(100, 100)); 28 | 29 | $this->assertEquals(1, $raster->count()); 30 | } 31 | 32 | public function testPartial1() { 33 | $strategy = new GridRasterStrategy(100, 100); 34 | 35 | $raster = $strategy->createRaster(new MockImageResource(99, 99)); 36 | 37 | $this->assertEquals(1, $raster->count()); 38 | } 39 | 40 | public function testPartialLarger() { 41 | $strategy = new GridRasterStrategy(100, 100); 42 | 43 | $raster = $strategy->createRaster(new MockImageResource(101, 101)); 44 | 45 | $this->assertEquals(4, $raster->count()); 46 | } 47 | 48 | public function testPartialSmaller() { 49 | $strategy = new GridRasterStrategy(100, 100); 50 | 51 | $raster = $strategy->createRaster(new MockImageResource(199, 199)); 52 | 53 | $this->assertEquals(4, $raster->count()); 54 | } 55 | } -------------------------------------------------------------------------------- /tests/imagemanipulation/reflection/ImageFilterReflectionTest.php: -------------------------------------------------------------------------------- 1 | getOriginalImage(ImageType::GIF); 11 | $res = $this->applyFilter(new ImageFilterReflection(200), $original, __METHOD__); 12 | 13 | $this->assertEquals(800, $res->getHeight(), 'Checking height'); 14 | $this->assertEquals(600, $res->getWidth(), 'Checking widht'); 15 | 16 | $this->assertColorQ1($res, self::RED); 17 | $this->assertColorQ2($res, self::GREEN); 18 | $this->assertColorQ3($res, self::WHITE); 19 | $this->assertColorQ4($res, self::WHITE); 20 | } 21 | 22 | public function testJpg(){ 23 | $original = $this->getOriginalImage(ImageType::JPG); 24 | $res = $this->applyFilter(new ImageFilterReflection(200), $original, __METHOD__); 25 | 26 | $this->assertEquals(800, $res->getHeight(), 'Checking height'); 27 | $this->assertEquals(600, $res->getWidth(), 'Checking widht'); 28 | 29 | $this->assertColorQ1($res, 'fe0000'); 30 | $this->assertColorQ2($res, '00ff01'); 31 | $this->assertColorQ3($res, self::WHITE); 32 | $this->assertColorQ4($res, self::WHITE); 33 | } 34 | public function testPng(){ 35 | $original = $this->getOriginalImage(ImageType::PNG); 36 | $res = $this->applyFilter(new ImageFilterReflection(200), $original, __METHOD__); 37 | 38 | $this->assertEquals(800, $res->getHeight(), 'Checking height'); 39 | $this->assertEquals(600, $res->getWidth(), 'Checking widht'); 40 | 41 | $this->assertColorQ1($res, self::RED); 42 | $this->assertColorQ2($res, self::GREEN); 43 | $this->assertColorQ3($res, self::WHITE); 44 | $this->assertColorQ4($res, self::WHITE); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/imagemanipulation/thumbnail/pixelstrategy/CenteredPixelStrategyTest.php: -------------------------------------------------------------------------------- 1 | assertNotNull($s); 13 | } 14 | 15 | public function testThumbJpg(){ 16 | $img = $this->getOriginalImage(ImageType::JPG); 17 | 18 | $res = ImageBuilder::create($img)->thumbCentered(300, 200)->toResource(); 19 | 20 | $this->assertEquals(300, $res->getX()); 21 | $this->assertEquals(200, $res->getY()); 22 | } 23 | 24 | public function testThumbGif(){ 25 | $img = $this->getOriginalImage(ImageType::GIF); 26 | 27 | $res = ImageBuilder::create($img)->thumbCentered(300, 200)->toResource(); 28 | 29 | $this->assertEquals(300, $res->getX()); 30 | $this->assertEquals(200, $res->getY()); 31 | } 32 | 33 | public function testThumbPng(){ 34 | $img = $this->getOriginalImage(ImageType::PNG); 35 | 36 | $res = ImageBuilder::create($img)->thumbCentered(300, 200)->toResource(); 37 | 38 | $this->assertEquals(300, $res->getX()); 39 | $this->assertEquals(200, $res->getY()); 40 | } 41 | } -------------------------------------------------------------------------------- /tests/imagemanipulation/thumbnail/pixelstrategy/MaxPixelStrategyTest.php: -------------------------------------------------------------------------------- 1 | assertNotNull($s); 17 | } 18 | 19 | public function testThumbJpg(){ 20 | $img = $this->getOriginalImage(ImageType::JPG); 21 | 22 | $res = ImageBuilder::create($img)->thumbMax(300, 200)->toResource(); 23 | 24 | $this->assertEquals(200, $res->getX()); 25 | $this->assertEquals(200, $res->getY()); 26 | } 27 | 28 | public function testThumbJpgRect(){ 29 | $img = new \SplFileInfo( __DIR__ . '/../../../test/sample-rect.jpg' ); 30 | 31 | $res = ImageBuilder::create($img)->thumbMax(300, 200)->toResource(); 32 | 33 | $this->assertEquals(100, $res->getX(), 'Checking image width'); 34 | $this->assertEquals(200, $res->getY(), 'Checking image height'); 35 | } 36 | 37 | public function testThumbGif(){ 38 | $img = $this->getOriginalImage(ImageType::GIF); 39 | 40 | $res = ImageBuilder::create($img)->thumbMax(300, 200)->toResource(); 41 | 42 | $this->assertEquals(200, $res->getX()); 43 | $this->assertEquals(200, $res->getY()); 44 | } 45 | 46 | /** 47 | * https://github.com/elgervb/imagemanipulation/issues/26 48 | */ 49 | public function testTooLargeX(){ 50 | $res = ImageGenerator::create(1251, 826, new Color('#999')); 51 | 52 | $thumbilizer = new Thumbalizer(new MaxPixelStrategy(250, 250)); 53 | $thumb = $thumbilizer->create($res); 54 | 55 | $this->assertEquals(250, $thumb->getX(), 'Checking image width'); 56 | $this->assertEquals(165, $thumb->getY(), 'Checking image height'); 57 | } 58 | 59 | /** 60 | * https://github.com/elgervb/imagemanipulation/issues/26 61 | */ 62 | public function testTooLargeY(){ 63 | $res = ImageGenerator::create(826, 1251, new Color('#999')); 64 | 65 | $thumbilizer = new Thumbalizer(new MaxPixelStrategy(250, 250)); 66 | $thumb = $thumbilizer->create($res); 67 | 68 | $this->assertEquals(165, $thumb->getX(), 'Checking image width'); 69 | $this->assertEquals(250, $thumb->getY(), 'Checking image height'); 70 | } 71 | 72 | public function testThumbPng(){ 73 | $img = $this->getOriginalImage(ImageType::PNG); 74 | 75 | $res = ImageBuilder::create($img)->thumbMax(300, 200)->toResource(); 76 | 77 | $this->assertEquals(200, $res->getX()); 78 | $this->assertEquals(200, $res->getY()); 79 | } 80 | } -------------------------------------------------------------------------------- /tests/imagemanipulation/thumbnail/pixelstrategy/PercentagePixelStrategyTest.php: -------------------------------------------------------------------------------- 1 | assertNotNull($s); 14 | } 15 | 16 | public function testThumbJpg(){ 17 | $img = $this->getOriginalImage(ImageType::JPG); 18 | 19 | $res = ImageBuilder::create($img)->thumbPercentage(50)->toResource(); 20 | 21 | $this->assertEquals(300, $res->getX()); 22 | $this->assertEquals(300, $res->getY()); 23 | } 24 | 25 | public function testThumbGif(){ 26 | $img = $this->getOriginalImage(ImageType::GIF); 27 | 28 | $res = ImageBuilder::create($img)->thumbPercentage(50)->toResource(); 29 | 30 | $this->assertEquals(300, $res->getX()); 31 | $this->assertEquals(300, $res->getY()); 32 | } 33 | 34 | public function testThumbPng(){ 35 | $img = $this->getOriginalImage(ImageType::PNG); 36 | 37 | $res = ImageBuilder::create($img)->thumbPercentage(50)->toResource(); 38 | 39 | $this->assertEquals(300, $res->getX()); 40 | $this->assertEquals(300, $res->getY()); 41 | } 42 | } -------------------------------------------------------------------------------- /tests/mocks/MockImageResource.php: -------------------------------------------------------------------------------- 1 | width = $width; 12 | $this->height = $height; 13 | } 14 | 15 | public function getY() 16 | { 17 | return $this->getHeight(); 18 | } 19 | 20 | public function getHeight() { 21 | return $this->height; 22 | } 23 | 24 | public function getX() 25 | { 26 | return $this->getWidth(); 27 | } 28 | 29 | public function getWidth() { 30 | return $this->width; 31 | } 32 | } -------------------------------------------------------------------------------- /tests/test/ImageFilterTestCase.php: -------------------------------------------------------------------------------- 1 | getImageRes($file, $aIdentifier); 31 | 32 | $aFilter->applyFilter($res); 33 | 34 | $res->setIsOverwrite(true); 35 | $res->setQuality(100); 36 | $res->createImage(); 37 | return $res; 38 | } 39 | 40 | /** 41 | * Assert that the color in quadrant 1 is 42 | * @param ImageImageResource $aRes 43 | * @param unknown_type $aColor 44 | */ 45 | protected function assertColorQ1(ImageImageResource $aRes, $aColor){ 46 | $coord = Coordinate::create(self::OFFSET, self::OFFSET); 47 | $testColor = $aRes->getColorAt($coord)->getHexColor(); 48 | $this->assertEquals($aColor, $testColor, "Checking color in quadrant 1 $coord $aColor vs $testColor"); 49 | } 50 | protected function assertColorQ2(ImageImageResource $aRes, $aColor){ 51 | $coord = Coordinate::create($aRes->getWidth() - self::OFFSET, self::OFFSET); 52 | $testColor = $aRes->getColorAt($coord)->getHexColor(); 53 | $this->assertEquals($aColor, $testColor, "Checking color in quadrant 2 $coord $aColor vs $testColor"); 54 | } 55 | protected function assertColorQ3(ImageImageResource $aRes, $aColor){ 56 | $coord = Coordinate::create(self::OFFSET, $aRes->getHeight() - self::OFFSET); 57 | $testColor = $aRes->getColorAt($coord)->getHexColor(); 58 | $this->assertEquals($aColor, $testColor, "Checking color in quadrant 3 $coord $aColor vs $testColor"); 59 | } 60 | protected function assertColorQ4(ImageImageResource $aRes, $aColor){ 61 | $coord = Coordinate::create($aRes->getWidth()-self::OFFSET, $aRes->getHeight()-self::OFFSET); 62 | $testColor = $aRes->getColorAt($coord)->getHexColor(); 63 | $this->assertEquals($aColor, $testColor, "Checking color in quadrant 4 $coord $aColor vs $testColor"); 64 | } 65 | } -------------------------------------------------------------------------------- /tests/test/sample-rect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elgervb/imagemanipulation/04375d9f413908e64eb67f75868fa4c6156c2cc2/tests/test/sample-rect.jpg -------------------------------------------------------------------------------- /tests/test/sample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elgervb/imagemanipulation/04375d9f413908e64eb67f75868fa4c6156c2cc2/tests/test/sample.gif -------------------------------------------------------------------------------- /tests/test/sample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elgervb/imagemanipulation/04375d9f413908e64eb67f75868fa4c6156c2cc2/tests/test/sample.jpg -------------------------------------------------------------------------------- /tests/test/sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elgervb/imagemanipulation/04375d9f413908e64eb67f75868fa4c6156c2cc2/tests/test/sample.png --------------------------------------------------------------------------------