stil / gd-text

PHP class making it easy to type text on pictures. Supports multi-lined text, horizontal and vertical alignment.
401 stars 130 forks source link

Bad text shadow #10

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hi,

When creating text within a white background, text shadow gets badly shaped (at least for me). To solve it, i rewrote the "Color->getIndex()" function. It works fine for me now:

/**
 * @param resource $image GD image resource
 * @return int Returns the index of the specified color+alpha in the palette of the image,
 *             or -1 if the color does not exist in the image's palette.
 */
public function getIndex($image)
{
    $color = -1;
    if ($this->hasAlphaChannel()) {
        if(($color = imagecolorexactalpha(
            $image,
            $this->red,
            $this->green,
            $this->blue,
            $this->alpha
        )) == -1){
            $color = imagecolorallocatealpha(
                $image,
                $this->red,
                $this->green,
                $this->blue,
                $this->alpha
            );
        }
    } else {
        if(($color = imagecolorexact(
            $image,
            $this->red,
            $this->green,
            $this->blue
        )) == -1){
            $color = imagecolorallocate(
                $image,
                $this->red,
                $this->green,
                $this->blue
            );
        }
    }
    return $color;
}

Before

thumb_bad

After

thumb_ok

stil commented 8 years ago

It seems that images other that True Color are affected (ie. GIFs or PNG-8). Thanks for pointing it out, I will fix it soon.