Jump to content

GD Drop Shadow


The Little Guy

Recommended Posts

With the following code, I am making a drop shadow. The issue that I am having is in the corners where the drop shadow isn't at, their is a white box. How can I make that white box transparent?

 

The result I am getting: http://hostbox.us/GD/

 

Here is the code I am using:

public function dropshadow($x, $y, $color, $alpha = 100){
// Create an image the size of the original plus the size of the drop shadow
$img = imagecreatetruecolor($this->width + $x, $this->height + $x);
// Add Alpha
        imagealphablending($img, false);
imagesavealpha($img, true);
        $transparent = imagecolorallocatealpha($img, 255, 255, 255, 127);
        // Fill the empty image with the alpha color
        imagefilledrectangle($img, 0, 0, $this->width + $x, $this->height + $y, $transparent);

// Create a drop shadow image
$drop = imagecreatetruecolor($this->width, $this->height);
imagefilledrectangle($drop, 0, 0, $this->width, $this->height, $color);

// Merge the 3 images into one
imagecopymerge($img, $drop, $x, $y, 0, 0, $this->width, $this->height, $alpha);
imagecopymerge($img, $this->img, 0, 0, 0, 0, $this->width, $this->height, 100);
return $img;
}

Link to comment
Share on other sites

http://hostbox.us/GD/

 

Okay, I figured it out! My result code won't really help anyone out, so it is useless to post it. but to explain what I did, first you need to know what I am making. I am making a GD php library that supports layers (acts similar to photoshop). So what I did, was instead of making one image with a drop shadow I attached a second image to the main image, that way you can apply filters to the main image and those filters won't affect the drop shadow.

 

To build that image in the link:

 

$mg = new MagicGraphic();

$layer1 = $mg->layer();
$layer1->importFile($file);
$layer1->filters("sepia");

$layer3 = $mg->layer();
$layer3->importFile($file2);
$layer3->filters("autoColor");
$layer3->x = 200;
$layer3->y = 20;
// Next line is not apart of the layer, just attached to it:
$layer3->dropshadow(20, 20, 0x000000, 50);

$mg->render(RENDER_JPG, null, 50);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.