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

Transparency using GD::pad (v2.0) #111

Open
luke83 opened this issue Aug 31, 2014 · 1 comment · May be fixed by #112
Open

Transparency using GD::pad (v2.0) #111

luke83 opened this issue Aug 31, 2014 · 1 comment · May be fixed by #112

Comments

@luke83
Copy link

luke83 commented Aug 31, 2014

Is there a way to make the method use transparent background (or preserve it from original image) for the padded output image?

// this will show image with white background:
$thumb = new GD($imgPath);
$thumb->resize(40, 40);
$thumb->pad(40, 40, [255, 255, 255]);
$thumb->save($thumbFilePath);

// this (I WOULD LIKE) will show image with transparent background:
$thumb = new GD($imgPath);
$thumb->resize(40, 40);
$thumb->pad(40, 40, false); // or any other call format to specify we wont transparent background
$thumb->save($thumbFilePath);

this is how i patched GD class, i don't know if it is the correct way, also tried with preserveAlpha with no result!

// near line 147
        if (!$color) {
            imagealphablending($this->workingImage, false);
            $fillColor = imagecolorallocatealpha($this->workingImage, 0, 0, 0, 127);
            imagefill($this->workingImage, 0, 0, $fillColor);
            imagesavealpha($this->workingImage, true);
        } else {
            // create the fill color
            $fillColor = imagecolorallocate(
                            $this->workingImage, $color[0], $color[1], $color[2]
            );

            // fill our working image with the fill color
            imagefill(
                            $this->workingImage, 0, 0, $fillColor
            );
        }
@bacinsky
Copy link

Hi, there is a fix:

public function pad($width, $height, $color = array(255, 255, 255, 127)) // <- add the alpha value
{
    // ...

   // (add following)
   imagealphablending($this->workingImage, false);
   imagesavealpha($this->workingImage, true);

    // create the fill color
    $fillColor = imagecolorallocatealpha(    // <- change to ...allocatealpha
        $this->workingImage,
        $color[0],
        $color[1],
        $color[2],
        $color[3]    // <- add the alpha value param
    ); 

bacinsky added a commit to bacinsky/PHPThumb that referenced this issue Sep 10, 2014
@bacinsky bacinsky linked a pull request Sep 10, 2014 that will close this issue
bacinsky added a commit to webino/Thumbnailer that referenced this issue Jun 7, 2018
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

Successfully merging a pull request may close this issue.

2 participants