Jump to content

new to PHP, help/advice on turning data into an image


NeilMac

Recommended Posts

Hi, I'm pretty new to PHP, struggled my way through most of my encounters with PHP so far, but getting the hang of it  8)

 

I'm looking for a simple script that turns a number or word served by a weather station into a graphic. E.g. If the temp is 20 degrees, a graphic I've designed would be shown, or a cloud or the sun or whatever.

 

At the moment the weather station feed is converted from 'webtags' in to php tags (temp is $temp, wind is $wind etc.) and these echo out as numbers and words on the website.

 

I can sort of see how it would work in my head, but need a little help.

 

Can anyone please point me in the right direction?

 

Thanks  :)

 

(for reference site is www.southtyneweather.co.uk)

Link to comment
Share on other sites

 

Thanks, but I think that is an overly complicated way of doing what I need, rather than adding text to an image I need to to directly replace the text value, e.g. replace the word '1°C' with a pre-designed graphic called '1degreec.gif', I would rather spend more time creating a shed load of separate graphics than use too much PHP.

 

Bearing in mind I would be replacing several values, therefore adapting and running the above mentioned script seems like overkill  :shrug:

Link to comment
Share on other sites

so you'd take that $temp variable

and then :

 
<?php
echo '<img src="images/degrees/'.  str_replace(chr(176), '',  $temp). '.jpg" alt="'. $temp. '">';
?>

 

or if it's an html page mostly

 

 

 
<img src="images/degrees/<?php echo str_replace(chr(176), '', $temp). '.jpg" alt="'. $temp; ?> ">

 

and then just have an images/degrees/ folder with 20.jpg, 21.jpg, etc in it. or whatever format you need, just change the extension in the code.

 

 

rereading just do a str_replace, taking out the degree symbol, and then name the images 20C.jpg, etc. i updated the code above to reflect that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.