Solved

PHP Fade

Posted on 2012-04-02
5
238 Views
Last Modified: 2012-04-18
Im looking at a way of creating an image which fades. I know I can use jQuery to create a fade, but Id like to do it in php so I can create shapes with fades.

So my question is, can I produce a rectangle, with a fill fading from one colour to another?

Also is it possible to create a circle, with a filling of transparent?

Thank you
0
Comment
Question by:tonelm54
5 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 37798386
Since all PHP processing is done on the server before the page gets to the browser, I don't see how PHP can help you with this.  You could possibly use AJAX to get each change from a PHP page but that is a lot of network activity accessing the server for each item.
0
 

Author Comment

by:tonelm54
ID: 37798427
Sorry, maybe some confusion, the image I'd like to be static (doesn't change after generated).

I have a template of a site which is yellow, which fades out to white or transparent (depends on the image), what I'm trying to do is create a script that will generate the image for me, so I can pass it the yellow parameter to draw the image fading to transparent, or I can pass it blue and it generates an image fading from blue to transparent.

I know it might be easier to create all the possible images, but doing it in code means I can quickly make it a shade darker or lighter without much effort.

Thank you
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 37798452
I think thats normally called a 'gradient' where it blends from one color to another.  Note that PNG and GIF support transparency but JPEG does not.  Here's a page that talks about it: http://www.bradshawenterprises.com/blog/2010/dynamically-drawing-gradients-with-php/
0
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 500 total points
ID: 37798464
What you need is usually called a "gradient".
Check out this class, as it does exactly what you are trying to do:
http://planetozh.com/blog/my-projects/images-php-gd-gradient-fill/
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37798935
If what you're looking for is a gradient, it looks something like this.Gradient from Red to White VerticallyAnd you would be doing everyone a favor if you create static images one pixel wide (or high, depending on the direction of the gradient).  Use CSS to repeat the image across the gradient area.  Generating a gradient on the server for every request is like putting new tires on your car every time you want to take a drive.  Sure, you can do it -- it just doesn't make sense in the real world.

If what you want is a fading effect like what happens to the captions on the banner images (onMouseOut) here, you can use jQuery.  Just use view source and copy my code.
http://www.landonbaseball.com/
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now