Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Radial gradients with opacity in PHP

I need to create a PNG radial gradient with opacity. I've looked through GDLib but I can't see a way to generate radial gradients. Does anyone know of a way with GDlib or any other graphics library for PHP?

I suppose worst-case I could generate it pixel-by-pixel using GDLib but how does one even start to do the math on that?

The goal is to generate sexy lighting effect background PNGs for web pages. An example of the effect can be seen on the header here which uses this background image. I've tried generic white lighting effect PNGs but it doesn't look anywhere near as good as tinted lighting, so my generated PNGs will take into account the website's color scheme.

I assume server-side is the way to go because browser support for CSS radial gradients is so patchy.

like image 963
Tak Avatar asked Nov 21 '25 14:11

Tak


1 Answers

Why not use a combination of imagecolorallocatealpha() and imageellipse() or imagefilledellipse()?

Edit:

See this class for an example of what I mean. You should be able to extend this to support alpha.

Edit2:

I have made some modifications to the class above to yield alpha support. It's not perfect, but it works for ellipses and such:

http://codepad.org/1eZ3Km0J

like image 191
Justin ᚅᚔᚈᚄᚒᚔ Avatar answered Nov 23 '25 02:11

Justin ᚅᚔᚈᚄᚒᚔ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!