<?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>camwebdesign.com &#187; Techniques</title>
	<atom:link href="http://camwebdesign.com/category/techniques/feed/" rel="self" type="application/rss+xml" />
	<link>http://camwebdesign.com</link>
	<description>High quality, cost effective wed design and hosting solutions</description>
	<lastBuildDate>Mon, 12 Jul 2010 10:54:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Serve Resized Images with PHP</title>
		<link>http://camwebdesign.com/techniques/serve-resized-images-with-php/</link>
		<comments>http://camwebdesign.com/techniques/serve-resized-images-with-php/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 19:33:00 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Images]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=605</guid>
		<description><![CDATA[This is the first tutorial of our PHP image tutorial series. There are many reasons we use PHP to serve images on sites including: resizing, watermarking, manipulation, skewing, server-caching, etc. This will cover the basics of serving and resizing an image with PHP. This technique will work with JPG, JPEG, GIF &#038; PNG image types. [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first tutorial of our PHP image tutorial series.  There are many reasons we use PHP to serve images on sites including: resizing, watermarking, manipulation, skewing, server-caching, etc.  This will cover the basics of serving and resizing an image with PHP.  This technique will work with JPG, JPEG, GIF &#038; PNG <span id="more-605"></span>image types.  We&#8217;ll cover more advanced image manipulation techniques in later posts.  Now lets get into the PHP code for the image manipulation.</p>
<p>The first line of code calls the functions.phtml include we defined in our <a href="http://camwebdesign.com/techniques/php-image-manipulation-functions/">PHP Image Manipulation Functions</a> post, change the &#8220;/path/to/include/&#8221; to your path.  The second line <a href="http://php.net/manual/en/reserved.variables.get.php">$_GET</a>s the image file from the URL we want to manipulate, and assigns it to the $img1 variable.  The third line checks if this requested image is a file, otherwise we use a generic <em>&#8220;No Photo&#8221;</em> image to prevent no image from displaying, feel free to copy ours at the bottom of the post.  The fourth line checks if the requested file is an image and surrounds the remaining code with the if statement.</p>
<div>
<pre><code id="code1">include_once("/path/to/include/functions.phtml");
$img1 = "/images/" . urldecode(stripslashes($_GET[img]));
if(!is_file($img1)) $img1 = "/images/nophoto.gif";
if(is_image($img1)){ 

   /*** The rest of the Code ***/

}</code></pre>
</div>
<p>Next part of the code gets the MIME type of the image file and calls the proper image header based on that MIME type.</p>
<div>
<pre><code id="code2">  //Send proper image header base on mime type
  $mime=get_mime($img1);
  header("Content-type: ".$mime);
</code></pre>
</div>
<p>With the following code we determine the final image&#8217;s width and height.  Based on the presence of $_GET[a] variable in the URL used to represent aspect, our code: makes a smaller image with the aspect ratio kept intact, otherwise it makes a thumbnail with equal width and height starting from the image&#8217;s center.  For thumbnails a width of 100 pixels is default, if we do not specify a width, with a max of 178 pixels.  For non-thumbnails (with aspect preserved) a default width of 300 pixels is set with a maximum of 588 pixels.  These numbers can be changed, we just set them to work within our site&#8217;s layout.</p>
<div>
<pre><code id="code3">  // Set dimensions, quality &#038; variables
  $width = $_GET[w];
  $v = ($_GET[a]) ? "none" : "thumb" ;
  if($v == "thumb") {
    ($width) ? "" : $width = 100;
    ($width > 178) ? $width = 178 : "" ;
    $height = $width;
    $thmb_quality = 100;
  }else{
    ($width) ? "" : $width = 300;
    ($width > 588) ? $width = 588 : "" ;
    $height = $width;
    $thmb_quality = 100;
  }</code></pre>
</div>
<p>We then determine the original image&#8217;s width and height.</p>
<div>
<pre><code id="code4">  // Get orig dimensions
  list($width_orig, $height_orig, $type_orig) = getimagesize($img1);
  $src_x=0;
  $src_y=0;</code></pre>
</div>
<p>With the following code we determine the final image&#8217;s width and height.  Our code makes thumbnails with equal with and height from an image&#8217;s center, or a smaller image with the aspect ratio kept intact all based on the presence of $_GET[a] variable in the URL.</p>
<div>
<pre><code id="code5">  if(!$_GET[a]){
    //it's a thumbnail request, make it square from the center
    if ($width_orig < $height_orig) {
      $src_y=($height_orig-$width_orig)/2;
      $height_orig=$width_orig;
    }else{
      $src_x=($width_orig-$height_orig)/2;
      $width_orig=$height_orig;
    }
	}else{
    //keep aspect ratio but keeping width set from page
    $height = ($width / $width_orig) * $height_orig;
  }</code></code></pre>
</div>
<p>Finally we resample then print the image with PHP.</p>
<div>
<pre><code id="code6">  // Resample
  $image=imagecreatefrom($img1);
  $im = imagecreatetruecolor($width, $height);
  imagecopyresampled($im, $image, 0, 0, $src_x, $src_y, $width, $height, $width_orig, $height_orig);

  //Print Image
  image_same_type($img1,$im,$thmb_quality);
  image_cache_type($img1,$im,$image_path);</code></pre>
</div>
<hr />
</p>
<p>Putting it all together we arrive at the following code, we named our PHP file thumb.php since it&#8217;s primary role is to make thumbnails for the site.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code7">&lt;?php
include_once("/path/to/include/functions.phtml");
$img1 = "/images/" .  urldecode(stripslashes($_GET[img]));
if(!is_file($img1)) $img1 = "/nophoto.gif";
if(is_image($img1)){

  //Send proper image header base on mime type
  $mime=get_mime($img1);
  header("Content-type: ".$mime);

  // Set dimensions, quality &#038; variables
  $width = $_GET[w];
  $v = ($_GET[a]) ? "none" : "thumb" ;
  if($v == "thumb") {
    ($width) ? "" : $width = 100;
    ($width &gt; 150) ? $width = 150 : "" ;
    $height = $width;
    $thmb_quality = 100;
  }else{
    ($width) ? "" : $width = 300;
    ($width &gt; 588) ? $width = 588 : "" ;
    $height = $width;
    $thmb_quality = 100;
  }

  // Get orig dimensions
  list($width_orig, $height_orig, $type_orig) = getimagesize($img1);
  $src_x=0;
  $src_y=0;

  if(!$_GET[a]){
    //it's a thumbnail request, make it square from the center
    if ($width_orig &lt; $height_orig) {
      $src_y=($height_orig-$width_orig)/2;
      $height_orig=$width_orig;
    }else{
      $src_x=($width_orig-$height_orig)/2;
      $width_orig=$height_orig;
    }
	}else{
    //keep aspect ratio but keeping width set from page
    $height = ($width / $width_orig) * $height_orig;
  }

  // Resample
  $image=imagecreatefrom($img1);
  $im = imagecreatetruecolor($width, $height);
  imagecopyresampled($im, $image, 0, 0, $src_x, $src_y, $width, $height, $width_orig, $height_orig);

  //Print Image
  image_same_type($img1,$im,$thmb_quality);
  image_cache_type($img1,$im,$image_path);

}
?&gt;</code></pre>
</div>
<hr />
<p>Now we simply call the image in a generic HTML image tag.  Be sure to use the alt portion of the image tag so that if the image generation fails text still appears, not to mention this will aid in SEO.  Below we are calling an image that has a max 200pixel width/height, keeping the aspect ratio, using an image named &#8220;uwcmc.jpg&#8221; for our United Way of Cape May County client.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code8">&lt;img src="http://camwebdesign.com/layout/thumb.php?w=200&#038;a=y&#038;img=uwcmc.jpg" alt="UWCMC" /&gt;</code></pre>
</div>
<p><img src="http://camwebdesign.com/layout/thumb.php?w=200&#038;a=y&#038;img=uwcmc.jpg" alt="UWCMC" /></p>
<hr />
</p>
<p>Below we are calling an image without specifying width or aspect ration, again using an image named &#8220;uwcmc.jpg&#8221;.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code9">&lt;img src="http://camwebdesign.com/layout/thumb.php?img=uwcmc.jpg" alt="UWCMC" /&gt;</code></pre>
</div>
<p><img src="http://camwebdesign.com/layout/thumb.php?img=uwcmc.jpg" alt="UWCMC" /></p>
<hr />
</p>
<p>Here is our free <em>&#8220;No Photo&#8221;</em> image:</p>
<p><a href="http://camwebdesign.com/techniques/serve-resized-images-with-php/attachment/nophoto" rel="attachment wp-att-644"><img src="http://camwebdesign.com/~/wp-content/uploads/2010/01/nophoto.gif" alt="" title="nophoto" width="135" height="135" class="alignnone size-full wp-image-644" /></a></p>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/php-image-manipulation-functions/" rel="bookmark" title="January 9, 2010">PHP Image Manipulation Functions</a></li>
<li><a href="http://camwebdesign.com/techniques/dynamic-font-based-images/" rel="bookmark" title="January 2, 2010">Dynamic Font-Based Images</a></li>
<li><a href="http://camwebdesign.com/techniques/consistent-cross-browser-code-snippets/" rel="bookmark" title="January 6, 2010">Consistent Cross-Browser Code Snippets</a></li>
</ul>
<p><!-- Similar Posts took 18.223 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/serve-resized-images-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Image Manipulation Functions</title>
		<link>http://camwebdesign.com/techniques/php-image-manipulation-functions/</link>
		<comments>http://camwebdesign.com/techniques/php-image-manipulation-functions/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 20:14:04 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Images]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=631</guid>
		<description><![CDATA[Lets define some PHP functions we&#8217;ll be calling on for our PHP image tutorial series. We define all these functions in a file named functions.phtml and call it in our PHP code through a PHP include_once(), this way we don&#8217;t bother with the functions in our PHP image code. This first function allows us to [...]]]></description>
			<content:encoded><![CDATA[<p>Lets define some PHP functions we&#8217;ll be calling on for our <a href="/category/techniques/php/images/">PHP image tutorial series</a>.  We define all these functions in a file named functions.phtml and call it in our PHP code through<span id="more-631"></span> a <a href="http://php.net/manual/en/function.include-once.php">PHP include_once()</a>, this way we don&#8217;t bother with the functions in our PHP image code.</p>
<p>This first function allows us to determine if the requested image file is an image <em>is_image()</em>.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code1">/*Define is_image() ****************************************************************************************************/
function is_image($var1) {
	$t=strtoupper(substr($var1,-3,3));
	$t2=strtoupper(substr($var1,-4,4));
	if($t=="GIF" ||$t=="PNG" ||$t=="JPG" ||$t2=="JPEG") return true;
	return false;
}
</code></pre>
</div>
<p>This function returns the extension for any file <em>getExtension().</em></p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code2">/*Define getExtension() ****************************************************************************************************/
function getExtension($file) {
  $pos = strrpos($file, '.');
  if(!$pos) { $photosubmitted = 'Error: Unknown Filetype'; }
  $str = substr($file, $pos, strlen($file));
  return $str;
}
</code></pre>
</div>
<p>The next function allows us to call the proper <a href="http://en.wikipedia.org/wiki/MIME#Content-Type">MIME type</a>, based on image type, in the header of the PHP code <em>get_mime()</em>.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code3">/*Define get_mime() ****************************************************************************************************/
function get_mime($var1) {
	$t=strtoupper(substr($var1,-4,4));
	switch($t){
		case ".JPG":
		case ".JPEG":
			return "image/jpeg";
			break;
		case ".GIF":
			return "image/gif";
			break;
		case ".PNG":
			return "image/png";
			break;
		default: return "";
			break;
	}
}</code></pre>
</div>
<p>This fourth function allows for the use of the proper PHP image createfrom<em>xxx</em> call based on image type <em>imagecreatefrom()</em>.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code4">/*Define imagecreatefrom() ****************************************************************************************************/
function imagecreatefrom($file)  {
if(strtoupper(substr($file,-3,3))=="JPG" || strtoupper(substr($file,-4,4))=="JPEG"){
	$image=imagecreatefromjpeg($file);
}
if(strtoupper(substr($file,-3,3))=="PNG"){
	$image=imagecreatefrompng($file);
}
if(strtoupper(substr($file,-3,3))=="GIF"){
	$image=imagecreatefromgif($file);
}
return $image;
}</code></pre>
</div>
<p>Lastly this functions will output the image to the browser <em>image_same_type().</em></p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code5">/*Define image_same_type() ****************************************************************************************************/
function image_same_type($file,$image,$quality = 100) {
  if(strtoupper(substr($file,-3,3))=="JPG" || strtoupper(substr($file,-4,4))=="JPEG"){
  	imagejpeg($image,null,$quality);
  }
  if(strtoupper(substr($file,-3,3))=="PNG"){
  	imagepng($image);
  }
  if(strtoupper(substr($file,-3,3))=="GIF"){
  	imagegif($image);
  }
}</code></pre>
</div>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/serve-resized-images-with-php/" rel="bookmark" title="January 11, 2010">Serve Resized Images with PHP</a></li>
<li><a href="http://camwebdesign.com/techniques/dynamic-font-based-images/" rel="bookmark" title="January 2, 2010">Dynamic Font-Based Images</a></li>
<li><a href="http://camwebdesign.com/techniques/select-code-in-snippets-with-jquery/" rel="bookmark" title="January 7, 2010">Select code in snippets with jQuery</a></li>
</ul>
<p><!-- Similar Posts took 15.282 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/php-image-manipulation-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Select code in snippets with jQuery</title>
		<link>http://camwebdesign.com/techniques/select-code-in-snippets-with-jquery/</link>
		<comments>http://camwebdesign.com/techniques/select-code-in-snippets-with-jquery/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 02:55:13 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Techniques]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=445</guid>
		<description><![CDATA[This tutorial will show we use jQuery to create &#8220;Select Code&#8221; links in our Code Sippets. Before jumping into this jQuery technique, you may want to see our tutorial on how we construct our Consistent Cross-Browser Code Snippets. Building on our Code Snippet technique we add some HTML, namely a wrapping &#60;div&#62; and a &#60;span&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial will show we use jQuery to create &#8220;Select Code&#8221; links in our Code Sippets.</p>
<p>Before jumping into this <a href="http://jquery.com/">jQuery</a> technique, you may want to see our tutorial on how we construct our <a href="/techniques/consistent-cross-browser-code-snippets/">Consistent Cross-Browser Code Snippets</a>.</p>
<p>Building on our Code Snippet technique we add <span id="more-445"></span>some HTML, namely a wrapping &lt;div&gt; and a &lt;span&gt; that holds our Select Code link.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code class="html" id="code1">&lt;div&gt;&lt;span class="CODEselect"&gt;[&lt;a href="#"&gt;Select Code&lt;/a&gt;]&lt;/span&gt;
&lt;pre&gt;&lt;code&gt;
&lt;!-- Place Code Here --&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</code></pre>
</div>
<p>We style and hide our &lt;span&gt; with some CSS.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code class="css" id="code2">.CODEselect {
  display: none;
}

.CODEselect a:hover{
  color: #F66;
  text-decoration:underline;
}</code></pre>
</div>
<p>We add a layer of javascript and jQuery to the mix.  This javascript is attributed to david_kw from <a href="http://www.codingforums.com/archive/index.php/t-105808.html">this post</a> on codingforums.com.  The Select Code links won&#8217;t work without javascript and jQuery, so we let jQuery make the links visible with the .show() call, for those users with javascript enabled.  Then we set the .click() event of the links to fire the javascript function through a little <a href="http://docs.jquery.com/Traversing">jQuery Traversing</a> to find the correct Code Snippet area to select.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code class="html" id="code3">function CODEselect(thisID){
  var thisCODE = document.getElementById(thisID);
  if (window.getSelection) {
    var selection = window.getSelection();
    if (selection.setBaseAndExtent) { /* for Safari */
      selection.setBaseAndExtent(thisCODE, 0, thisCODE, 1);
    } else { /* for FF, Opera */
      var range = document.createRange();
      range.selectNodeContents(thisCODE);
      selection.removeAllRanges();
      selection.addRange(range);
    }
  } else { /* for IE */
    var range = document.body.createTextRange();
    range.moveToElementText(thisCODE);
    range.select();
  }
}
$(document).ready(function(){
  $('.CODEselect').show();
  $('.CODEselect a').click(function () {
      var ParentTagName = $(this).parents().get(1).tagName;
      var CodeBoxID = $(this).closest(ParentTagName).find('code').attr('id');
      CODEselect(CodeBoxID);
      return false;
    });
});</code></pre>
</div>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/php-image-manipulation-functions/" rel="bookmark" title="January 9, 2010">PHP Image Manipulation Functions</a></li>
<li><a href="http://camwebdesign.com/techniques/consistent-cross-browser-code-snippets/" rel="bookmark" title="January 6, 2010">Consistent Cross-Browser Code Snippets</a></li>
<li><a href="http://camwebdesign.com/techniques/css-reset-anyone/" rel="bookmark" title="January 5, 2010">CSS Reset anyone?</a></li>
</ul>
<p><!-- Similar Posts took 14.575 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/select-code-in-snippets-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Consistent Cross-Browser Code Snippets</title>
		<link>http://camwebdesign.com/techniques/consistent-cross-browser-code-snippets/</link>
		<comments>http://camwebdesign.com/techniques/consistent-cross-browser-code-snippets/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 04:30:02 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=491</guid>
		<description><![CDATA[How did we create and style consistent cross-browser Code Snippets with &#60;pre&#62; and &#60;code&#62; tags and some simple CSS. The problem, not all browsers treat the padding of the &#60;pre&#62; tag the same. I know what your first thought was&#8230;&#8221;It&#8217;s Internet Explorer!&#8221;, wrong actually the culprit is Firefox . In short Firefox doesn&#8217;t play well [...]]]></description>
			<content:encoded><![CDATA[<p>How did we create and style consistent cross-browser Code Snippets with &lt;pre&gt; and &lt;code&gt; tags and some simple CSS.</p>
<p>The problem, not all browsers treat the padding of the &lt;pre&gt; tag the same.  I know what your first thought was&#8230;&#8221;It&#8217;s Internet Explorer!&#8221;, wrong actually the culprit is <span id="more-491"></span>Firefox <img src='http://camwebdesign.com/~/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .  In short Firefox doesn&#8217;t play well with spaces and tabs in the &lt;pre&gt; tag.  Yes a <a href="/techniques/css-reset-anyone/">CSS reset</a> does go a long way in fixing this issue, but we wanted to further the control of our Code Snippets and do some fancy stuff to them as well.</p>
<p>Our solution&#8230;</p>
<p>We nest the &lt;pre&gt; and &lt;code&gt; tags allowing control of the margin, padding and backgrounds for each of the elements.  Our HTML, CSS, PHP, javascript or whatever code goes inside the tags.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code class="html" id="code1">&lt;pre&gt;&lt;code&gt;
&lt;!-- Place Code Here --&gt;
&lt;/code&gt;&lt;/pre&gt;</code></pre>
</div>
<p>The CSS for our &lt;pre&gt; and &lt;code&gt; tags.  We control the padding in the &lt;pre&gt; tag and the spaces and tabs in the code are properly represented in the &lt;code&gt; tag.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code class="css" id="code2">pre {
	padding: 0;
	margin: 4px 0 12px 0;
	border: 1px solid #ccc;
	line-height: 20px;
	background: url(/images/code-bg.gif) repeat-y top left #000;
	width: 586px;
	overflow: auto;
	overflow-Y: hidden;
}
pre code {
	margin: 0 8px 0 25px;
	padding: 18px 0;
	display: block;
	color: #3C3;
}</code></pre>
</div>
<p>So there you have it, simple yet effective in producing consistent results across all browsers.</p>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/css-reset-anyone/" rel="bookmark" title="January 5, 2010">CSS Reset anyone?</a></li>
<li><a href="http://camwebdesign.com/techniques/select-code-in-snippets-with-jquery/" rel="bookmark" title="January 7, 2010">Select code in snippets with jQuery</a></li>
<li><a href="http://camwebdesign.com/techniques/dynamic-font-based-images/" rel="bookmark" title="January 2, 2010">Dynamic Font-Based Images</a></li>
</ul>
<p><!-- Similar Posts took 14.814 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/consistent-cross-browser-code-snippets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Reset anyone?</title>
		<link>http://camwebdesign.com/techniques/css-reset-anyone/</link>
		<comments>http://camwebdesign.com/techniques/css-reset-anyone/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 17:43:14 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=521</guid>
		<description><![CDATA[When we create a new site&#8217;s CSS, we start with a CSS Reset to level the playing field between browsers. The problem, not all browsers treat the margin, padding, line height, font size, styling, text decoration, etc. the same, a CSS Reset helps us to &#8220;reset&#8221; these within each browser. The CSS Reset technique is [...]]]></description>
			<content:encoded><![CDATA[<p>When we create a new site&#8217;s CSS, we start with a CSS Reset to level the playing field between browsers.  The problem, not all browsers treat the margin, padding, line height, font size, styling, text decoration, etc. the same, <span id="more-521"></span>a CSS Reset helps us to &#8220;reset&#8221; these within each browser.  The <a href="http://www.google.com/search?q=CSS+Reset+technique">CSS Reset technique</a> is nothing new so we&#8217;ll let you read up on it&#8217;s history.</p>
<h3>Here is the reset that we use as our basic CSS building blocks:</h3>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code1">/* ------------------------Begin Reset------------------------ */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	outline: 0;
	font-size: 100%;
	vertical-align: baseline;
	background: transparent;
}
body {
  line-height: 1.4;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}

/* remember to define focus styles! */
:focus {
	outline: 0;
}

/* remember to highlight inserts somehow! */
ins {
	text-decoration: none;
}
del {
	text-decoration: line-through;
}

/* tables still need 'cellspacing="0"' in the markup */
table {
	border-collapse: collapse;
	border-spacing: 0;
}
/* ------------------------End Reset------------------------ */</code></pre>
</div>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/consistent-cross-browser-code-snippets/" rel="bookmark" title="January 6, 2010">Consistent Cross-Browser Code Snippets</a></li>
<li><a href="http://camwebdesign.com/techniques/select-code-in-snippets-with-jquery/" rel="bookmark" title="January 7, 2010">Select code in snippets with jQuery</a></li>
<li><a href="http://camwebdesign.com/techniques/dynamic-font-based-images/" rel="bookmark" title="January 2, 2010">Dynamic Font-Based Images</a></li>
</ul>
<p><!-- Similar Posts took 14.524 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/css-reset-anyone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What WordPress plugins do we use?</title>
		<link>http://camwebdesign.com/techniques/what-wordpress-plugins-do-we-use/</link>
		<comments>http://camwebdesign.com/techniques/what-wordpress-plugins-do-we-use/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 21:49:26 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=413</guid>
		<description><![CDATA[A list of the WordPress plugins we recommend and use. Akismet &#8211; SPAM control, this plugin is the ultimate in controlling unwanted spam in your posts and pages. Akismet checks your comments against the Akismet web service to see if they look like spam or not. You need a WordPress.com API key to use it. [...]]]></description>
			<content:encoded><![CDATA[<h3>A list of the WordPress plugins we recommend and use.</h3>
<p><span id="more-413"></span></p>
<ol>
<li><strong>Akismet</strong> &#8211; SPAM control, this plugin is the ultimate in controlling unwanted spam in your posts and pages.<br />
<blockquote><p>Akismet checks your comments against the Akismet web service to see if they look like spam or not. You need a WordPress.com API key to use it. You can review the spam it catches under &#8220;Comments.&#8221; To show off your Akismet stats just put  in your template.</p></blockquote>
<ul>
<li>By <a href="http://ma.tt/">Matt Mullenweg</a> | <a href="http://akismet.com/">Visit plugin site</a></li>
</ul>
</li>
<li><strong>All in One SEO Pack</strong> &#8211; Provides full SEO customization for your posts and pages, including title tags, descriptions, meta tags, etc.<br />
<blockquote><p>Out-of-the-box SEO for your WordPress blog.</p></blockquote>
<ul>
<li>By <a title="Visit author homepage" href="http://michaeltorbert.com">Michael Torbert</a> | <a title="Visit plugin site" href="http://semperfiwebdesign.com">Visit plugin site</a></li>
</ul>
</li>
<li><strong>Contact Form 7</strong> &#8211; The author reports that this is just another contact form plugin, <em>understatement if ever there was one</em>.  This provides the easiest form creation and management we&#8217;ve ever used on any platform.<br />
<blockquote><p>Just another contact form plugin. Simple but flexible.</p></blockquote>
<ul>
<li>By <a title="Visit author homepage" href="http://ideasilo.wordpress.com/">Takayuki Miyoshi</a> | <a title="Visit plugin site" href="http://contactform7.com/">Visit plugin site</a></li>
</ul>
</li>
<li><strong>Custom Field Template</strong> &#8211; This extends the functionality of the already easy to use WordPress Custom Fields for pages and posts.<br />
<blockquote><p>This plugin adds the default custom fields on the Write Post/Page.</p></blockquote>
<ul>
<li>By <a title="Visit author homepage" href="http://wpgogo.com/">Hiroaki Miyashita</a> | <a title="Visit plugin site" href="http://wpgogo.com/development/custom-field-template.html">Visit plugin site</a></li>
</ul>
</li>
<li><strong>Google Analyticator</strong> &#8211; Allows for easy installation of Google&#8217;s Analytics code into your blog, including smart control so you don&#8217;t track admin activity etc.<br />
<blockquote><p>Adds the necessary JavaScript code to enable Google&#8217;s Analytics. After enabling this plugin visit the settings page and enter your Google Analytics&#8217; UID and enable logging.</p></blockquote>
<ul>
<li>By <a title="Visit author homepage" href="http://ronaldheft.com/">Ronald Heft</a> | <a title="Visit plugin site" href="http://ronaldheft.com/code/analyticator/">Visit plugin site</a></li>
</ul>
</li>
<li><strong>Google XML Sitemaps</strong> &#8211; Provides easy to maintain and control XML sitemaps for your blog / website, a must have for SEO and search engine ranking.<br />
<blockquote><p>This plugin will generate a special XML sitemap which will help search engines like Google, Yahoo, Bing and Ask.com to better index your blog.</p></blockquote>
<ul>
<li>By <a title="Visit author homepage" href="http://www.arnebrachhold.de/">Arne Brachhold</a> | <a title="Visit plugin site" href="http://www.arnebrachhold.de/redir/sitemap-home/">Visit plugin site</a></li>
</ul>
</li>
<li><strong>Most Popular Posts</strong> &#8211; This is great for boosting interest in your content, especially what&#8217;s popular.<br />
<blockquote><p>Display a link to the most popular posts on your blog according to the number of comments.</p></blockquote>
<ul>
<li>By <a title="Visit author homepage" href="http://www.wesg.ca">Wes Goodhoofd</a> | <a title="Visit plugin site" href="http://www.wesg.ca/2008/08/wordpress-widget-most-popular/">Visit plugin site</a></li>
</ul>
</li>
<li><strong>Search Everything</strong> &#8211; Adds extended search capability and functionality to WordPress&#8217; already great search abilities.<br />
<blockquote><p>Adds search functionality without modifying any template pages: Activate, Configure and Search. Options Include: search highlight, search pages, excerpts, attachments, drafts, comments, tags and custom fields (metadata). Also offers the ability to exclude specific pages and posts. Does not search password-protected content.</p></blockquote>
<ul>
<li>By <a title="Visit author homepage" href="http://sproutventure.com/">Dan Cameron of Sprout Venture</a> | <a title="Visit plugin site" href="http://dancameron.org/wordpress/wordpress-plugins/search-everything-wordpress-plugin">Visit plugin site</a></li>
</ul>
</li>
<li><strong>Similar Posts</strong> &#8211; Provides a configurable list of smartly chosen posts and/or pages to the bottom of your post to generate more interest in your content.<br />
<blockquote><p>Displays a highly configurable list of related posts. Similarity can be based on any combination of word usage in the content, title, or tags. Don&#8217;t be disturbed if it takes a few moments to complete the installation &#8212; the plugin is indexing your posts. Instructions and help online. Requires the latest version of the Post-Plugin Library to be installed.</p></blockquote>
<ul>
<li>By <a href="http://rmarsh.com/" title="Visit author homepage">Rob Marsh, SJ</a> | <a href="http://rmarsh.com/plugins/similar-posts/" title="Visit plugin site">Visit plugin site</a></li>
</ul>
</li>
<li><strong>WordPress Database Backup</strong> &#8211; Creates backups of your WordPress blog or website, what would you do if your server crashed!?<br />
<blockquote><p>On-demand backup of your WordPress database.</p></blockquote>
<ul>
<li>By <a title="Visit author homepage" href="http://www.ilfilosofo.com/">Austin Matzko</a> | <a title="Visit plugin site" href="http://www.ilfilosofo.com/blog/wp-db-backup">Visit plugin site</a></li>
</ul>
</li>
</ol>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/consistent-cross-browser-code-snippets/" rel="bookmark" title="January 6, 2010">Consistent Cross-Browser Code Snippets</a></li>
<li><a href="http://camwebdesign.com/techniques/dynamic-font-based-images/" rel="bookmark" title="January 2, 2010">Dynamic Font-Based Images</a></li>
<li><a href="http://camwebdesign.com/techniques/css-reset-anyone/" rel="bookmark" title="January 5, 2010">CSS Reset anyone?</a></li>
</ul>
<p><!-- Similar Posts took 14.969 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/what-wordpress-plugins-do-we-use/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dynamic Font-Based Images</title>
		<link>http://camwebdesign.com/techniques/dynamic-font-based-images/</link>
		<comments>http://camwebdesign.com/techniques/dynamic-font-based-images/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 19:26:12 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=319</guid>
		<description><![CDATA[We wanted to create stylish text images for our page and post headings, but we didn&#8217;t want to create them in advance, we wanted them on the fly. This is a tutorial on how we accomplished this using PHP. Let&#8217;s get to it! You&#8217;ll need PHP (PHP: Hypertext Preprocessor) the open source dynamic language the [...]]]></description>
			<content:encoded><![CDATA[<p>We wanted to create stylish text images for our page and post headings, but we didn&#8217;t want to create them in advance, we wanted them on the fly.  This is a tutorial on how we accomplished this using PHP.</p>
<p><span id="more-319"></span></p>
<p>Let&#8217;s get to it!</p>
<p>You&#8217;ll need PHP (PHP: Hypertext Preprocessor) the open source dynamic language the code in our example is written.  We won&#8217;t elaborate, the internet is full of <a href="http://www.google.com/search?q=php">information reguarding PHP</a>.</p>
<p>You&#8217;ll need the GD library, an open source code library for the dynamic creation of images by programmers, <em>typically</em> installed along with PHP.  <a href="http://www.google.com/search?q=gd+library">Information on the GD library</a> also abounds on the internet.  Check with your host if you are unsure if you have it installed.</p>
<p>A windows font of your choice, for our site we chose a nice font called <a href="http://www.google.com/search?q=agency+font">Agency</a>.  Upload a copy of this font onto your server wherever you like, just be sure to change the path/to/the/font to your font&#8217;s path in the PHP code.</p>
<p>Determine the colors of your image (in hexidecimal form) for the following:  text, background &amp; text-shadow (if wanted).   Hexadecimal uses three sets of numbers to represent the Red, Green, and Blue values for a particular color.  We chose a blue text, with a white background and a light grey shadow.  There are quite a few free color picking programs and <a href="http://www.visibone.com/">websites</a> available, we use <a href="http://www.iconico.com/colorpic/">ColorPic by iconico.com</a> for all our color needs.  It&#8217;s freeware and does not include any other unwanted software included in the download package.</p>
<p>Save this PHP code and name the file font.php:</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code class="php" id="code1">&lt;?php
// Get the text to draw
$text = ($_GET['text']) ? $_GET['text'] : 'oops...missing text' ;  //set default text if missing

// Path to the font
$font = '/path/to/the/font/AGENCYR.TTF';

// Get display font size
$size = ($_GET['size']) ? $_GET['size'] : 18.5 ;  //set default if empty

// Get display width
$width = ($_GET['w']) ? $_GET['w'] : 100 ;  //set default if empty

// Get display height
$height = ($_GET['h']) ? $_GET['h'] : 40 ;  //set default if empty

// Create the image
$im = imagecreatetruecolor($width, $height);

// Choose text color
$color = ($_GET[color]) ? $_GET[color] : "black" ;  //Image color
switch($color) {
  case "black" : $use_color = imagecolorallocate($im, 0, 0, 0); break;
  case "orange" : $use_color = imagecolorallocate($im, 255, 159, 64); break;
  case "blue" : $use_color = imagecolorallocate($im, 53, 50, 111); break;
  case "white" : $use_color = imagecolorallocate($im, 255, 255, 255); break;
}

// Get the top offset
$offset = ($_GET['offset']) ? $_GET['offset'] : 30 ;  //set default if empty

// Create the image background
$bgcolor = ($_GET['bgcolor'] == 'white') ?	imagecolorallocate($im, 255, 255, 255) : imagecolorallocate($im, 0, 0, 0) ;  //set default if empty
imagefilledrectangle($im, 0, 0, $width, $height, $bgcolor);

// Make the background-color transparent
imagecolortransparent($im, $bgcolor);

// Add some shadow to the text if requested
if($_GET['shadow']){
  $shadoffset = $offset + 2;
  $shadow = imagecolorallocate($im, 220, 220, 220);
  imagettftext($im, $size, 0, 1, $shadoffset, $shadow, $font, $text);
}

// Add the text in the color chosen
imagettftext($im, $size, 0, 0, $offset, $use_color, $font, $text);	

// Set the content-type and print the image
header('Content-type: image/gif');
imagegif($im);
?&gt;</code></pre>
</div>
<p>Simply call the dynamic font based image in a generic HTML image tag. Be sure to use the <em>alt</em> portion of the image tag so that if the image generation fails text still appears, not to mention this will aid in SEO.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code class="xhtml" id="code2">&lt;img src="font.php?size=18&amp;w=400&amp;h=34&amp;shadow=y&amp;color=blue&amp;bgcolor=white&amp;text=My+Dynamic+Font+Based+Image" alt="My Dynamic Font Based Image" /&gt;</code></pre>
</div>
<p>Some Examples:</p>
<ul>
<li><img src="/layout/font.php?w=400&amp;shadow=y&amp;color=blue&amp;bgcolor=white&amp;text=Blue+with+a+shadow+on+a+white+background" alt="Blue with a shadow on a white background" /></li>
<li><img src="/layout/font.php?w=400&amp;shadow=y&amp;color=black&amp;bgcolor=white&amp;text=Black+with+a+shadow+on+a+white+background" alt="Black without a shadow on a white background" /></li>
<li><img src="/layout/font.php?w=400&amp;shadow=y&amp;color=orange&amp;bgcolor=white&amp;text=Orange+with+a+shadow+on+a+white+background" alt="Orange with a shadow on a white background" /></li>
<li><img src="/layout/font.php?w=400&amp;color=blue&amp;bgcolor=white&amp;text=Blue+without+a+shadow+on+a+white+background" alt="Blue without a shadow on a white background" /></li>
<li><img src="/layout/font.php?w=400&amp;color=black&amp;bgcolor=white&amp;text=Black+without+a+shadow+on+a+white+background" alt="Black without a shadow on a white background" /></li>
<li><img src="/layout/font.php?w=400&amp;color=orange&amp;bgcolor=white&amp;text=Orange+without+a+shadow+on+a+white+background" alt="Orange without a shadow on a white background" /></li>
</ul>
<p>How do <em>we</em> dynamically use this technique in conjunction with our site&#8217;s code?  The text for our images come from the &lt;?php the_title(); ?&gt; call from WordPress.  Hence, whatever text is set for the page or post title will be displayed in image form.  No need to create static text images for our pages and posts.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code class="xhtml" id="code3">&lt;img src="font.php?size=20&amp;w=500&amp;shadow=y&amp;color=blue&amp;bgcolor=white&amp;text=< ?php the_title(); ?>" alt="< ?php the_title(); ?>" /&gt;</code></pre>
</div>
<p>Room for improvement?  Why yes there is always improvements that can be made to the code, some or our thoughts include:</p>
<ul>
<li>Create an on the fly HEX color conversion based on the $color and $bgcolor variables</li>
<li>Determine the top offset based on the image height and the font size, allowing all text to align in the center of the image.</li>
<li>Auto width based on number of text characters.  This could be tricky and may require a monospacing (fixed-width) font.</li>
</ul>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/serve-resized-images-with-php/" rel="bookmark" title="January 11, 2010">Serve Resized Images with PHP</a></li>
<li><a href="http://camwebdesign.com/techniques/php-image-manipulation-functions/" rel="bookmark" title="January 9, 2010">PHP Image Manipulation Functions</a></li>
<li><a href="http://camwebdesign.com/techniques/css-reset-anyone/" rel="bookmark" title="January 5, 2010">CSS Reset anyone?</a></li>
</ul>
<p><!-- Similar Posts took 16.210 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/dynamic-font-based-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello World! &#8211; PHP Style</title>
		<link>http://camwebdesign.com/techniques/hello-world-php-style/</link>
		<comments>http://camwebdesign.com/techniques/hello-world-php-style/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 19:32:45 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=563</guid>
		<description><![CDATA[What would a list of How-To-Techniques be on a WordPress site without a &#8220;Hello World!&#8221; example in PHP? We think lacking at best, so let&#8217;s play with some simple php code in the examples below. [Select Code] &#60;?php print "Hello, World!"; ?&#62; Alternatively we could write it this way: [Select Code] &#60;?php echo "Hello, World!"; [...]]]></description>
			<content:encoded><![CDATA[<p>What would a list of How-To-Techniques be on a WordPress site without a &#8220;Hello World!&#8221; example in PHP?</p>
<p>We think lacking at best, so let&#8217;s play with some simple php code <span id="more-563"></span>in the examples below.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code1" class="php">&lt;?php
    print "Hello, World!";
?&gt;</code></pre>
</div>
<p>Alternatively we could write it this way:</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code2" class="php">&lt;?php
    echo "Hello, World!";
?&gt;</code></pre>
</div>
<p>Both Yield <em>Hello, World!</em></p>
<p>If you don&#8217;t understand the significance of the PHP &#8220;Hello World!&#8221; example, then you must not know the advantages <a href="http://en.wikipedia.org/wiki/Server-side_scripting">server-side programming</a> languages provide.  The use of HTML to print Hello World! is simple, but having it done dynamically on the fly is quite another thing.  Server-side programming has changed the face of how the web works, and PHP has truly fueled the open source revolution.</p>
<p>Now we&#8217;ll move on to the question, &#8220;What is the difference between the PHP print() and echo() language constructs&#8221;?</p>
<p>The answer, not much &#8211; BUT &#8211; echo is faster than print.  Print returns an int value and echo returns no value.  Example: $value = print &#8220;Hello World&#8221;; here $value will be set to 1.  So print can be used in complex expression where you can&#8217;t use echo.</p>
<p>We can however, use echo is some creative short hand statements, like this one.</p>
<div><span class="CODEselect">[<a href="#">Select Code</a>]</span></p>
<pre><code id="code3" class="php">&lt;?php
    echo($text == 'hi') ? "Hello World!" : "Goodbye World!" ;
?&gt;</code></pre>
</div>
<p>Suppose the variable $text was set to &#8220;hi&#8221;, this would print <em>Hello World!</em>.  If $text was set to anything else then it will print <em>Goodbye World!</em>.</p>
<p>Post your thoughts below&#8230;</p>
<hr /><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://camwebdesign.com/techniques/dynamic-font-based-images/" rel="bookmark" title="January 2, 2010">Dynamic Font-Based Images</a></li>
<li><a href="http://camwebdesign.com/techniques/serve-resized-images-with-php/" rel="bookmark" title="January 11, 2010">Serve Resized Images with PHP</a></li>
<li><a href="http://camwebdesign.com/techniques/consistent-cross-browser-code-snippets/" rel="bookmark" title="January 6, 2010">Consistent Cross-Browser Code Snippets</a></li>
</ul>
<p><!-- Similar Posts took 15.130 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/hello-world-php-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
