NeilMac Posted February 5, 2012 Share Posted February 5, 2012 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 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) Quote Link to comment https://forums.phpfreaks.com/topic/256458-new-to-php-helpadvice-on-turning-data-into-an-image/ Share on other sites More sharing options...
litebearer Posted February 5, 2012 Share Posted February 5, 2012 Might start by looking here ... http://terriswallow.com/weblog/2007/writing-text-to-images-with-php/ Quote Link to comment https://forums.phpfreaks.com/topic/256458-new-to-php-helpadvice-on-turning-data-into-an-image/#findComment-1314741 Share on other sites More sharing options...
NeilMac Posted February 5, 2012 Author Share Posted February 5, 2012 Might start by looking here ... http://terriswallow.com/weblog/2007/writing-text-to-images-with-php/ 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 Quote Link to comment https://forums.phpfreaks.com/topic/256458-new-to-php-helpadvice-on-turning-data-into-an-image/#findComment-1314773 Share on other sites More sharing options...
digibucc Posted February 5, 2012 Share Posted February 5, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256458-new-to-php-helpadvice-on-turning-data-into-an-image/#findComment-1314775 Share on other sites More sharing options...
NeilMac Posted February 5, 2012 Author Share Posted February 5, 2012 Thanks digibucc, thats worked perfectly! Really appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/256458-new-to-php-helpadvice-on-turning-data-into-an-image/#findComment-1314783 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.