<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Beautiful Code</title>
	<atom:link href="http://blog.zincroe.com/2009/01/beautiful-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.zincroe.com/2009/01/beautiful-code/</link>
	<description>Ramblings from the team at zinc Roe</description>
	<lastBuildDate>Tue, 24 Jan 2012 09:36:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.6</generator>
	<item>
		<title>By: keven ages</title>
		<link>http://blog.zincroe.com/2009/01/beautiful-code/comment-page-1/#comment-97</link>
		<dc:creator>keven ages</dc:creator>
		<pubDate>Thu, 05 Feb 2009 21:02:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.zincroe.com/?p=63#comment-97</guid>
		<description>lol fair enough:
&lt;pre lang=&quot;javascript&quot;&gt;
$(document).ready(function(){
    // let&#039;s hide all the div&#039;s first.  We let jQuery take care of this so that browsers or devices w/o javascript can view the content still
    $(&quot;.view-content-health-tips .item-list h3&quot;).next().hide();

   //add an effect to open the first item in our list to help the user realize how the interface works
    $(&quot;.view-content-health-tips .item-list h3:first&quot;).next().show(&quot;slow&quot;);
    $(&quot;.my-class-name .item-list h3:first&quot;).next().show(&quot;slow&quot;);

    //add a click listener to the headers to toggle the content in the list
    $(&quot;.view-content-health-tips .item-list h3&quot;).click(function () {
        $(this).next().toggle(&#039;normal&#039;);
    });
});
&lt;/pre&gt;

Essentially this creates a toggle effect for the following xHTML

&lt;pre&gt;
block 1

content 1
content 2.
content 3

block 2

content 1-1
content 2-1.
content 3-1
&lt;/pre&gt;

I love anything that only occupies a few lines of code but is both highly extensive as well as practical.</description>
		<content:encoded><![CDATA[<p>lol fair enough:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// let's hide all the div's first.  We let jQuery take care of this so that browsers or devices w/o javascript can view the content still</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.view-content-health-tips .item-list h3&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">//add an effect to open the first item in our list to help the user realize how the interface works</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.view-content-health-tips .item-list h3:first&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.my-class-name .item-list h3:first&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//add a click listener to the headers to toggle the content in the list</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.view-content-health-tips .item-list h3&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'normal'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Essentially this creates a toggle effect for the following xHTML</p>
<pre>
block 1

content 1
content 2.
content 3

block 2

content 1-1
content 2-1.
content 3-1
</pre>
<p>I love anything that only occupies a few lines of code but is both highly extensive as well as practical.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luke</title>
		<link>http://blog.zincroe.com/2009/01/beautiful-code/comment-page-1/#comment-94</link>
		<dc:creator>Luke</dc:creator>
		<pubDate>Thu, 05 Feb 2009 20:19:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.zincroe.com/?p=63#comment-94</guid>
		<description>&lt;strong&gt;@kevin&lt;/strong&gt;: don&#039;t be shy, let&#039;s see your beautiful code!</description>
		<content:encoded><![CDATA[<p><strong>@kevin</strong>: don&#8217;t be shy, let&#8217;s see your beautiful code!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: keven ages</title>
		<link>http://blog.zincroe.com/2009/01/beautiful-code/comment-page-1/#comment-93</link>
		<dc:creator>keven ages</dc:creator>
		<pubDate>Thu, 05 Feb 2009 20:04:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.zincroe.com/?p=63#comment-93</guid>
		<description>We prefer to let javascript handle the image transparency issue.  GD can be a pain sometimes for the simple reason that not everyone has it installed and it can use a lot of resources.  Great code btw, we just prefer it this way:

&lt;pre lang=&quot;javascript&quot;&gt;&lt;!-- [if IE 6]&gt; --&gt;
 
$(document).ready(function() {
    //location of transparent gif
    $.ifixpng(&#039;/sites/all/themes/proscenium/images/pixel.gif&#039;);
    //fix transparency for div id membership-block
    $(&#039;#membership-block&#039;).pngfix();
});&lt;/pre&gt;


I was going to post a piece of javascript that I found to be beautiful, however, after reading the example in the post, I think I&#039;ve been trumped.</description>
		<content:encoded><![CDATA[<p>We prefer to let javascript handle the image transparency issue.  GD can be a pain sometimes for the simple reason that not everyone has it installed and it can use a lot of resources.  Great code btw, we just prefer it this way:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;!--</span> <span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">if</span> IE <span style="color: #CC0000;">6</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span> <span style="color: #339933;">--&gt;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//location of transparent gif</span>
    $.<span style="color: #660066;">ifixpng</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/sites/all/themes/proscenium/images/pixel.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//fix transparency for div id membership-block</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#membership-block'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">pngfix</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I was going to post a piece of javascript that I found to be beautiful, however, after reading the example in the post, I think I&#8217;ve been trumped.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse</title>
		<link>http://blog.zincroe.com/2009/01/beautiful-code/comment-page-1/#comment-92</link>
		<dc:creator>Jesse</dc:creator>
		<pubDate>Mon, 26 Jan 2009 16:37:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.zincroe.com/?p=63#comment-92</guid>
		<description>I&#039;ve chosen a piece of code that&#039;s smaller in size, however not as small as JavaScript image preloading.

Mine has to do with images also, but deals with PNG images on web sites.

Internet Explorer (older versions, at least) are not setup inherently to handle alpha transparency in PNG images, but there is scripting to allow it to. In order to have proper placeholders and such I&#039;ve written some PHP code that I&#039;ve used on a few web sites to handle this gracefully.

The $root variable is set on each page loaded, I always do this to work well with relative links rather than absolute, and can write the same code across files as long as $root is set properly.

There&#039;s likely more I could add to this function to support additional IMG tag parameters, but this is pretty much all I use most of the time, so I kept it simpler.

Usage examples:
&lt;pre lang=&quot;php&quot;&gt;&lt;?php echo img_tag(&#039;transparent_image.png&#039;); ?&gt;
&lt;?php echo img_tag(&#039;transparent_image.png&#039;, 2, &#039;red&#039;, &#039;This is transparent!&#039;, &#039;right&#039;); ?&gt;
&lt;?php $png = img_tag(&#039;transparent_image.png&#039;); ?&gt;&lt;/pre&gt;

And so on...

Here&#039;s the code:

&lt;pre lang=&quot;php&quot;&gt;&lt;?php
// $img = image location/name. ie. ../images/title.png
// $bd = border size
// $bdc = border colour
// $alt = alternate text
// $align = image alignment in reference to text
function img_tag($img, $bd = 0, $bdc = NULL, $alt = NULL, $align = NULL)
{
    global $root;
    $ret = null;
    $png = false;
    $ie = false;

    // get the image size for width/height parameters
    list($w, $h) = @getimagesize($img);

    // find the extension to make sure it&#039;s a PNG file being passed
    $ext = explode(&#039;.&#039;, $img);
    if (strtolower($ext[sizeof($ext) - 1]) == &#039;png&#039;) { $png = true; }

    // make sure we only do this for MS IE
    if (stristr($_SERVER[&#039;HTTP_USER_AGENT&#039;], &#039;msie&#039;)) { $ie = true; }

    // the return variable, start with the image source.
    // - if it&#039;s IE and a PNG image, we&#039;ll display a 1x1 transparent
    // gif with the correct width/height as a placeholder,
    // otherwise we&#039;ll just display the image
    $ret = &#039;&lt;img src=&quot;&#039;;
    if ($ie &amp;&amp; $png) { $ret .= $root . &#039;images/1x1.gif&#039;; } else { $ret .= $img; }

    // add the width/height parameters and start the style tag
    $ret .= &#039;&quot; width=&quot;&#039; . $w . &#039;&quot; height=&quot;&#039; . $h . &#039;&quot; style=&quot;border: &#039;;

    // if border size isn&#039;t passed, return 0 for no border
    if (!empty($bd)) { $ret .= $bd; } else { $ret .= 0; }
    $ret .= &#039;px&#039;;

    // add a solid border with the colour specified
    if (!empty($bdc)) { $ret .= &#039; solid &#039; . $bdc; }
    $ret .= &#039;;&#039;;

    // add the alignment in the style tag too and close style parameter
    if (!empty($align)) { $ret .= &#039; text-align: &#039; . $align . &#039;;&#039;; }
    $ret .= &#039;&quot;&#039;;

    // for good measure, add HTML align parameter too
    if (!empty($align)) { $ret .= &#039; align=&quot;&#039; . $align . &#039;&quot;&#039;; }

    // add alt text, if none specified we&#039;ll use the image name
    $ret .= &#039; alt=&quot;&#039;;
    if (!empty($alt)) { $ret .= $alt; } else { $ret .= $img; }
    $ret .= &#039;&quot;&#039;;

    // now we verify if it&#039;s IE and a PNG we&#039;ll add the code to allow IE
    // to handle alpha transparency, as the width/height have to be
    // specified here also. just add another style parameter.
    if ($ie &amp;&amp; $png)
    {
        $ret .= &#039; style=&quot;width:&#039; . $w . &#039;px; height:&#039; . $h . &#039;px; &#039; .
        &#039;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\&#039;&#039; .
        $img . &#039;\&#039;, sizingMethod=\&#039;scale\&#039;);&quot;&#039;;
    }

    // close the IMG tag completely
    $ret .= &#039; /&gt;&#039;;

    // return the variable. this way it can be manipulated or just put into
    // a variable if I don&#039;t want it displayed right away. or I can just echo
    // the function name directly to have it print right away.
    return $ret;
}
?&gt;&lt;/pre&gt;

Hope this helps someone out there, and hope you can improve on what I&#039;ve done also. One likely improvement I will make is to utilize only one style tag, since IE will have two set in the same image since I&#039;m closing one and opening another. It does however, work for IE prior to version 7 back to 5.5. Version 5.0 and prior are still not going to handle this gracefully, they lack the support for this filter.

There is likely some caveats to using this also, and I know there&#039;s other ways to use it (an include JS file that is only read by IE browsers (by using an &quot;if lt IE 7.&quot; to load it, and using a script defer tag to render before the page). The above way works for me, and is how I&#039;ll keep it until I&#039;ll need additional features.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve chosen a piece of code that&#8217;s smaller in size, however not as small as JavaScript image preloading.</p>
<p>Mine has to do with images also, but deals with PNG images on web sites.</p>
<p>Internet Explorer (older versions, at least) are not setup inherently to handle alpha transparency in PNG images, but there is scripting to allow it to. In order to have proper placeholders and such I&#8217;ve written some PHP code that I&#8217;ve used on a few web sites to handle this gracefully.</p>
<p>The $root variable is set on each page loaded, I always do this to work well with relative links rather than absolute, and can write the same code across files as long as $root is set properly.</p>
<p>There&#8217;s likely more I could add to this function to support additional IMG tag parameters, but this is pretty much all I use most of the time, so I kept it simpler.</p>
<p>Usage examples:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> img_tag<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'transparent_image.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> img_tag<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'transparent_image.png'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'red'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'This is transparent!'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'right'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$png</span> <span style="color: #339933;">=</span> img_tag<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'transparent_image.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>And so on&#8230;</p>
<p>Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// $img = image location/name. ie. ../images/title.png</span>
<span style="color: #666666; font-style: italic;">// $bd = border size</span>
<span style="color: #666666; font-style: italic;">// $bdc = border colour</span>
<span style="color: #666666; font-style: italic;">// $alt = alternate text</span>
<span style="color: #666666; font-style: italic;">// $align = image alignment in reference to text</span>
<span style="color: #000000; font-weight: bold;">function</span> img_tag<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bd</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bdc</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #000088;">$alt</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #000088;">$align</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$root</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$png</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$ie</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// get the image size for width/height parameters</span>
    <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$h</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// find the extension to make sure it's a PNG file being passed</span>
    <span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ext</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ext</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'png'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$png</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// make sure we only do this for MS IE</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">stristr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'msie'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ie</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// the return variable, start with the image source.</span>
    <span style="color: #666666; font-style: italic;">// - if it's IE and a PNG image, we'll display a 1x1 transparent</span>
    <span style="color: #666666; font-style: italic;">// gif with the correct width/height as a placeholder,</span>
    <span style="color: #666666; font-style: italic;">// otherwise we'll just display the image</span>
    <span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;img src=&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ie</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$png</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$root</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'images/1x1.gif'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$img</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// add the width/height parameters and start the style tag</span>
    <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&quot; width=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$w</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; height=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$h</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; style=&quot;border: '</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// if border size isn't passed, return 0 for no border</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bd</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$bd</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'px'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// add a solid border with the colour specified</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bdc</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' solid '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$bdc</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">';'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// add the alignment in the style tag too and close style parameter</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$align</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' text-align: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$align</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">';'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// for good measure, add HTML align parameter too</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$align</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' align=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$align</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// add alt text, if none specified we'll use the image name</span>
    <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' alt=&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$alt</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$alt</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$img</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// now we verify if it's IE and a PNG we'll add the code to allow IE</span>
    <span style="color: #666666; font-style: italic;">// to handle alpha transparency, as the width/height have to be</span>
    <span style="color: #666666; font-style: italic;">// specified here also. just add another style parameter.</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ie</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$png</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' style=&quot;width:'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$w</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'px; height:'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$h</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'px; '</span> <span style="color: #339933;">.</span>
        <span style="color: #0000ff;">'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''</span> <span style="color: #339933;">.</span>
        <span style="color: #000088;">$img</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\', sizingMethod=\'scale\');&quot;'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// close the IMG tag completely</span>
    <span style="color: #000088;">$ret</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' /&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// return the variable. this way it can be manipulated or just put into</span>
    <span style="color: #666666; font-style: italic;">// a variable if I don't want it displayed right away. or I can just echo</span>
    <span style="color: #666666; font-style: italic;">// the function name directly to have it print right away.</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Hope this helps someone out there, and hope you can improve on what I&#8217;ve done also. One likely improvement I will make is to utilize only one style tag, since IE will have two set in the same image since I&#8217;m closing one and opening another. It does however, work for IE prior to version 7 back to 5.5. Version 5.0 and prior are still not going to handle this gracefully, they lack the support for this filter.</p>
<p>There is likely some caveats to using this also, and I know there&#8217;s other ways to use it (an include JS file that is only read by IE browsers (by using an &#8220;if lt IE 7.&#8221; to load it, and using a script defer tag to render before the page). The above way works for me, and is how I&#8217;ll keep it until I&#8217;ll need additional features.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

