diff --git a/.editorconfig b/.editorconfig index 1f5ca04..ded442d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,10 @@ -root = true -[*] -ident_style = space -indet_size = 4 +root = true +[*] +ident_style = space +indet_size = 4 +end_of_line = crlf +charset = utf-8 + +[*.md] +max_line_length = off +trim_trailing_whitespace = false \ No newline at end of file diff --git a/composer.json b/composer.json index 7c1bcc1..dcee92b 100644 --- a/composer.json +++ b/composer.json @@ -1,50 +1,50 @@ -{ - "name": "gabrieldarezzo/colorizzar", - "description": "Change the colors of an image without lose alpha channnel", - "license": "MIT", - "keywords": ["image", "gd", "rgb", "color", "alpha"], - "homepage": "https://github.com/gabrieldarezzo/colorizzar", - "authors": [ - { - "name": "Gabriel Darezzo", - "email": "darezzo.gabriel@gmail.com", - "homepage": "https://inwork.com.br" - } - ], - "require": { - "php": ">=5.4", - "ext-gd": "*" - }, - "extra": { - "class": "Colorizzar" - }, - "require-dev": { - "phpunit/phpunit": "^4.8", - "squizlabs/php_codesniffer": "2.*", - "friendsofphp/php-cs-fixer": "^2.8" - }, - "scripts": { - "test": [ - "phpunit" - ], - "ci": [ - "php-cs-fixer fix ./src", - "php-cs-fixer fix ./tests", - "phpcs --standard=PSR2 ./src", - "phpcs --standard=PSR2 ./tests", - "@test" - ] - }, - "autoload": { - "psr-4": { - "Colorizzar\\": "src/Colorizzar/" - } - }, - "autoload-dev": { - "psr-4": { - "Colorizzar\\Test\\": "tests/" - } - }, - "minimum-stability": "dev", - "version": "1.0.0" -} +{ + "name": "gabrieldarezzo/colorizzar", + "description": "Change the colors of an image without lose alpha channnel", + "license": "MIT", + "keywords": ["image", "gd", "rgb", "color", "alpha"], + "homepage": "https://github.com/gabrieldarezzo/colorizzar", + "authors": [ + { + "name": "Gabriel Darezzo", + "email": "darezzo.gabriel@gmail.com", + "homepage": "https://inwork.com.br" + } + ], + "require": { + "php": ">=5.4", + "ext-gd": "*" + }, + "extra": { + "class": "Colorizzar" + }, + "require-dev": { + "phpunit/phpunit": "^4.8", + "squizlabs/php_codesniffer": "2.*", + "friendsofphp/php-cs-fixer": "^2.4" + }, + "scripts": { + "test": [ + "phpunit" + ], + "ci": [ + "php-cs-fixer fix ./src", + "php-cs-fixer fix ./tests", + "phpcs --standard=PSR2 ./src", + "phpcs --standard=PSR2 ./tests", + "@test" + ] + }, + "autoload": { + "psr-4": { + "Colorizzar\\": "src/Colorizzar/" + } + }, + "autoload-dev": { + "psr-4": { + "Colorizzar\\Test\\": "tests/" + } + }, + "minimum-stability": "dev", + "version": "1.0.0" +} diff --git a/src/Colorizzar/ChangeColor.php b/src/Colorizzar/ChangeColor.php index e932963..9014ab7 100644 --- a/src/Colorizzar/ChangeColor.php +++ b/src/Colorizzar/ChangeColor.php @@ -173,7 +173,7 @@ public function colorizeKeepAplhaChannnel($fileOutPath) public function colorizeByNameColor($nameColor, $folderName, $fileName = '') { if (!file_exists($folderName)) { - mkdir($folderName); + mkdir($folderName, null, true); } $color = Colors::createByName($nameColor); diff --git a/src/Colorizzar/UploadFile.php b/src/Colorizzar/UploadFile.php index a74363c..52658f1 100644 --- a/src/Colorizzar/UploadFile.php +++ b/src/Colorizzar/UploadFile.php @@ -113,7 +113,7 @@ private function handle(array $file) } if (! file_exists($this->UploadPath)) { - mkdir($this->UploadPath); + mkdir($this->UploadPath, null, true); } if ($file['arquivo']['error'] !== UPLOAD_ERR_OK) { diff --git a/tests/ChangeColorTests.php b/tests/ChangeColorTests.php index 7c35a6a..a921555 100644 --- a/tests/ChangeColorTests.php +++ b/tests/ChangeColorTests.php @@ -1,196 +1,196 @@ -fileLocation); - $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); - $result = $changeColor->colorizeByNameColor('Red Violet', $this->newOutput, 'violetinha.png'); - unlink($this->newOutput . 'violetinha.png'); - rmdir($this->newOutput); - - $this->assertTrue($result); - } - - public function assertPreConditions() - { - $this->assertFileExists( - $this->fileLocation, - 'Arquivo de origem deve exitir.' - ); - } - - public function testFileCreation() - { - $this->assertTrue(file_exists($this->fileLocation)); - $this->assertTrue(is_readable($this->fileLocation)); - } - - /** - * @expectedException Exception - */ - public function testShouldValidateSetFromRGB() - { - $changeColor = new ChangeColor($this->fileLocation); - //$changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); - - //Blue Color - $red = 135; - $green = 206; - $blue = 235; - $changeColor->setToRGB($red, $green, $blue); - - $fileOut = $this->folderOut . 'new_blue_car.png'; - $changeColor->colorizeKeepAplhaChannnel($fileOut); - - $this->assertTrue(file_exists($this->fileLocation)); - } - - /** - * @expectedException Exception - */ - public function testShouldValidateSetToRGB() - { - $changeColor = new ChangeColor($this->fileLocation); - $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); - - //Blue Color - $red = 135; - $green = 206; - $blue = 235; - //$changeColor->setToRGB($red, $green, $blue); - - $fileOut = $this->folderOut . 'new_blue_car.png'; - $changeColor->colorizeKeepAplhaChannnel($fileOut); - - $this->assertTrue(file_exists($this->fileLocation)); - } - - public function testColorizeKeepAplhaChannnel() - { - $changeColor = new ChangeColor($this->fileLocation); - $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); - - //Blue Color - $red = 135; - $green = 206; - $blue = 235; - $changeColor->setToRGB($red, $green, $blue); - - $fileOut = $this->folderOut . 'new_blue_car.png'; - $changeColor->colorizeKeepAplhaChannnel($fileOut); - - $this->assertTrue(file_exists($this->fileLocation)); - } - - public function testColorizeByNameColorDefaultName() - { - $changeColor = new ChangeColor($this->fileLocation); - $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); - $result = $changeColor->colorizeByNameColor('Red Violet', $this->folderOut); - - $this->assertTrue($result); - } - - public function testColorizeByNameColorCustomName() - { - $changeColor = new ChangeColor($this->fileLocation); - $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); - $changeColor->colorizeByNameColor('Red Violet', $this->folderOut, 'violetinha.png'); - - $this->assertTrue(file_exists($this->folderOut . 'violetinha.png')); - } - - public function testColorizeLoopColors() - { - /* - $changeColor = new ChangeColor($this->fileLocation); - $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); - - foreach (Colors::getAllColors() as $color) { - $rgb = $color->getRgb(); - $targetRed = $rgb[0]; - $targetGreen = $rgb[1]; - $targetBlue = $rgb[2]; - $colorName = $color->getColorName(); - - $folderOut = $this->folderOut . $colorName . '.png'; - - $changeColor->setToRGB($targetRed, $targetGreen, $targetBlue); - $changeColor->colorizeKeepAplhaChannnel($folderOut); - } - - $this->assertTrue(file_exists($this->folderOut . 'blue.png')); - */ - $this->assertTrue(true); - } - - public function testColorizeToAllColors() - { - $changeColor = new ChangeColor($this->fileLocation); - $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); - - $resultAllColors = $changeColor->colorizeToAllColors($this->folderOut); - - $finalResult = true; - $findFile = true; - - //Check if result is true and file exists - foreach ($resultAllColors as $result) { - $finalResult = $finalResult && $result['result']; - $findFile = $findFile && file_exists($this->folderOut . $result['file_name']); - } - - $this->assertTrue($finalResult); - $this->assertTrue($findFile); - } - - public function provideValidHexName() - { - return (array) [ - 'HexaDecimal Blue' => ['#1F75FE'], - 'HexaDecimal Red' => ['#EE204D'], - 'HexaDecimal VioletBlue' => ['#324AB2'], - 'HexaDecimal Orange' => ['#FF7538'], - 'HexaDecimal TorchRed' => ['#FF1F28'], - ]; - } - - /** - * @dataProvider provideValidHexName - */ - public function testSetAndToToHex($hexaDecimal) - { - $changeColor = new ChangeColor($this->fileLocation); - $changeColor->setFromHex($this->defaultHex); - - $changeColor->setToHex($hexaDecimal); - $fileOut = $this->folderOut . $hexaDecimal . '.png'; - $changeColor->colorizeKeepAplhaChannnel($fileOut); - - $this->assertTrue(file_exists($fileOut)); - } -} +fileLocation); + $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); + $result = $changeColor->colorizeByNameColor('Red Violet', $this->newOutput, 'violetinha.png'); + unlink($this->newOutput . 'violetinha.png'); + rmdir($this->newOutput); + + $this->assertTrue($result); + } + + public function assertPreConditions() + { + $this->assertFileExists( + $this->fileLocation, + 'Arquivo de origem deve exitir.' + ); + } + + public function testFileCreation() + { + $this->assertTrue(file_exists($this->fileLocation)); + $this->assertTrue(is_readable($this->fileLocation)); + } + + /** + * @expectedException Exception + */ + public function testShouldValidateSetFromRGB() + { + $changeColor = new ChangeColor($this->fileLocation); + //$changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); + + //Blue Color + $red = 135; + $green = 206; + $blue = 235; + $changeColor->setToRGB($red, $green, $blue); + + $fileOut = $this->folderOut . 'new_blue_car.png'; + $changeColor->colorizeKeepAplhaChannnel($fileOut); + + $this->assertTrue(file_exists($this->fileLocation)); + } + + /** + * @expectedException Exception + */ + public function testShouldValidateSetToRGB() + { + $changeColor = new ChangeColor($this->fileLocation); + $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); + + //Blue Color + $red = 135; + $green = 206; + $blue = 235; + //$changeColor->setToRGB($red, $green, $blue); + + $fileOut = $this->folderOut . 'new_blue_car.png'; + $changeColor->colorizeKeepAplhaChannnel($fileOut); + + $this->assertTrue(file_exists($this->fileLocation)); + } + + public function testColorizeKeepAplhaChannnel() + { + $changeColor = new ChangeColor($this->fileLocation); + $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); + + //Blue Color + $red = 135; + $green = 206; + $blue = 235; + $changeColor->setToRGB($red, $green, $blue); + + $fileOut = $this->folderOut . 'new_blue_car.png'; + $changeColor->colorizeKeepAplhaChannnel($fileOut); + + $this->assertTrue(file_exists($this->fileLocation)); + } + + public function testColorizeByNameColorDefaultName() + { + $changeColor = new ChangeColor($this->fileLocation); + $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); + $result = $changeColor->colorizeByNameColor('Red Violet', $this->folderOut); + + $this->assertTrue($result); + } + + public function testColorizeByNameColorCustomName() + { + $changeColor = new ChangeColor($this->fileLocation); + $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); + $changeColor->colorizeByNameColor('Red Violet', $this->folderOut, 'violetinha.png'); + + $this->assertTrue(file_exists($this->folderOut . 'violetinha.png')); + } + + public function testColorizeLoopColors() + { + /* + $changeColor = new ChangeColor($this->fileLocation); + $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); + + foreach (Colors::getAllColors() as $color) { + $rgb = $color->getRgb(); + $targetRed = $rgb[0]; + $targetGreen = $rgb[1]; + $targetBlue = $rgb[2]; + $colorName = $color->getColorName(); + + $folderOut = $this->folderOut . $colorName . '.png'; + + $changeColor->setToRGB($targetRed, $targetGreen, $targetBlue); + $changeColor->colorizeKeepAplhaChannnel($folderOut); + } + + $this->assertTrue(file_exists($this->folderOut . 'blue.png')); + */ + $this->assertTrue(true); + } + + public function testColorizeToAllColors() + { + $changeColor = new ChangeColor($this->fileLocation); + $changeColor->setFromRGB($this->defaultRedRGB, $this->defaultGreenRGB, $this->defaultBlueRGB); + + $resultAllColors = $changeColor->colorizeToAllColors($this->folderOut); + + $finalResult = true; + $findFile = true; + + //Check if result is true and file exists + foreach ($resultAllColors as $result) { + $finalResult = $finalResult && $result['result']; + $findFile = $findFile && file_exists($this->folderOut . $result['file_name']); + } + + $this->assertTrue($finalResult); + $this->assertTrue($findFile); + } + + public function provideValidHexName() + { + return (array) [ + 'HexaDecimal Blue' => ['#1F75FE'], + 'HexaDecimal Red' => ['#EE204D'], + 'HexaDecimal VioletBlue' => ['#324AB2'], + 'HexaDecimal Orange' => ['#FF7538'], + 'HexaDecimal TorchRed' => ['#FF1F28'], + ]; + } + + /** + * @dataProvider provideValidHexName + */ + public function testSetAndToToHex($hexaDecimal) + { + $changeColor = new ChangeColor($this->fileLocation); + $changeColor->setFromHex($this->defaultHex); + + $changeColor->setToHex($hexaDecimal); + $fileOut = $this->folderOut . $hexaDecimal . '.png'; + $changeColor->colorizeKeepAplhaChannnel($fileOut); + + $this->assertTrue(file_exists($fileOut)); + } +}