PDA

View Full Version : Creating image of text using php



Morgenmuffel
08-02-2007, 10:28 AM
Hi all

Situation is this

A client wants to put captions on her images (in jpg format) that will be used in a slideshow
This needs to be done on the server

my plan was to have her enter the relevant text press enter and the text would be written on to a gif with a semitransparent background which would then be added to the bottom of her image (jpg)

I know i have explained badly but basically the end result should look like this (http://nigel.geek.nz/burger.jpg)

Thing is i have no idea how to ....


convert text to an image
put the resulting image Gif on to a jpeg and keep the semitransparent background of the gif so the jped shows through a little


any help would be appreciated

Greg
08-02-2007, 10:43 AM
1) Screenshot and paste into your image editor.
2) Use something like Pictureshark (free).

Erayd
08-02-2007, 10:56 AM
What is the intended use for the images? Is the slideshow going to be run in a web browser? If so, then I recommend you use CSS rather than altering the images to achieve the effect - it's a lot faster, and takes a fair bit of processing load off the server. The effect will render in all major browsers except Konqueror/Safari. The CSS tags needed are position, z-index, and the three browser-specific opacity tags.

If you must alter the images themselves, then PHP has a built-in graphics library called 'gd' that will do what you want. Alternatively, you can use a plugin library for something like ImageMagick.

Greg
08-02-2007, 11:46 AM
I recommend you use CSS rather than altering the images to achieve the effect - it's a lot faster, and takes a fair bit of processing load off the server. The effect will render in all major browsers except Konqueror/Safari. The CSS tags needed are position, z-index, and the three browser-specific opacity tags.

If you must alter the images themselves, then PHP has a built-in graphics library called 'gd' that will do what you want. Alternatively, you can use a plugin library for something like ImageMagick.Riiiight. So he has to ask the questions but suddenly knows how to use CSS and PHP's GD? :lol:

Rob99
08-02-2007, 11:52 AM
http://blog.neatlysliced.com/index.php/category/css/

Erayd
08-02-2007, 02:03 PM
Riiiight. So he has to ask the questions but suddenly knows how to use CSS and PHP's GD? :lol:You got it. The reasoning for my logic was this:

1. The processing 'needs to be done on the server' - by 'server' I am assuming he is meaning a webserver in this case, and the client's uploading images to it.

2. As the processing must be done on the server, some kind of CGI is required - and seeing as PHP is installed on most webservers, he most likely has access to GD.

3. If he is responsible for a website that drives all this, then he likely knows CSS. However as I have run into a lot of people that 'know CSS' but don't know how to use some of the newer CSS2 techniques, I mentioned which tags were required.

4. If he doesn't understand it, he can ignore it - better to make a suggestion that _might_ be helpful than to shut up and let him be told it's not possible.

Erayd
08-02-2007, 02:06 PM
[could some mod remove this please? - irrelevant post]

Morgenmuffel
08-02-2007, 02:33 PM
Ok thanks for the suggestions, just realized a left out some rather important parts of the equation, (you sometimes forget that not everyone is in the same room as you).

the images are going to be used by an existing flash slideshow that is controlled with an XML file, basically the customer wants simple captions on the image (like the one displayed earlier).

I want this done on the server mainly because i can control and to a certain extent idiot proof the process of adding new images, making the caption sizes and fonts standard so the slideshow looks at least moderately coherent

CSS is also out as I don't want to figure out how to get CSS styles working inside a Flash window and also because about 10% of the sites users are using IE 5 browsers which from memory had hopeless CSS support, I do use CSS on other parts of the site but mainly limit it to the really basic stuff

I am planning on using the GD or imagemagic libraries as they are both installed, but i have never turned text into an image and I am really unsure of how to add the caption to the image and retain the required transparency
I can't seem to find a tutorial that explains this in baby steps or at least clear english

mejobloggs
08-02-2007, 02:43 PM
http://www.php.net/manual/en/function.imagettftext.php
http://www.scriptplayground.com/tutorials/php/Text-On-Image/

And I think you can get phpThumb() which will do it for you: http://phpthumb.sourceforge.net/
(Note that using phpThumb to do stuff with images on the fly would probably be quite heavy on the server. But I think you can get phpThumb() to write to a file as well, so it won't be on the fly)