Skip to content

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

@luke83

Description

@luke83

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
            );
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions