Hi,
I have spent hours and hours trying to come up with a solution and I simply cant seem to do it. What I am trying to do is, using GD2, draw a rectangle (with varying stroke) which has smooth rounded corners. The problem is that it is a border to be overlayed over a background image so the rectangle and corners need to be transparent.
I have had some success by creating graphics for the corners but when they are resampled to create the antialiasing effect it alters the colour so when I set the transparency, only some of the pixels are removed.
Can anyone help??
Example: http://www.betaversion.co.uk/rounded.php
Rounded Corners with Transparency
Moderators: onion2k, General Moderators
resizing transparent images is quite tricky, because resampling doesn't keep color values intact. You've discovered that already.
I think the best way to do this would be to use a truecolor image and alpha channel, and only convert to transparent image at the end, after resizing with resample. This would have the desired effect, because you must be aware of the fact that even if you successfully resized a transparent image, the pixels that lay on the edge of the border will be background-ish (white-ish in your case) due to mixing white pixels with border pixels. These pixels wouldn't be neither border-color nor white. So if you'd then merge this image onto a background, that white artifacts will be very visible, unless the background itself is white (which it isn't, otherwise you wouldn't care about transparency).
Or, if not that, you can use 24-bit pngs if you don't mind the fact that IE6 doesn't support them.
But, anyhow, do you mind posting your code so I can take a look? I have some experience with resizing, because I've managed to handle it in my image library (see my sig). It doesn't support drawing, but maybe you'd find it useful.
regards
I think the best way to do this would be to use a truecolor image and alpha channel, and only convert to transparent image at the end, after resizing with resample. This would have the desired effect, because you must be aware of the fact that even if you successfully resized a transparent image, the pixels that lay on the edge of the border will be background-ish (white-ish in your case) due to mixing white pixels with border pixels. These pixels wouldn't be neither border-color nor white. So if you'd then merge this image onto a background, that white artifacts will be very visible, unless the background itself is white (which it isn't, otherwise you wouldn't care about transparency).
Or, if not that, you can use 24-bit pngs if you don't mind the fact that IE6 doesn't support them.
But, anyhow, do you mind posting your code so I can take a look? I have some experience with resizing, because I've managed to handle it in my image library (see my sig). It doesn't support drawing, but maybe you'd find it useful.
regards
Re: Rounded Corners with Transparency
that php rounded corners looks great, thanks for sharing