Page 1 of 1
Rounding corners using gd
Posted: Mon Sep 07, 2009 10:57 pm
by Existance0
So, it seemed to work at first when I was only rounding the top right corner but once I rotated the image for the other corners it just puts white boxes there.
Code: Select all
//Create the image
$img=imagecreatetruecolor(250,350);
//The following rounds the corners
$corner=imagecreatefrompng('rounded_corner.png');
//Top-left corner
imagecopymerge($img,$corner,0,0,0,0,5,5,100);
//Bottom-left corner
$rotated=imagerotate($corner,90,0);
imagecopymerge($img,$rotated,0,345,0,0,5,5,100);
//Bottom-right corner
$rotated=imagerotate($corner,180,0);
imagecopymerge($img,$rotated,245,345,0,0,5,5,100);
//Top-right corner
$rotated=imagerotate($corner,270,0);
imagecopymerge($img,$rotated,245,0,0,0,5,5,100);
//Output the image to the browser
header("Content-type:image/png");
imagepng($img);
Anyone know whats wrong?
Re: Rounding corners using gd
Posted: Mon Sep 07, 2009 11:03 pm
by Ollie Saunders
I don't know the answer for sure but it wouldn't surprise me if it turns out that this is just a shortcoming of GD. I've found many things like this that are supposed to work but you get just white or black or whatever. There are a load of compilation options for GD that affect it's capabilities so that might have something to do with it, I don't think I ever managed to get them all switched on and working I can't remember why not now, it was quite a while ago.
If you're looking for a quick(ish) solution you might have to resort to putting pixels in rounded corner shapes, which could be fun, it's not every day you get to call trigonometry functions.
Re: Rounding corners using gd
Posted: Mon Sep 07, 2009 11:08 pm
by Existance0
I actually found that it is most likely related to setting the transparency.
I had originally had lime green set as a transparent color but later removed it so that was an issue but I was using...
wrong. I took out these lines and ended up getting the top left corner to work again (because changing lime to black made it the opposite of what I wanted). But I think the problem lies in that the other corners after rotated lose their transparency which makes them become that white square instead of the original transparent one that I'm merging with it.
EDIT:
Wow, it appears to be a problem with both rotating the image and setting the transparency. Leaving the top left corner with no transparency it overlays the corner correctly with white outside of the rounded edge. Setting white to be transparent like so...
Code: Select all
imagecolortransparent($img, $white);
Doesn't make the outside white transparent but rather just switches the colors making the white now on the inside of the rounded corner.
The rotating on the other hand and part that is rotated with or without being set transparent returns a white square.
Re: Rounding corners using gd
Posted: Tue Sep 08, 2009 7:43 am
by Existance0
Example:
http://arch-games.com/FFCG/test.html
OK, if I set transparency then it just switches the colors. As seen in the top left corner. Rotating the image at all makes the image become a white square as seen in the other three corners.