1 reply [Last post]
trib
Offline
Regular
London, UK
Last seen: 16 years 51 weeks ago
London, UK
Joined: 2004-03-12
Posts: 11
Points: 0

I understand and agree with the basic principle that if an image is part of the content of a page, it should be included as an IMG tag, whereas if it is a design element that is not part of the 'message', it should be a CSS background.

However, on a site I am doing at the moment, I have a client whose designer insists that all headings must be in Meta, so they have to be images for the benefit of us mere mortals who don't have every font known to man. To make matters more interesting, the title text is retrieved from a database and can change at the drop of a hat.

To generate these titles I have therfore used an image-generating PHP script, which is referenced something like this:

http://ab-twtc2004001.ginger.assanka.com/lib/inc/imagetext/11101008211625525525532/mtbkro/Welcome

(long string of numbers includes things like foreground rgb, background rgb, font size etc)

The question

Since I don't know the size of the image before it is generated, how can I create a CSS container for it? At the moment those images that are dynamic are being placed directly into the XHTML:

http://ab-twtc2004001.ginger.assanka.com/

Is this appropriate practice, and can anyone suggest a more elegant solution?

Andrew[/b]

ClevaTreva
ClevaTreva's picture
Offline
Guru
A hilly place, UK
Last seen: 2 years 17 weeks ago
A hilly place, UK
Joined: 2004-02-05
Posts: 2902
Points: 0

best practice for background image with unknown size

Hi

If you are using the gd library to make the image, which I assume you are, rather than feed it directly, save it to a file, then use the gd getimagesize function to get the image attributes and then set these in the css using php echo's. This would have to be done inline rather than in the css file.

I am going to assume that there are a finite number of images you might make, and so caching these on the server makes sense.

The script would make a name that would accurately describe the image so that should it be needed again you could check to see if it exists, and only if it doesn't do you make a new image.

Would that work?

Trevor