WideImage icon indicating copy to clipboard operation
WideImage copied to clipboard

Wrong $fillColor Inside function resizeInsideRect()

Open applibs opened this issue 3 years ago • 3 comments

This function has param $fillColor = null abn when is not passed, image is filled black color! Who said that background color must be black and not white or transparent. I expect transparent color and other colors only when is passed.

Something like this:

if ($fillColor) {
                if (is_numeric($fillColor)) {
                    $fillColor = $this->getColorRGB($fillColor);
                }
            } else {
                // $fillColor = $this->getColorRGB($this->getColorAt(0, 0));
            }
            
            $rect = WideImage::createTrueColorImage($width, $height);
            if($fillColor) {
                $rect->fill(0, 0, $rect->allocateColor($fillColor));
            } else {
                $rect->fill(0, 0, $rect->setTransparentColor(0));
            }

applibs avatar Mar 02 '21 17:03 applibs

Currently, it falls back to the colour of pixel in corner, which sounds reasonable to me. Your image probably has fully-transparent black pixel. The issue is that it does not preserve the alpha.

jtojnar avatar Mar 02 '21 19:03 jtojnar

Does the following change fix your issue?

diff --git a/lib/TrueColorImage.php b/lib/TrueColorImage.php
index 38ce416..c8c4161 100644
--- a/lib/TrueColorImage.php
+++ b/lib/TrueColorImage.php
@@ -285,7 +285,7 @@ class TrueColorImage extends Image
         }
 
         $rect = WideImage::createTrueColorImage($width, $height);
-        $rect->fill(0, 0, $rect->allocateColor($fillColor));
+        $rect->fill(0, 0, $rect->allocateColorAlpha($fillColor));
 
         $img = $this;
 

jtojnar avatar Mar 02 '21 19:03 jtojnar

Yes, its correct now.

applibs avatar Mar 02 '21 20:03 applibs