Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong $fillColor Inside function resizeInsideRect() #22

Open
applibs opened this issue Mar 2, 2021 · 3 comments
Open

Wrong $fillColor Inside function resizeInsideRect() #22

applibs opened this issue Mar 2, 2021 · 3 comments

Comments

@applibs
Copy link

applibs commented Mar 2, 2021

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));
            }
@jtojnar
Copy link
Contributor

jtojnar commented Mar 2, 2021

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
Copy link
Contributor

jtojnar commented Mar 2, 2021

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;
 

@applibs
Copy link
Author

applibs commented Mar 2, 2021

Yes, its correct now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants