<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rupstjarn 55 &#187; PHP Scripts</title>
	<atom:link href="http://domotica.ronnkvist.nu/category/php-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://domotica.ronnkvist.nu</link>
	<description>Domotica - Home Automation</description>
	<lastBuildDate>Thu, 05 Nov 2009 09:57:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dynamic thermometer-image</title>
		<link>http://domotica.ronnkvist.nu/blog/2009/09/18/dynamic-thermometer-image/</link>
		<comments>http://domotica.ronnkvist.nu/blog/2009/09/18/dynamic-thermometer-image/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 07:42:17 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[PHP Scripts]]></category>
		<category><![CDATA[Dynamic]]></category>
		<category><![CDATA[Thermometer]]></category>

		<guid isPermaLink="false">http://domotica.ronnkvist.nu/?p=172</guid>
		<description><![CDATA[If you want to create a dynamic thermometer for your webpage PHP has some capability to create and modify images.
The script below can be called with http://domotica.ronnkvist.nu/temperature-scripts/termometer.php?temp=22 to create an image like this:


&#60;?php
	// Should be in even 5's (20, 25, 30 and so on)
	$maxTemp = 30;
	$minTemp = -30;

	// Where should the bar be placed?
	$barStart = [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to create a dynamic thermometer for your webpage PHP has some capability to create and modify images.</p>
<p>The script below can be called with http://domotica.ronnkvist.nu/temperature-scripts/termometer.php?temp=22 to create an image like this:<br />
<img src="http://domotica.ronnkvist.nu/temperature-scripts/termometer.php?temp=22" alt="22" /></p>
<pre class="brush: php;">
&lt;?php
	// Should be in even 5's (20, 25, 30 and so on)
	$maxTemp = 30;
	$minTemp = -30;

	// Where should the bar be placed?
	$barStart = 8;
	$maxHeight = 172;
	$totalBarHeight = 164;

	// Colors and what background to use
    $tmpImg = @imagecreatefrompng(&quot;termometer.png&quot;);
	$colBar = imagecolorallocate($tmpImg, 208, 33, 33);
	$colBlack = imagecolorallocate($tmpImg, 0, 0, 0);

	// Temperature-lines
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 0), 22, $barStart+(($totalBarHeight/6) * 0), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 1), 22, $barStart+(($totalBarHeight/6) * 1), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 2), 22, $barStart+(($totalBarHeight/6) * 2), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 3), 22, $barStart+(($totalBarHeight/6) * 3), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 4), 22, $barStart+(($totalBarHeight/6) * 4), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 5), 22, $barStart+(($totalBarHeight/6) * 5), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 6), 22, $barStart+(($totalBarHeight/6) * 6), $colBlack);

	// Text-strings by the lines
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 0)-4, &quot; 30&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 1)-4, &quot; 20&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 2)-4, &quot; 10&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 3)-4, &quot;  0&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 4)-4, &quot;-10&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 5)-4, &quot;-20&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 6)-4, &quot;-30&quot;, $colBlack);

	$temperature = trim($_GET['temp']);
	if ($temperature == &quot;&quot;) {
		$temperature = 0;
	}

	// Calculate the bar-height
	$tempSpan = (0 - $minTemp) + $maxTemp;
	if ($temperature == 0) {
		$barHeight = ($totalBarHeight / 2);
	} elseif ($temperature &gt; 0) {
		if ($temperature &gt;= $maxTemp) {
			$barHeight = $totalBarHeight;
		} else {
			$barHeight = ($totalBarHeight / 2) + (($temperature / $maxTemp) * ($totalBarHeight / 2));
		}
	} else {
		if ($temperature &lt;= $minTemp) {
			$barHeight = 0;
		} else {
			$barHeight = ($totalBarHeight / 2) - (($totalBarHeight / 2) * ((0-$temperature) / (0-$minTemp)));
		}
	}

	// Temperature-bar
	imagefilledrectangle($tmpImg, 7, $barStart+($totalBarHeight-$barHeight), 13, 172, $colBar);

	// Create the image
	header( &quot;Content-type: image/png&quot; );
	imagepng($tmpImg );
?&gt;
</pre>
<p>The background image is found at <a href="http://domotica.ronnkvist.nu/temperature-scripts/termometer.png">http://domotica.ronnkvist.nu/temperature-scripts/termometer.png</a></p>
]]></content:encoded>
			<wfw:commentRss>http://domotica.ronnkvist.nu/blog/2009/09/18/dynamic-thermometer-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

