Skip to content

Commit

Permalink
phan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Dec 26, 2021
1 parent 9593332 commit e02ac20
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 130 deletions.
7 changes: 5 additions & 2 deletions composer.json
Expand Up @@ -34,7 +34,7 @@
},

"require-dev" : {
"jbzoo/toolbox-dev" : "^3.1.0"
"jbzoo/toolbox-dev" : "^3.2.0"
},

"autoload" : {
Expand All @@ -48,7 +48,10 @@
},

"config" : {
"optimize-autoloader" : true
"optimize-autoloader" : true,
"allow-plugins" : {
"composer/package-versions-deprecated" : true
}
},

"extra" : {
Expand Down
84 changes: 42 additions & 42 deletions src/Filter.php
Expand Up @@ -42,7 +42,7 @@ final class Filter
public static function sepia($image): void
{
self::grayscale($image);
imagefilter($image, IMG_FILTER_COLORIZE, 100, 50, 0);
\imagefilter($image, \IMG_FILTER_COLORIZE, 100, 50, 0);
}

/**
Expand All @@ -52,7 +52,7 @@ public static function sepia($image): void
*/
public static function grayscale($image): void
{
imagefilter($image, IMG_FILTER_GRAYSCALE);
\imagefilter($image, \IMG_FILTER_GRAYSCALE);
}

/**
Expand All @@ -64,7 +64,7 @@ public static function grayscale($image): void
public static function pixelate($image, int $blockSize = 10): void
{
$blockSize = VarFilter::int($blockSize);
imagefilter($image, IMG_FILTER_PIXELATE, $blockSize);
\imagefilter($image, \IMG_FILTER_PIXELATE, $blockSize);
}

/**
Expand All @@ -74,7 +74,7 @@ public static function pixelate($image, int $blockSize = 10): void
*/
public static function edges($image): void
{
imagefilter($image, IMG_FILTER_EDGEDETECT);
\imagefilter($image, \IMG_FILTER_EDGEDETECT);
}

/**
Expand All @@ -84,7 +84,7 @@ public static function edges($image): void
*/
public static function emboss($image): void
{
imagefilter($image, IMG_FILTER_EMBOSS);
\imagefilter($image, \IMG_FILTER_EMBOSS);
}

/**
Expand All @@ -94,7 +94,7 @@ public static function emboss($image): void
*/
public static function invert($image): void
{
imagefilter($image, IMG_FILTER_NEGATE);
\imagefilter($image, \IMG_FILTER_NEGATE);
}

/**
Expand All @@ -108,13 +108,13 @@ public static function blur($image, int $passes = 1, int $type = self::BLUR_SEL)
{
$passes = Helper::blur($passes);

$filterType = IMG_FILTER_SELECTIVE_BLUR;
$filterType = \IMG_FILTER_SELECTIVE_BLUR;
if (self::BLUR_GAUS === $type) {
$filterType = IMG_FILTER_GAUSSIAN_BLUR;
$filterType = \IMG_FILTER_GAUSSIAN_BLUR;
}

for ($i = 0; $i < $passes; $i++) {
imagefilter($image, $filterType);
\imagefilter($image, $filterType);
}
}

Expand All @@ -126,7 +126,7 @@ public static function blur($image, int $passes = 1, int $type = self::BLUR_SEL)
*/
public static function brightness($image, int $level): void
{
imagefilter($image, IMG_FILTER_BRIGHTNESS, Helper::brightness($level));
\imagefilter($image, \IMG_FILTER_BRIGHTNESS, Helper::brightness($level));
}

/**
Expand All @@ -137,7 +137,7 @@ public static function brightness($image, int $level): void
*/
public static function contrast($image, int $level): void
{
imagefilter($image, IMG_FILTER_CONTRAST, Helper::contrast($level));
\imagefilter($image, \IMG_FILTER_CONTRAST, Helper::contrast($level));
}

/**
Expand All @@ -159,7 +159,7 @@ public static function colorize($image, string $color, float $opacity): void
$green = Helper::color($rgba[1]);
$blue = Helper::color($rgba[2]);

imagefilter($image, IMG_FILTER_COLORIZE, $red, $green, $blue, $alpha);
\imagefilter($image, \IMG_FILTER_COLORIZE, $red, $green, $blue, $alpha);
}

/**
Expand All @@ -169,7 +169,7 @@ public static function colorize($image, string $color, float $opacity): void
*/
public static function meanRemove($image): void
{
imagefilter($image, IMG_FILTER_MEAN_REMOVAL);
\imagefilter($image, \IMG_FILTER_MEAN_REMOVAL);
}

/**
Expand All @@ -180,7 +180,7 @@ public static function meanRemove($image): void
*/
public static function smooth($image, int $passes = 1): void
{
imagefilter($image, IMG_FILTER_SMOOTH, Helper::smooth($passes));
\imagefilter($image, \IMG_FILTER_SMOOTH, Helper::smooth($passes));
}

/**
Expand All @@ -194,15 +194,15 @@ public static function desaturate($image, int $percent = 100)
{
// Determine percentage
$percent = Helper::percent($percent);
$width = (int)imagesx($image);
$height = (int)imagesy($image);
$width = (int)\imagesx($image);
$height = (int)\imagesy($image);

if ($percent === self::MAX_PERCENT) {
self::grayscale($image);
} elseif ($newImage = imagecreatetruecolor($width, $height)) { // Make a desaturated copy of the image
imagealphablending($newImage, false);
imagecopy($newImage, $image, 0, 0, 0, 0, $width, $height);
imagefilter($newImage, IMG_FILTER_GRAYSCALE);
} elseif ($newImage = \imagecreatetruecolor($width, $height)) { // Make a desaturated copy of the image
\imagealphablending($newImage, false);
\imagecopy($newImage, $image, 0, 0, 0, 0, $width, $height);
\imagefilter($newImage, \IMG_FILTER_GRAYSCALE);

// Merge with specified percentage
Helper::imageCopyMergeAlpha(
Expand Down Expand Up @@ -234,13 +234,13 @@ public static function opacity($image, $opacity)
// Determine opacity
$opacity = Helper::opacity($opacity);

$width = (int)imagesx($image);
$height = (int)imagesy($image);
$width = (int)\imagesx($image);
$height = (int)\imagesy($image);

if ($newImage = imagecreatetruecolor($width, $height)) {
if ($newImage = \imagecreatetruecolor($width, $height)) {
// Set a White & Transparent Background Color
if ($background = imagecolorallocatealpha($newImage, 0, 0, 0, 127)) {
imagefill($newImage, 0, 0, $background);
if ($background = \imagecolorallocatealpha($newImage, 0, 0, 0, 127)) {
\imagefill($newImage, 0, 0, $background);

// Copy and merge
Helper::imageCopyMergeAlpha(
Expand All @@ -252,7 +252,7 @@ public static function opacity($image, $opacity)
$opacity
);

imagedestroy($image);
\imagedestroy($image);

return $newImage;
}
Expand All @@ -279,8 +279,8 @@ public static function rotate($image, int $angle, $bgColor = self::DEFAULT_BACKG
$angle = Helper::rotate($angle);
$rgba = Helper::normalizeColor($bgColor);

$newBgColor = (int)imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
$newImage = imagerotate($image, -($angle), $newBgColor);
$newBgColor = (int)\imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
$newImage = \imagerotate($image, -($angle), $newBgColor);

Helper::addAlpha($newImage);

Expand All @@ -297,19 +297,19 @@ public static function rotate($image, int $angle, $bgColor = self::DEFAULT_BACKG
public static function flip($image, string $direction)
{
$direction = Helper::direction($direction);
$width = (int)imagesx($image);
$height = (int)imagesy($image);
$width = (int)\imagesx($image);
$height = (int)\imagesy($image);

if ($newImage = imagecreatetruecolor($width, $height)) {
if ($newImage = \imagecreatetruecolor($width, $height)) {
Helper::addAlpha($newImage);

if ($direction === 'y') {
for ($y = 0; $y < $height; $y++) {
imagecopy($newImage, $image, 0, $y, 0, $height - $y - 1, $width, 1);
\imagecopy($newImage, $image, 0, $y, 0, $height - $y - 1, $width, 1);
}
} elseif ($direction === 'x') {
for ($x = 0; $x < $width; $x++) {
imagecopy($newImage, $image, $x, 0, $width - $x - 1, 0, 1, $height);
\imagecopy($newImage, $image, $x, 0, $width - $x - 1, 0, 1, $height);
}
} elseif ($direction === 'xy' || $direction === 'yx') {
$newImage = self::flip($image, 'x');
Expand All @@ -332,14 +332,14 @@ public static function flip($image, string $direction)
*/
public static function fill($image, $color = self::DEFAULT_BACKGROUND): void
{
$width = (int)imagesx($image);
$height = (int)imagesy($image);
$width = (int)\imagesx($image);
$height = (int)\imagesy($image);

$rgba = Helper::normalizeColor($color);
$fillColor = (int)imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
$fillColor = (int)\imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);

Helper::addAlpha($image, false);
imagefilledrectangle($image, 0, 0, $width, $height, $fillColor);
\imagefilledrectangle($image, 0, 0, $width, $height, $fillColor);
}

/**
Expand All @@ -366,25 +366,25 @@ public static function text($image, string $text, string $fontFile, array $param
*/
public static function border($image, array $params = []): void
{
$params = array_merge([
$params = \array_merge([
'color' => '#333',
'size' => 1,
], $params);

$size = Vars::range((int)$params['size'], 1, 1000);
$rgba = Helper::normalizeColor((string)$params['color']);
$width = (int)imagesx($image);
$height = (int)imagesy($image);
$width = (int)\imagesx($image);
$height = (int)\imagesy($image);

$posX1 = 0;
$posY1 = 0;
$posX2 = $width - 1;
$posY2 = $height - 1;

$color = (int)imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);
$color = (int)\imagecolorallocatealpha($image, $rgba[0], $rgba[1], $rgba[2], $rgba[3]);

for ($i = 0; $i < $size; $i++) {
imagerectangle($image, $posX1++, $posY1++, $posX2--, $posY2--, $color);
\imagerectangle($image, $posX1++, $posY1++, $posX2--, $posY2--, $color);
}
}
}

0 comments on commit e02ac20

Please sign in to comment.