The Little Guy Posted March 18, 2012 Share Posted March 18, 2012 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; } Quote Link to comment https://forums.phpfreaks.com/topic/259216-gd-drop-shadow/ Share on other sites More sharing options...
Mahngiel Posted March 18, 2012 Share Posted March 18, 2012 Let us know when you have a result (even a screenshot) to look at. without seeing the result yet, have you thought about using imagefilledpolygon() to make the shadow? Also, look into creating the image as a PNG and using imagesavealpha() Quote Link to comment https://forums.phpfreaks.com/topic/259216-gd-drop-shadow/#findComment-1328829 Share on other sites More sharing options...
The Little Guy Posted March 18, 2012 Author Share Posted March 18, 2012 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); Quote Link to comment https://forums.phpfreaks.com/topic/259216-gd-drop-shadow/#findComment-1328836 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.