<?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>CAM Web Design &#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, 14 May 2012 04:20:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Detect iPad with javascript</title>
		<link>http://camwebdesign.com/techniques/detect-ipad-with-javascript/</link>
		<comments>http://camwebdesign.com/techniques/detect-ipad-with-javascript/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 06:50:34 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[iPad]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1799</guid>
		<description><![CDATA[We created and maintain an intranet website for an electric utility (of whom I work for &#8211; they pay my bills).  The site is accessed by personnel with iPads, and it contains some flash content (AccuWeather Accunet and Open Flash Chart). As you may already know flash is not supported by Apple&#8217;s Safari browser. We <a href="http://camwebdesign.com/techniques/detect-ipad-with-javascript/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>We created and maintain an <a href="/portfolio/ace-system-operations/">intranet website for an electric utility</a> (of whom I work for &#8211; they pay my bills).  The site is accessed by personnel with iPads, and it contains some flash content (<a href="http://www.accuweather.com/accunet/index.asp">AccuWeather Accunet</a> and <a href="http://teethgrinder.co.uk/open-flash-chart-2/">Open Flash Chart</a>).  As you may already know flash is not <span id="more-1799"></span>supported by Apple&#8217;s Safari browser.  We wanted to detect if the user was accessing the site with an iPad.  If they are we use <a href="http://jquery.com/">jQuery</a> to alter the HTML code, removing the flash content and display a message &#8220;Some content not available, your device does not support Flash&#8221;.  Of course we could replace the HTML with alternative content rather than the pat message, but for our needs this is what we&#8217;ve done.</p>
<p>First we use one line of javascript to detect if the user agent is an iPad.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">var isiPad <span style="color: #339933;">=</span> navigator.<span style="color: #006633;">userAgent</span>.<span style="color: #006633;">match</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">/</span>iPad<span style="color: #339933;">/</span>i<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then we use jQuery to replace the HTML, where necessary, with our message using the <a href="http://api.jquery.com/html"><code>html()</code></a> function.  Exampled below, we&#8217;re replacing the HTML if a <code>&lt;div&gt;</code> with an id of AccuWeather, with our message.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isiPad <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#AccuWeather&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">html</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Some content not available, your device does not support Flash'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Our stance on Adobe Flash, we fully support the new HTML5 and CSS3 standards, and are not fans of Flash.  Nor are we fans of Adobe&#8217;s new product <a href="http://labs.adobe.com/technologies/edge/">Edge</a>.  We prefer to hand code, it&#8217;s usually much lighter and more understandable than code from a WYSIWYG.</p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/detect-ipad-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplify the WordPress Admin sidebar navigation</title>
		<link>http://camwebdesign.com/techniques/simplify-the-wordpress-admin-sidebar-navigation/</link>
		<comments>http://camwebdesign.com/techniques/simplify-the-wordpress-admin-sidebar-navigation/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 07:35:49 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1648</guid>
		<description><![CDATA[Want to remove some of the root WordPress Admin sidebar navigation? We have a client that was mainly interested in writing pages and managing media for those pages, they were not going to use Posts, Comments or Links in the administration area. We set them up as Editors on a WordPress Multisite installation, below is <a href="http://camwebdesign.com/techniques/simplify-the-wordpress-admin-sidebar-navigation/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>Want to remove some of the root WordPress Admin sidebar navigation?  We have a client that was mainly interested in writing pages and managing media for those pages, they were not going to use Posts, Comments or Links in the administration area.  We set them up as <a href="http://codex.wordpress.org/Roles_and_Capabilities#Editor">Editors</a> on a <a href="/techniques/wordpress/wordpress-multisite-on-hostgator-reseller/">WordPress Multisite</a> installation, below is how we removed those items from appearing in the navigation.</p>
<p>First we define a new function, we used <code>remove_admin_menu_items()</code>.<span id="more-1648"></span>  In this function we define an array <code>$remove_menu_items</code> that contains the menu items we wish to remove from the admin navigation.  The function is designed to step through WordPress&#8217; multidimensional array <code>$menu</code>, getting each <code>$menu</code> item name by use of the PHP function <a href="http://php.net/manual/en/function.explode.php"><code>explode()</code></a>.  It then checks if that <code>$menu</code> item name is in our <code>$remove_menu_items</code> array using the PHP function <a href="http://php.net/manual/en/function.in-array.php"><code>in_array()</code></a>.  If the <code>$menu</code> item name does appear, then that item is removed from the multidimensional array <code>$menu</code>, by use the PHP function <a href="http://php.net/manual/en/function.unset.php"><code>unset()</code></a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> remove_admin_menu_items<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$remove_menu_items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Links'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comments'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$menu</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">end</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$item</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;">$menu</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">key</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</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;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">NULL</span>?<span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$remove_menu_items</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">key</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We then initiate the <code>remove_admin_menu_items()</code> function using the <a href="http://codex.wordpress.org/Function_Reference/add_action"><code>add_action()</code></a> WordPress function as shown below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_menu'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remove_admin_menu_items'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Putting it all together yields the following code to be placed in your theme&#8217;s functions.php file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* Clean up the admin sidebar navigation *************************************************/</span>
<span style="color: #000000; font-weight: bold;">function</span> remove_admin_menu_items<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$remove_menu_items</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Links'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Comments'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$menu</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">end</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$item</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;">$menu</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">key</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</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;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">NULL</span>?<span style="color: #000088;">$item</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$remove_menu_items</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">key</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$menu</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_menu'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remove_admin_menu_items'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>All you&#8217;ll need to change is the array of items to remove in the <cdoe>$remove_menu_items</code> array.  In our example we removed: Posts, Links and Comments.  Other root level WordPress admin sidebar navigation items available for removal are Media, Pages, Appearance, Plugins, Users, Tools and Settings.</p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/simplify-the-wordpress-admin-sidebar-navigation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Redefine Twenty Ten header image width and height</title>
		<link>http://camwebdesign.com/techniques/redefine-twenty-ten-header-image-width-and-height/</link>
		<comments>http://camwebdesign.com/techniques/redefine-twenty-ten-header-image-width-and-height/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 05:59:24 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Twenty Ten]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1629</guid>
		<description><![CDATA[How do you go about redefining the WordPress Twenty Ten header image width and height? We recently used the Twenty Ten theme as a Parent Theme for a multi-site installation for a client. We wanted to retain the use of the custom header image, but wanted a different image width and height. It is accomplished <a href="http://camwebdesign.com/techniques/redefine-twenty-ten-header-image-width-and-height/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>How do you go about redefining the WordPress Twenty Ten header image width and height?  We recently used the Twenty Ten theme as a Parent Theme for a multi-site installation for a client. We wanted to retain the use of the custom header image, but wanted a different image width and height.  It is accomplished with a few lines of code in the Twenty Ten <a href="http://codex.wordpress.org/Child_Themes">child theme</a>’s functions.php file.  <a href="http://camwebdesign.com/?p=1593">You are using a child theme, aren’t you?</a></p>
<p>The answer to this one is just so simple<span id="more-1629"></span> it needs nearly no explanation.  Simply redefine two varaibles <code>HEADER_IMAGE_WIDTH</code>, and <code>HEADER_IMAGE_HEIGHT</code>.  For our purposes we needed <code>800x182</code> to fit into the template.  Below is the code to be placed in your theme&#8217;s functions.php file simply add the image size to suite your needs:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* Redefine the header image width and height ********************************************/</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'HEADER_IMAGE_WIDTH'</span><span style="color: #339933;">,</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'twentyten_header_image_width'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">800</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'HEADER_IMAGE_HEIGHT'</span><span style="color: #339933;">,</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'twentyten_header_image_height'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">182</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>UPDATE: This also works for the WordPress Twenty Eleven theme.</p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/redefine-twenty-ten-header-image-width-and-height/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Remove default WordPress Twenty Ten header images</title>
		<link>http://camwebdesign.com/techniques/remove-default-wordpresstwenty-ten-header-images/</link>
		<comments>http://camwebdesign.com/techniques/remove-default-wordpresstwenty-ten-header-images/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 05:44:30 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Twenty Ten]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1622</guid>
		<description><![CDATA[How do you remove those pesky default header images included in the Twenty Ten WordPress theme. We recently used the Twenty Ten theme as a Parent Theme for a multi-site installation for a client. We wanted to retain the use of the custom header image, but didn&#8217;t want the default header images to be visible. <a href="http://camwebdesign.com/techniques/remove-default-wordpresstwenty-ten-header-images/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>How do you remove those pesky default header images included in the Twenty Ten WordPress theme.  We recently used the Twenty Ten theme as a Parent Theme for a multi-site installation for a client.  We wanted to retain the use of the custom header image, but didn&#8217;t want the default header images to be visible.  It is accomplished with a few lines of code in the Twenty Ten <a href="http://codex.wordpress.org/Child_Themes">child theme</a>’s functions.php file.  <a href="http://camwebdesign.com/?p=1593">You are using a child theme, aren’t you?</a></p>
<p>First define a new function, we used <code>remove_twenty_ten_headers()</code>.<span id="more-1622"></span>  We use the <a href="http://codex.wordpress.org/Function_Reference/unregister_default_headers"><code>unregister_default_headers()</code></a> WordPress function to un-register as many as we want.  In our example we removed them all.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> remove_twenty_ten_headers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    unregister_default_headers<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'berries'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'cherryblossom'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'concave'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'fern'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'forestfloor'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'inkwell'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'path'</span> <span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'sunset'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We then initiate the new <code>remove_twenty_ten_headers()</code> function using the <a href="http://codex.wordpress.org/Function_Reference/add_action"><code>add_action()</code></a> WordPress function as shown below.  We make sure to call our function after the theme setup has run to be sure our function is called after <a href="http://codex.wordpress.org/Function_Reference/register_default_headers"><code>register_default_headers()</code></a> has already added the headers we want to remove.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'after_setup_theme'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remove_twenty_ten_headers'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">11</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Putting it all together yields the following code to be placed in your theme&#8217;s functions.php file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* Remove default twenty ten images ***********************************************/</span>
<span style="color: #000000; font-weight: bold;">function</span> remove_twenty_ten_headers<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    unregister_default_headers<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'berries'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'cherryblossom'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'concave'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'fern'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'forestfloor'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'inkwell'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'path'</span> <span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'sunset'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'after_setup_theme'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remove_twenty_ten_headers'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">11</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>How simple is that!</p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/remove-default-wordpresstwenty-ten-header-images/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Create a WordPress Child Theme, allow updates</title>
		<link>http://camwebdesign.com/techniques/create-a-wordpress-child-theme-allow-updates/</link>
		<comments>http://camwebdesign.com/techniques/create-a-wordpress-child-theme-allow-updates/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 05:04:29 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Twenty Ten]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1593</guid>
		<description><![CDATA[So you&#8217;ve got a decent handle on how WordPress works, you may have even edited a few themes directly, but now those themes have updates, what do you do (better yet what should you have done)? You need to explore Child Themes. How do you actually create a child theme in WordPress you may ask? <a href="http://camwebdesign.com/techniques/create-a-wordpress-child-theme-allow-updates/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;ve got a decent handle on how WordPress works, you may have even edited a few themes directly, but now those themes have updates, what do you do (better yet what should you have done)?  You need to explore Child Themes.  How do you actually create a child theme in WordPress you may ask?  We will quickly explore what you need<span id="more-1593"></span> to create a Child Theme using the WordPress Twenty Ten theme as an example.  Then we will detail how to allow those updates to occur without loosing your customizations to any theme.</p>
<p>What do you need to create your Twenty Ten Child Theme (the basics):</p>
<ol>
<li>Twenty Ten installed in the <code>wp-content/themes/</code> folder.</li>
<li>A folder with your Child&#8217;s Theme name in the <code>wp-content/themes/</code> folder.</li>
<li>A <code>style.css</code> CSS file in the folder of your Child&#8217;s Theme.</li>
</ol>
<p>What could be additionally required:</p>
<ol>
<li>A <code>functions.php</code> file in the folder of your Child&#8217;s Theme, to modify or add functions.</li>
<li>Any additional file(s) you wish to modify from the Parent Theme: <code>header.php</code>, <code>footer.php</code>, etc.</li>
</ol>
<p>The magic happens in the CSS file of your Child Theme, namely the &#8220;Template&#8221; declaration line.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
Template: twentyten
*/</span></pre></td></tr></table></div>

<p>Adding this &#8220;Template&#8221; declaration in the CSS file tells WordPress to look for and run the Twenty Ten theme as a parent to this theme.  The Child Theme will then get all the functionality of the Parent, but you&#8217;ll be able to modify the files without worry of being overwritten when the Parent Theme updates.  Putting the &#8220;Template&#8221; declaration together with some of the common WordPress Theme declarations yeilds the code below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
Theme Name: Your New Child Theme Name
Theme URI: http://your_web_site.com/
Description: Custom theme for your_web_site.com.
Author: You
Author URI: http://your_web_site.com/
Version: 0.1.0
Tags: all, the, tags, describing, your, new, theme
Template: twentyten
*/</span></pre></td></tr></table></div>

<p>So what should you do if you have modified a theme and updates to the theme are available?  Turn your current theme into a Child Theme.  For the sake of clarity, let&#8217;s assume you&#8217;ve modified the Twenty Ten theme.  Follow these steps below (replacing your current theme&#8217;s name where we&#8217;ve used Twenty Ten):</p>
<ol>
<li>Rename your current &#8220;Twenty Ten&#8221; theme in the <code>style.css</code> CSS file by modifying the &#8220;Theme Name&#8221; line.</li>
<li>Rename the &#8220;twentyten&#8221; folder your current theme is in.</li>
<li>Download a clean up-to-date copy of the Twenty Ten theme into your <code>wp-content/themes/</code> folder, don&#8217;t activate it.</li>
<li>Modify your newly renamed theme&#8217;s <code>style.css</code> CSS file by adding the &#8220;Template: twentyten&#8221; declaration.</li>
<li>Remove all the files you did not modify from your new Child Theme&#8217;s folder (you can usually tell by file-date-time if your using an ftp client).  Leave the original Twenty Ten ones alone from now on!</li>
<li>Re-activate your newly created Child Theme.</li>
</ol>
<p>Now you can happily let the Twenty Ten theme update eternally without loosing your modifications.</p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/create-a-wordpress-child-theme-allow-updates/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Remove Widgets from Twenty Ten WordPress theme</title>
		<link>http://camwebdesign.com/techniques/remove-widgets-from-twenty-ten-wordpress-theme/</link>
		<comments>http://camwebdesign.com/techniques/remove-widgets-from-twenty-ten-wordpress-theme/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 03:50:37 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Twenty Ten]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1585</guid>
		<description><![CDATA[So you want to remove some of the &#8220;stock&#8221; Widget Areas from the WordPress Twenty Ten theme, how do you go about doing this? We will be using the WordPress function unregister_sidebar(). It is accomplished with a few lines of code in your Twenty Ten child theme’s functions.php file. You are using a child theme, <a href="http://camwebdesign.com/techniques/remove-widgets-from-twenty-ten-wordpress-theme/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>So you want to remove some of the &#8220;stock&#8221; Widget Areas from the WordPress Twenty Ten theme, how do you go about doing this?  We will be using the WordPress function <a href="http://codex.wordpress.org/Function_Reference/unregister_sidebar"><code>unregister_sidebar()</code></a>. It is accomplished with a few lines of code in your Twenty Ten <a href="http://codex.wordpress.org/Child_Themes">child theme</a>’s functions.php file.  <a href="http://camwebdesign.com/?p=1593">You are using a child theme, aren’t you?</a></p>
<p>First define a new function, we used <code>remove_widget_area()</code>.  <span id="more-1585"></span>Inside this function we un-register the desired &#8220;stock&#8221; Widget Areas we don&#8217;t want or need.  Twenty Ten comes with the following &#8220;stock&#8221; Widget Areas: primary-widget-area, secondary-widget-area, first-footer-widget-area, second-footer-widget-area, third-footer-widget-area and fourth-footer-widget-area.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> remove_widget_area<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	unregister_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'secondary-widget-area'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	unregister_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'first-footer-widget-area'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	unregister_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'second-footer-widget-area'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	unregister_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'third-footer-widget-area'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	unregister_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'fourth-footer-widget-area'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We then initiate the new <code>remove_widget_area()</code> function using the <a href="http://codex.wordpress.org/Function_Reference/add_action"><code>add_action()</code></a> WordPress function as shown below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'admin_init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remove_widget_area'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Putting it all together yields the following code to be placed in your theme&#8217;s functions.php file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* Remove &quot;extra&quot; Twenty Ten Widget Areas *******************************************************/</span>
<span style="color: #000000; font-weight: bold;">function</span> remove_widget_area<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	unregister_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'secondary-widget-area'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	unregister_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'first-footer-widget-area'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	unregister_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'second-footer-widget-area'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	unregister_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'third-footer-widget-area'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	unregister_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'fourth-footer-widget-area'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'admin_init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remove_widget_area'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>It&#8217;s just that simple, now it&#8217;s your turn!</p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/remove-widgets-from-twenty-ten-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>WordPress Multisite on Hostgator (Reseller)</title>
		<link>http://camwebdesign.com/techniques/wordpress/wordpress-multisite-on-hostgator-reseller/</link>
		<comments>http://camwebdesign.com/techniques/wordpress/wordpress-multisite-on-hostgator-reseller/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 15:46:02 +0000</pubDate>
		<dc:creator>Troy</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1553</guid>
		<description><![CDATA[Utilizing the multisite capabilities of WordPress 3.0+ can have many applications and advantages. It substantially reduces the disk space required for multiple websites running WP. It also simplifies the process of keeping your WordPress installation, themes and plugins up-to-date. As we have installed a couple of these on our HostGator reseller account, we can safely <a href="http://camwebdesign.com/techniques/wordpress/wordpress-multisite-on-hostgator-reseller/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>Utilizing the multisite capabilities of WordPress 3.0+ can have many applications and advantages. It substantially reduces the disk space required for multiple websites running WP.  It also simplifies the process of keeping your WordPress installation, themes and plugins up-to-date.</p>
<p>As we have installed a couple of these on our HostGator reseller account, we can safely say that the process is relatively painless.  But it helps to know in advance which steps are relevant to the HostGator environment.<span id="more-1553"></span></p>
<p>The <a href="http://codex.wordpress.org/Create_A_Network">WordPress multisite installation instructions</a> are as thorough as possible, given the different environments they must account for.</p>
<p>The only step that needs clarification in that procedure is step 2:</p>
<blockquote>
<h3>Step 2: Setting Wildcard Subdomains</h3>
<p>(If this is a Sub-directories Install, skip this step.)<br />
Sub-domain sites work with the use of wildcard subdomains. This is a two-step process:<br />
Apache must be configured to accept wildcards.<br />
Open up the httpd.conf file or the include file containing the VHOST entry for your web account.<br />
Add this line:<br />
ServerAlias *.example.com<br />
In the DNS records on your server, add a wildcard subdomain that points to the main installation. It should look like:<br />
A *.example.com<br />
[...snip...]</p></blockquote>
<p>For the first step in the &#8220;two-step process&#8221; described above, HostGator (reseller) seems to be set up to allow wildcard subdomains already (Good thing, too, since we don&#8217;t have access to httpd.conf or the VHOST file.)<br />
So on the &#8220;step two&#8221;&#8230;</p>
<p>For this step, you will need to access cPanel.<br />
In the &#8220;Domains&#8221; section, select &#8220;Subdomains&#8221;. Here you will want to create a wildcard subdomain (by creating the &#8216;*&#8217; subdomain.) A properly set up subdomain will look (something) like:<br />
<a href="http://camwebdesign.com/~/wp-content/uploads/2011/01/subdomain-cpanel.jpg"><img class="alignright size-large wp-image-1559" title="subdomain-cpanel" src="http://camwebdesign.com/~/wp-content/uploads/2011/01/subdomain-cpanel-600x51.jpg" alt="" width="600" height="51" /></a></p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/wordpress/wordpress-multisite-on-hostgator-reseller/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Do not let your domain name expire!</title>
		<link>http://camwebdesign.com/techniques/do-not-let-your-domain-name-expire/</link>
		<comments>http://camwebdesign.com/techniques/do-not-let-your-domain-name-expire/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 18:25:53 +0000</pubDate>
		<dc:creator>Troy</dc:creator>
				<category><![CDATA[Domain Management]]></category>
		<category><![CDATA[Techniques]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1456</guid>
		<description><![CDATA[A client recently tried to re-acquire a domain that had lapsed and was given an asking price of $36,000 (yes, thirty six thousand!) dollars. While this is likely grounds for a cybersquatting civil lawsuit, it would end up costing near that amount to retain legal counsel. (I am sure the unscrupulous individuals who perpetrate such <a href="http://camwebdesign.com/techniques/do-not-let-your-domain-name-expire/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>A client recently tried to re-acquire a domain that had lapsed and was given an asking price of $36,000 (yes, <em>thirty six thousand</em>!) dollars.<span id="more-1456"></span><br />
<img class="alignright size-medium wp-image-1458" title="Cybersquatting" src="http://camwebdesign.com/~/wp-content/uploads/2010/09/Cybersquatting-300x247.png" alt="" width="300" height="247" /></p>
<p>While this is likely grounds for a <a href="http://en.wikipedia.org/wiki/Cybersquatting">cybersquatting</a> civil lawsuit, it would end up costing near that amount to retain legal counsel. (I am sure the unscrupulous individuals who perpetrate such &#8220;business&#8221; are aware of this.)</p>
<p>So the bottom line is this: <strong>Do not let your domain name expire!</strong></p>
<p>If you let us purchase your domain, we will automatically renew it for you. If you are hosting through us, we will do what we can to remind you that your domain is expiring.</p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/do-not-let-your-domain-name-expire/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serve Watermarked Images with PHP</title>
		<link>http://camwebdesign.com/techniques/serve-watermarked-images-with-php/</link>
		<comments>http://camwebdesign.com/techniques/serve-watermarked-images-with-php/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 15:41:02 +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=1301</guid>
		<description><![CDATA[So you want to watermark your images, how do you do this? In this technique we&#8217;ll show you how we serve our images with a watermark using PHP. We&#8217;ll be building on the Serve Resized Images with PHP tutorial we published previously, which explains basic re-size manipulation of your images. Stepping through the code, we <a href="http://camwebdesign.com/techniques/serve-watermarked-images-with-php/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>So you want to watermark your images, how do you do this?  In this technique we&#8217;ll show you how we serve our images with a watermark using PHP.  We&#8217;ll be building on the <a href="http://camwebdesign.com/techniques/serve-resized-images-with-php/">Serve Resized Images with PHP</a> tutorial we published previously, which explains basic re-size manipulation of your images.</p>
<p>Stepping through the code, we first get our previously created watermark<span id="more-1301"></span> <img src="http://camwebdesign.com/images/copyright.png" alt="watermark" style="vertical-align:middle;" /> using the <a href="http://php.net/manual/en/function.imagecreatefrompng.php"><code>imagecreatefrompng()</code></a> PHP function, setting it to the variable $watermark for simplicity.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$watermark</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'../images/watermark.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Next we determine the watermark image&#8217;s width and height.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$watermark_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$watermark</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$watermark_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$watermark</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Since we want our watermark to appear in the bottom right of the original image, we&#8217;ll subtract the watermark image&#8217;s width and height from the original image&#8217;s width and height to determine it&#8217;s placement.  We also subtract 5 pixels for a padded placement.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dest_x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$watermark_width</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dest_y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$watermark_height</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Lastly we&#8217;ll actually apply the watermark image using the <a href="http://php.net/manual/en/function.imagecopymerge.php"><code>imagecopymerge()</code></a> PHP function.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">imagecopymerge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$watermark</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_y</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$watermark_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$watermark_height</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Putting the watermark code together we get the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Set up Watermark</span>
<span style="color: #000088;">$watermark</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'../images/watermark.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$watermark_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$watermark</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$watermark_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$watermark</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dest_x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$watermark_width</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dest_y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$watermark_height</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Apply Watermark</span>
<span style="color: #990000;">imagecopymerge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$watermark</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_y</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$watermark_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$watermark_height</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Adding the watermark code to our previous Serve Resized Images with PHP technique code we&#8217;ll have the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/path/to/include/functions.phtml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$img1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/images/&quot;</span> <span style="color: #339933;">.</span>  <span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>img<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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: #339933;">!</span><span style="color: #990000;">is_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$img1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/nophoto.gif&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_image<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//Send proper image header base on mime type</span>
  <span style="color: #000088;">$mime</span><span style="color: #339933;">=</span>get_mime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$mime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Set dimensions, quality &amp; variables</span>
  <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>w<span style="color: #009900;">&#93;</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: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//it's a thumbnail request don't preserve aspect</span>
    <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">150</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$thmb_quality</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</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: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">588</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">588</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$thmb_quality</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Get orig dimensions</span>
  <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width_orig</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height_orig</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type_orig</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$src_x</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$src_y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//it's a thumbnail request, make it square from the center</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width_orig</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #000088;">$height_orig</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$src_y</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$height_orig</span><span style="color: #339933;">-</span><span style="color: #000088;">$width_orig</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$height_orig</span><span style="color: #339933;">=</span><span style="color: #000088;">$width_orig</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;">$src_x</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width_orig</span><span style="color: #339933;">-</span><span style="color: #000088;">$height_orig</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$width_orig</span><span style="color: #339933;">=</span><span style="color: #000088;">$height_orig</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//keep aspect ratio but keeping width set from page</span>
    <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$width_orig</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$height_orig</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Resample</span>
  <span style="color: #000088;">$image</span><span style="color: #339933;">=</span>imagecreatefrom<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src_y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width_orig</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height_orig</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/*BEGIN WATERMARK CODE**************************************************************/</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//Set up Watermark</span>
  <span style="color: #000088;">$watermark</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'../images/watermark.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$watermark_width</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesx</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$watermark</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$watermark_height</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagesy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$watermark</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$dest_x</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$watermark_width</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$dest_y</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$height</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$watermark_height</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//Apply Watermark</span>
  <span style="color: #990000;">imagecopymerge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$watermark</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_y</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$watermark_width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$watermark_height</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">/*END WATERMARK CODE****************************************************************/</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//Print Image</span>
  image_same_type<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #339933;">,</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span><span style="color: #000088;">$thmb_quality</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
  image_cache_type<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #339933;">,</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span><span style="color: #000088;">$image_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<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 the default 588pixel width/height, keeping the aspect ratio, using an image named &#8220;uwcmc.jpg&#8221; for our <a href="http://camwebdesign.com/portfolio/united-way-of-cape-may-county/">United Way of Cape May County</a> client.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;http://camwebdesign.com/layout/thumb.php?a=y&amp;img=uwcmc.jpg&quot; alt=&quot;UWCMC&quot; /&gt;</pre></td></tr></table></div>

<p><img src="http://camwebdesign.com/layout/thumb.php?a=y&#038;img=uwcmc.jpg" alt="UWCMC" class="contentimg" /></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/serve-watermarked-images-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Admin Link Shortcode for Thematic Footer Text</title>
		<link>http://camwebdesign.com/techniques/admin-link-shortcode-for-thematic-footer-text/</link>
		<comments>http://camwebdesign.com/techniques/admin-link-shortcode-for-thematic-footer-text/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 12:07:03 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Thematic]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1252</guid>
		<description><![CDATA[Thematic comes with a variety of shortcodes that can be added to the footer text in the Thematic Options. We wanted to add the Admin link to the footer, but there is no predefined Thematic shortcode to do this. This technique shows how to create a custom Admin shortcode for Thematic. It is accomplished with <a href="http://camwebdesign.com/techniques/admin-link-shortcode-for-thematic-footer-text/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://themeshaper.com/thematic/">Thematic</a> comes with a variety of <a href="http://en.support.wordpress.com/shortcodes/">shortcodes</a> that can be added to the footer text in the Thematic Options.  We wanted to add the Admin link to the footer, but there is no predefined Thematic shortcode to do this.  This technique shows how to create a custom Admin shortcode for Thematic.  It is accomplished with a few lines of code in your Thematic <a href="http://codex.wordpress.org/Child_Themes">child theme</a>’s functions.php file.  <a href="http://camwebdesign.com/?p=1593">You are using a child theme, aren’t you?</a></p>
<p>First define a new function, we used <code>thmfooter_admin_link()</code>.<span id="more-1252"></span>  We return the <a href="http://codex.wordpress.org/Function_Reference/wp_register"><code>wp_register()</code></a> WordPress function, to yield the Admin link.  Be sure to set the <code>wp_register() $echo</code> <a href="http://codex.wordpress.org/Function_Reference/wp_register#Parameters">parameter</a> to false, otherwise the Admin link will automatically print.  We&#8217;ll also set the <code>$before</code> and <code>$after</code> parameters as needed.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> thmfooter_admin_link<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> wp_register<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'| '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Lastly we register the shortcode, naming it &#8216;admin-link&#8217;, using the <a href="http://codex.wordpress.org/Function_Reference/add_shortcode"><code>add_shortcode()</code></a> WordPress function as shown below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin-link'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'thmfooter_admin_link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Usage of our new shortcode is accomplished by simply adding [admin-link] in the footer text of the Thematic Options.</p>
<div id="attachment_1289" class="wp-caption alignnone" style="width: 580px"><img class="size-full wp-image-1289" title="Thematic Options" src="http://camwebdesign.com/~/wp-content/uploads/2010/08/thematic_options.jpg" alt="Thematic Options" width="570" height="320" /><p class="wp-caption-text">Thematic Options</p></div>
<p>Putting it all together, we have the following code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Add Admin shortcode to the siteinfo footer***************************************************************************</span>
<span style="color: #000000; font-weight: bold;">function</span> thmfooter_admin_link<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> wp_register<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'| '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin-link'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'thmfooter_admin_link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Yep, it&#8217;s just that simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/admin-link-shortcode-for-thematic-footer-text/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using HTML5 with your Thematic Child Theme</title>
		<link>http://camwebdesign.com/techniques/using-html5-with-your-thematic-child-theme/</link>
		<comments>http://camwebdesign.com/techniques/using-html5-with-your-thematic-child-theme/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 02:32:38 +0000</pubDate>
		<dc:creator>Troy</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Thematic]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1180</guid>
		<description><![CDATA[In the interest of keeping our websites &#8220;future-proof&#8221;, I began investigating using the HTML5 DOCTYPE. As it turns out, the switch for most WordPress themes will be trivial: Change the doctype declaration to: &#60;&#33;DOCTYPE html&#62; Remove the (now defunct) profile="..." attribute from the opening &#60;head&#62; tag. Remove the unnecessary &#60;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&#62; tag. Add <a href="http://camwebdesign.com/techniques/using-html5-with-your-thematic-child-theme/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>In the interest of keeping our websites &#8220;future-proof&#8221;, I began investigating using the HTML5 DOCTYPE.</p>
<p>As it turns out, the switch for most WordPress themes will be trivial: </p>
<ol>
<li>Change the doctype declaration to: <code>&lt;&#33;DOCTYPE html&gt;</code> </li>
<li>Remove the (now defunct) <code>profile="..."</code> attribute from the opening <code>&lt;head&gt;</code> tag.</li>
<li>Remove the unnecessary <code>&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;</code> tag.</li>
<li>Add the <code>&lt;meta charset="utf-8"&gt;</code> tag.</li>
</ol>
<p>Normally, this would be easily found in the <code>header.php</code> file of your theme.  In fact, the default WordPress theme (&#8216;<a href="http://2010dev.wordpress.com/">TwentyTen</a>&#8216; as of WP3) automatically uses the HTML5 doctype declaration.</p>
<p><a href="http://themeshaper.com/thematic/">Thematic</a>, however, uses the traditional &#8220;XHTML 1.0 Transitional&#8221; doctype<span id="more-1180"></span> that WordPress has used for years.  In order to use the HTML5 doctype, you will need to override four standard Thematic functions: <code>thematic_create_doctype</code>, <code>language_attributes</code>, <code>thematic_head_profile</code> and <code>thematic_create_contenttype</code> within your <a href="http://codex.wordpress.org/Child_Themes">child theme&#8217;s</a> <code>functions.php</code> file (<a href="http://camwebdesign.com/?p=1593">you are using a child theme, aren’t you?</a>), thusly:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//replace the standard doctype declaration and html tag opening...</span>
<span style="color: #000000; font-weight: bold;">function</span> html5_create_doctype<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;!DOCTYPE html&gt;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;html&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thematic_create_doctype'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'html5_create_doctype'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//replace the lang attribute in the opening &lt;html&gt; tag...</span>
<span style="color: #000000; font-weight: bold;">function</span> html5_language_attributes<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>en<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'language_attributes'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'html5_language_attributes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//replace the &lt;head&gt; tag opening to remove the now defunct profile attribute and add the &lt;meta charset=&quot;utf-8&quot;&gt; tag...</span>
<span style="color: #000000; font-weight: bold;">function</span> html5_head<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;head&gt;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;meta charset=<span style="color: #000099; font-weight: bold;">\&quot;</span>utf-8<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thematic_head_profile'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'html5_head'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//remove the now defunct &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt; tag...</span>
<span style="color: #000000; font-weight: bold;">function</span> html5_create_charset<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thematic_create_contenttype'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'html5_create_charset'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/using-html5-with-your-thematic-child-theme/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress 3.0 Menu Management</title>
		<link>http://camwebdesign.com/techniques/wordpress-3-0-menu-management/</link>
		<comments>http://camwebdesign.com/techniques/wordpress-3-0-menu-management/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 08:28:02 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1126</guid>
		<description><![CDATA[One of the best all-around additions to WordPress 3.0 is custom Menu management. So how do you implement custom menus into your WordPress site? Simply add a few lines of code in your theme&#8217;s functions.php file, then add the menus where desired in your theme. Yes, it requires adding php code to your theme&#8217;s files, <a href="http://camwebdesign.com/techniques/wordpress-3-0-menu-management/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>One of the best all-around <a href="http://codex.wordpress.org/Version_3.0#Highlights">additions to WordPress 3.0</a> is <a href="http://codex.wordpress.org/Appearance_Menus_SubPanel">custom Menu management</a>.  So how do you implement custom menus into your WordPress site?  Simply add a few lines of code in your theme&#8217;s <a href="http://codex.wordpress.org/Theme_Development#Functions_File">functions.php</a> file, then add the menus where desired in your theme.  Yes, it requires adding php code to your theme&#8217;s files, but it&#8217;s simple and easy to understand.</p>
<p>First we register the ability for your theme to use custom menus using the <a href="http://codex.wordpress.org/Function_Reference/add_theme_support"><code>add_theme_support()</code></a> WordPress function.<span id="more-1126"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_theme_support<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'menus'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Next we define the custom menus.  For this example we&#8217;ll create two menus: menu-1 and menu-2, and name them &#8220;Main Navigation&#8217; and &#8216;Footer Navigation&#8217; respectively.  We accomplish this in a new function &#8216;register_site_menus&#8217;, using the <a href="http://codex.wordpress.org/Function_Reference/register_nav_menus"><code>register_nav_menus()</code></a> WordPress function.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> register_site_menus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	register_nav_menus<span style="color: #009900;">&#40;</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'menu-1'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Main Navigation'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'menu-2'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Footer Navigation'</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We then initiate the new <code>register_site_menus()</code> function using the <a href="http://codex.wordpress.org/Function_Reference/add_action"><code>add_actions()</code></a> WordPress function as shown below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'register_site_menus'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Putting it all together yields the following code to be placed in your theme&#8217;s functions.php file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_theme_support<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'menus'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> register_site_menus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	register_nav_menus<span style="color: #009900;">&#40;</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'menu-1'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Main Navigation'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'menu-2'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Footer Navigation'</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'register_site_menus'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Next we add &#8216;menu-1&#8242; our &#8216;Main Navigation&#8217; menu, using the <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu"><code>wp_nav_menu()</code></a> WordPress function where we want that menu to appear in your theme (header, sidebar, etc.).  We also chose to not have a container automatically added to our menu for this example below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">wp_nav_menu<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
	<span style="color: #0000ff;">'theme_location'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'menu-1'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'container'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span>
<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We&#8217;ll add &#8216;menu-2&#8242; our &#8216;Footer Navigation&#8217; menu, using the same function but, we also give the menu a custom CSS id of &#8216;footer-nav&#8217;.  You can read all about the <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu#Parameters">parameters of the <code>wp_nav_menu()</code> function</a> yourself rather than bore you with the details here.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">wp_nav_menu<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'theme_location'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'menu-2'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'container'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'menu_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'footer-nav'</span>
<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/wordpress-3-0-menu-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Create Custom Roles and Capabilities</title>
		<link>http://camwebdesign.com/techniques/wordpress-create-custom-roles-and-capabilities/</link>
		<comments>http://camwebdesign.com/techniques/wordpress-create-custom-roles-and-capabilities/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 01:17:08 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1166</guid>
		<description><![CDATA[So you want to add a custom Role to your WordPress site to add more flexibility when assigning users their role, what do you do? Simply add a role, with a few lines of code in your theme&#8217;s functions.php file, using WordPress&#8217; add_role() function, as defined below. 1 add_role&#40; $role_name, $display_name, $capabilities &#41;; The example <a href="http://camwebdesign.com/techniques/wordpress-create-custom-roles-and-capabilities/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>So you want to add a custom <a href="http://codex.wordpress.org/Roles_and_Capabilities">Role</a> to your WordPress site to add more flexibility when assigning users their role, what do you do? Simply add a role, with a few lines of code in your theme&#8217;s <a href="http://codex.wordpress.org/Theme_Development#Functions_File">functions.php</a> file, using WordPress&#8217; <a href="http://codex.wordpress.org/Function_Reference/add_role"><code>add_role()</code></a> function, as defined below.<span id="more-1166"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_role<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$role_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$display_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$capabilities</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The example below adds a role of Video Manager with a custom cabability of &#8216;manage videos&#8217;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_role<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'video_manager, '</span>Video Manager<span style="color: #0000ff;">', array( '</span>manage_videos<span style="color: #0000ff;">' ) );</span></pre></td></tr></table></div>

<h3>NOTE: Once you add this code to your functions.php file and view any page on your site to make the role addition, you can and should comment it out so that it doesn&#8217;t run on every page view.</h3>
<p>Now, how do we use this new role with the new capability you ask?  Simply use the WordPress <code>current_user_can()</code> function to check the user&#8217;s capability.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> current_user_can<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'manage_videos'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// let them manage those videos!</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This technique can be combined with our <a href="http://camwebdesign.com/techniques/wordpress-role-capability-restriction/">WordPress Role Capability Restriction technique</a> to add even more capabilities to your new custom role.  Simply create your new role then use it in the <code>get_role()</code> function call detailed in our technique.</p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/wordpress-create-custom-roles-and-capabilities/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>WordPress Role Capability Restriction</title>
		<link>http://camwebdesign.com/techniques/wordpress-role-capability-restriction/</link>
		<comments>http://camwebdesign.com/techniques/wordpress-role-capability-restriction/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 06:59:23 +0000</pubDate>
		<dc:creator>Corey</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://camwebdesign.com/?p=1089</guid>
		<description><![CDATA[So you want to restrict user capabilities of a role on your WordPress site from editing and deleting other user&#8217;s pages and posts, but you can&#8217;t seem to find an easy-to-use plugin that meets your needs, what do you do? Simply restrict that role, with a few lines of code in your theme&#8217;s functions.php file, <a href="http://camwebdesign.com/techniques/wordpress-role-capability-restriction/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>So you want to restrict user <a href="http://codex.wordpress.org/Roles_and_Capabilities">capabilities of a role</a> on your WordPress site from editing and deleting other user&#8217;s pages and posts, but you can&#8217;t seem to find an easy-to-use plugin that meets your needs, what do you do?  Simply restrict that role, with a few lines of code in your theme&#8217;s <a href="http://codex.wordpress.org/Theme_Development#Functions_File">functions.php</a> file, using WordPress&#8217; <code>get_role()</code> and <code>remove_cap()</code> functions.  The example below is how to restrict the <a href="http://codex.wordpress.org/Roles_and_Capabilities#Author">author role</a>.<span id="more-1089"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$role</span> <span style="color: #339933;">=</span> get_role<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'author'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$role</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">remove_cap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'edit_others_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$role</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">remove_cap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'edit_others_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$role</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">remove_cap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'delete_others_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$role</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">remove_cap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'delete_others_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Pretty simple huh?  That&#8217;s what I thought when I learned how easily this can be accomplished.</p>
<p>So what&#8217;s actually going on with the code?  First, we create a variable $role populated with the author&#8217;s capabilities.  Then we remove the ability of the authors to &#8216;edit_others_pages&#8217;, and <a href="http://codex.wordpress.org/Roles_and_Capabilities#Capabilities">other capabilities</a> as desired.  This code performs a database change to the role.</p>
<h3>NOTE: Once you add this code to your functions.php file and view any page on your site to make the capability changes, you can and should comment it out so that it doesn&#8217;t run on every page view.</h3>
<p>How do you reverse this you may ask?  Simple, use WordPress&#8217; <code>add_cap()</code> function, as if WordPress would let us down.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$role</span> <span style="color: #339933;">=</span> get_role<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'author'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$role</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_cap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'edit_others_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$role</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_cap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'edit_others_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$role</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_cap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'delete_others_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$role</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_cap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'delete_others_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This works great when you&#8217;ve <a href="http://camwebdesign.com/techniques/wordpress-create-custom-role-and-capabilities/">Created Custom Roles</a> and need to assign capabilities to those new roles.</p>
<p>Below is real-world code we&#8217;ve used on a site, and how we left it commented for future reference.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* Begin Editor Restriction  ****************/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Enable Restriction Below */</span>
<span style="color: #666666; font-style: italic;">//$role = get_role('editor');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;remove_cap('edit_others_pages');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;remove_cap('edit_others_posts');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;remove_cap('delete_others_pages');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;remove_cap('delete_others_posts');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;remove_cap('manage_links');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;remove_cap('moderate_comments');</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Disable Restriction Below */</span>
<span style="color: #666666; font-style: italic;">//$role = get_role('editor');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;add_cap('edit_others_pages');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;add_cap('edit_others_posts');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;add_cap('delete_others_pages');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;add_cap('delete_others_posts');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;add_cap('manage_links');</span>
<span style="color: #666666; font-style: italic;">//$role-&gt;add_cap('moderate_comments');</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* End Editor Restriction  ***************/</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/wordpress-role-capability-restriction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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[There are many reasons we use PHP to serve images on sites including: resizing, watermarking, 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. We&#8217;ll cover more advanced image manipulation techniques in later posts. The first <a href="http://camwebdesign.com/techniques/serve-resized-images-with-php/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<p>There are many reasons we use PHP to serve images on sites including: resizing, <a href="http://camwebdesign.com/techniques/serve-watermarked-images-with-php/">watermarking</a>, 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.  We&#8217;ll cover more advanced image manipulation techniques in later posts.</p>
<p>The first line of code calls the functions.phtml<span id="more-605"></span> 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"><code>$_GET</code></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.  The fourth line checks if the requested file is an image and surrounds the remaining code with the if statement.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/path/to/include/functions.phtml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$img1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/images/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>img<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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: #339933;">!</span><span style="color: #990000;">is_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$img1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/images/nophoto.gif&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_image<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
&nbsp;
   <span style="color: #666666; font-style: italic;">/*** The rest of the Code ***/</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></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 class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #666666; font-style: italic;">//Send proper image header base on mime type</span>
  <span style="color: #000088;">$mime</span><span style="color: #339933;">=</span>get_mime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$mime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>With the following code we determine the final image&#8217;s width and height.  Based on the presence of <code>$_GET[a]</code> 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 class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #666666; font-style: italic;">// Set dimensions, quality &amp; variables</span>
  <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>w<span style="color: #009900;">&#93;</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: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//it's a thumbnail request don't preserve aspect</span>
    <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">178</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">178</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$thmb_quality</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</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: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">588</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">588</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$thmb_quality</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We then determine the original image&#8217;s width and height.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #666666; font-style: italic;">// Get orig dimensions</span>
  <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width_orig</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height_orig</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type_orig</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$src_x</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$src_y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span></pre></td></tr></table></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 <code>$_GET[a]</code> variable in the URL.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//it's a thumbnail request, make it square from the center</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width_orig</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$height_orig</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$src_y</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$height_orig</span><span style="color: #339933;">-</span><span style="color: #000088;">$width_orig</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$height_orig</span><span style="color: #339933;">=</span><span style="color: #000088;">$width_orig</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;">$src_x</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width_orig</span><span style="color: #339933;">-</span><span style="color: #000088;">$height_orig</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$width_orig</span><span style="color: #339933;">=</span><span style="color: #000088;">$height_orig</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//keep aspect ratio but keeping width set from page</span>
    <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$width_orig</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$height_orig</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</pre>
<p>Finally we re-sample then print the image with PHP.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #666666; font-style: italic;">// Resample</span>
  <span style="color: #000088;">$image</span><span style="color: #339933;">=</span>imagecreatefrom<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src_y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width_orig</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height_orig</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//Print Image</span>
  image_same_type<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #339933;">,</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span><span style="color: #000088;">$thmb_quality</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
  image_cache_type<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #339933;">,</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span><span style="color: #000088;">$image_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<hr />
<br />
Putting it all together we arrive at the following code, we named our PHP file thumb.php since it's primary role is to make thumbnails for the site.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/path/to/include/functions.phtml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$img1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/images/&quot;</span> <span style="color: #339933;">.</span>  <span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>img<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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: #339933;">!</span><span style="color: #990000;">is_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$img1</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/nophoto.gif&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_image<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//Send proper image header base on mime type</span>
  <span style="color: #000088;">$mime</span><span style="color: #339933;">=</span>get_mime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$mime</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Set dimensions, quality &amp; variables</span>
  <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>w<span style="color: #009900;">&#93;</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: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//it's a thumbnail request don't preserve aspect</span>
    <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">150</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$thmb_quality</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</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: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">300</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">588</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">588</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">;</span>
    <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$width</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$thmb_quality</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Get orig dimensions</span>
  <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width_orig</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height_orig</span><span style="color: #339933;">,</span> <span style="color: #000088;">$type_orig</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$src_x</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$src_y</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>a<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//it's a thumbnail request, make it square from the center</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width_orig</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #000088;">$height_orig</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$src_y</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$height_orig</span><span style="color: #339933;">-</span><span style="color: #000088;">$width_orig</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$height_orig</span><span style="color: #339933;">=</span><span style="color: #000088;">$width_orig</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;">$src_x</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width_orig</span><span style="color: #339933;">-</span><span style="color: #000088;">$height_orig</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$width_orig</span><span style="color: #339933;">=</span><span style="color: #000088;">$height_orig</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//keep aspect ratio but keeping width set from page</span>
    <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$width_orig</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$height_orig</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Resample</span>
  <span style="color: #000088;">$image</span><span style="color: #339933;">=</span>imagecreatefrom<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src_y</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width_orig</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height_orig</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">//Print Image</span>
  image_same_type<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #339933;">,</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span><span style="color: #000088;">$thmb_quality</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
  image_cache_type<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img1</span><span style="color: #339933;">,</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span><span style="color: #000088;">$image_path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<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 "uwcmc.jpg" for our <a href="http://camwebdesign.com/portfolio/united-way-of-cape-may-county/">United Way of Cape May County</a> client.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;http://camwebdesign.com/layout/thumb.php?w=200&amp;a=y&amp;img=uwcmc.jpg&quot; alt=&quot;UWCMC&quot; /&gt;</pre></td></tr></table></div>

<p><img src="http://camwebdesign.com/layout/thumb.php?w=200&#038;a=y&#038;img=uwcmc.jpg" alt="UWCMC" /></p>
<p>
Below we are calling an image without specifying width or aspect ration, again using an image named "uwcmc.jpg".</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;http://camwebdesign.com/layout/thumb.php?img=uwcmc.jpg&quot; alt=&quot;UWCMC&quot; /&gt;</pre></td></tr></table></div>

<p><img src="http://camwebdesign.com/layout/thumb.php?img=uwcmc.jpg" alt="UWCMC" /></p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/serve-resized-images-with-php/feed/</wfw:commentRss>
		<slash:comments>1</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 <a href="http://camwebdesign.com/techniques/php-image-manipulation-functions/" class="more-link">(more...)</a>]]></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 a PHP <a href="http://php.net/manual/en/function.include-once.php"><code>include_once()</code></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 <code>is_image()</code><span id="more-631"></span>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*Define is_image() ****************************************************************************************************/</span>
<span style="color: #000000; font-weight: bold;">function</span> is_image<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$t</span><span style="color: #339933;">=</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var1</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$t2</span><span style="color: #339933;">=</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var1</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</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: #000088;">$t</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;GIF&quot;</span> <span style="color: #339933;">||</span><span style="color: #000088;">$t</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;PNG&quot;</span> <span style="color: #339933;">||</span><span style="color: #000088;">$t</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;JPG&quot;</span> <span style="color: #339933;">||</span><span style="color: #000088;">$t2</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;JPEG&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This function returns the extension for any file <code>getExtension().</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*Define getExtension() ****************************************************************************************************/</span>
<span style="color: #000000; font-weight: bold;">function</span> getExtension<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$pos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</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: #339933;">!</span><span style="color: #000088;">$pos</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$photosubmitted</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Error: Unknown Filetype'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pos</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>><br />
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 <code>get_mime()</code>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*Define get_mime() ****************************************************************************************************/</span>
<span style="color: #000000; font-weight: bold;">function</span> get_mime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$t</span><span style="color: #339933;">=</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var1</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;.JPG&quot;</span><span style="color: #339933;">:</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;.JPEG&quot;</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;image/jpeg&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;.GIF&quot;</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;image/gif&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;.PNG&quot;</span><span style="color: #339933;">:</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;image/png&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This fourth function allows for the use of the proper PHP image <code>createfrom<em>xxx</em>()</code> call based on image type <code>imagecreatefrom()</code>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*Define imagecreatefrom() ****************************************************************************************************/</span>
<span style="color: #000000; font-weight: bold;">function</span> imagecreatefrom<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;JPG&quot;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;JPEG&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>		
	<span style="color: #000088;">$image</span><span style="color: #339933;">=</span><span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;PNG&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>		
	<span style="color: #000088;">$image</span><span style="color: #339933;">=</span><span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;GIF&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>		
	<span style="color: #000088;">$image</span><span style="color: #339933;">=</span><span style="color: #990000;">imagecreatefromgif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$image</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Lastly this functions will output the image to the browser <code>image_same_type().</code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*Define image_same_type() ****************************************************************************************************/</span>
<span style="color: #000000; font-weight: bold;">function</span> image_same_type<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span><span style="color: #000088;">$quality</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;JPG&quot;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;JPEG&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>		
  	<span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #000088;">$quality</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;PNG&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>		
  	<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,-</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;GIF&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>		
  	<span style="color: #990000;">imagegif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$image</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/php-image-manipulation-functions/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 <a href="http://camwebdesign.com/techniques/css-reset-anyone/" class="more-link">(more...)</a>]]></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, 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:<span id="more-521"></span></h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* ------------------------Begin Reset------------------------ */</span>
html<span style="color: #00AA00;">,</span> body<span style="color: #00AA00;">,</span> div<span style="color: #00AA00;">,</span> span<span style="color: #00AA00;">,</span> applet<span style="color: #00AA00;">,</span> object<span style="color: #00AA00;">,</span> iframe<span style="color: #00AA00;">,</span>
h1<span style="color: #00AA00;">,</span> h2<span style="color: #00AA00;">,</span> h3<span style="color: #00AA00;">,</span> h4<span style="color: #00AA00;">,</span> h5<span style="color: #00AA00;">,</span> h6<span style="color: #00AA00;">,</span> p<span style="color: #00AA00;">,</span> blockquote<span style="color: #00AA00;">,</span> pre<span style="color: #00AA00;">,</span>
a<span style="color: #00AA00;">,</span> abbr<span style="color: #00AA00;">,</span> acronym<span style="color: #00AA00;">,</span> address<span style="color: #00AA00;">,</span> big<span style="color: #00AA00;">,</span> cite<span style="color: #00AA00;">,</span> code<span style="color: #00AA00;">,</span>
del<span style="color: #00AA00;">,</span> dfn<span style="color: #00AA00;">,</span> em<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">,</span> img<span style="color: #00AA00;">,</span> ins<span style="color: #00AA00;">,</span> kbd<span style="color: #00AA00;">,</span> q<span style="color: #00AA00;">,</span> s<span style="color: #00AA00;">,</span> samp<span style="color: #00AA00;">,</span>
small<span style="color: #00AA00;">,</span> strike<span style="color: #00AA00;">,</span> strong<span style="color: #00AA00;">,</span> sub<span style="color: #00AA00;">,</span> sup<span style="color: #00AA00;">,</span> tt<span style="color: #00AA00;">,</span> var<span style="color: #00AA00;">,</span>
b<span style="color: #00AA00;">,</span> u<span style="color: #00AA00;">,</span> i<span style="color: #00AA00;">,</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">,</span>
dl<span style="color: #00AA00;">,</span> dt<span style="color: #00AA00;">,</span> dd<span style="color: #00AA00;">,</span> ol<span style="color: #00AA00;">,</span> ul<span style="color: #00AA00;">,</span> li<span style="color: #00AA00;">,</span>
fieldset<span style="color: #00AA00;">,</span> form<span style="color: #00AA00;">,</span> label<span style="color: #00AA00;">,</span> legend<span style="color: #00AA00;">,</span>
table<span style="color: #00AA00;">,</span> caption<span style="color: #00AA00;">,</span> tbody<span style="color: #00AA00;">,</span> tfoot<span style="color: #00AA00;">,</span> thead<span style="color: #00AA00;">,</span> tr<span style="color: #00AA00;">,</span> th<span style="color: #00AA00;">,</span> td <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">baseline</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1.4</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
ol<span style="color: #00AA00;">,</span> ul <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
blockquote<span style="color: #00AA00;">,</span> q <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">quotes</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
blockquote<span style="color: #3333ff;">:before</span><span style="color: #00AA00;">,</span> blockquote<span style="color: #3333ff;">:after</span><span style="color: #00AA00;">,</span>
q<span style="color: #3333ff;">:before</span><span style="color: #00AA00;">,</span> q<span style="color: #3333ff;">:after </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">''</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* remember to define focus styles! */</span>
<span style="color: #3333ff;">:focus </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* remember to highlight inserts somehow! */</span>
ins <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
del <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">line-through</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* tables still need 'cellspacing=&quot;0&quot;' in the markup */</span>
table <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">border-collapse</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">collapse</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-spacing</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/* ------------------------End Reset------------------------ */</span></pre></td></tr></table></div>

]]></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. <a href="http://camwebdesign.com/techniques/what-wordpress-plugins-do-we-use/" class="more-link">(more...)</a>]]></description>
			<content:encoded><![CDATA[<h3>A list of the WordPress plugins we recommend and use.<span id="more-413"></span></h3>
<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>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>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/what-wordpress-plugins-do-we-use/feed/</wfw:commentRss>
		<slash:comments>1</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[Images]]></category>
		<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. You&#8217;ll need PHP (PHP: Hypertext Preprocessor) the open source dynamic language the code in our example <a href="http://camwebdesign.com/techniques/dynamic-font-based-images/" class="more-link">(more...)</a>]]></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>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>.<span id="more-319"></span></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 class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Get the text to draw</span>
<span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'text'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'text'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'oops...missing text'</span> <span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//set default text if missing</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Path to the font</span>
<span style="color: #000088;">$font</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/path/to/the/font/AGENCYR.TTF'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get display font size</span>
<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'size'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color:#800080;">18.5</span> <span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//set default if empty</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get display width</span>
<span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span> <span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//set default if empty</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get display height</span>
<span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'h'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'h'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">40</span> <span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//set default if empty</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create the image</span>
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Choose text color</span>
<span style="color: #000088;">$color</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>color<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span>color<span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;black&quot;</span> <span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//Image color</span>
<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$color</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;black&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$use_color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;orange&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$use_color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">159</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">64</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;blue&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$use_color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">53</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">111</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;white&quot;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$use_color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get the top offset</span>
<span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'offset'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'offset'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #cc66cc;">30</span> <span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//set default if empty</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create the image background</span>
<span style="color: #000088;">$bgcolor</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bgcolor'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'white'</span><span style="color: #009900;">&#41;</span> ?	<span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//set default if empty</span>
<span style="color: #990000;">imagefilledrectangle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bgcolor</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Make the background-color transparent</span>
<span style="color: #990000;">imagecolortransparent</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bgcolor</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Add some shadow to the text if requested</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'shadow'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$shadoffset</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$offset</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$shadow</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">220</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">220</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">220</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">imagettftext</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$shadoffset</span><span style="color: #339933;">,</span> <span style="color: #000088;">$shadow</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Add the text in the color chosen</span>
<span style="color: #990000;">imagettftext</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$offset</span><span style="color: #339933;">,</span> <span style="color: #000088;">$use_color</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
<span style="color: #666666; font-style: italic;">// Set the content-type and print the image</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: image/gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagegif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></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 class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;font.php?size=18&amp;amp;w=400&amp;amp;h=34&amp;amp;shadow=y&amp;amp;color=blue&amp;amp;bgcolor=white&amp;amp;text=My+Dynamic+Font+Based+Image&quot; alt=&quot;My Dynamic Font Based Image&quot; /&gt;</pre></td></tr></table></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 <code>&lt;?php the_title(); ?&gt;</code> 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 class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;font.php?size=20&amp;amp;w=500&amp;amp;shadow=y&amp;amp;color=blue&amp;amp;bgcolor=white&amp;amp;text=&lt;?php the_title(); ?&gt;&quot; alt=&quot;&lt;?php the_title(); ?&gt;&quot; /&gt;</pre></td></tr></table></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 <code>$color</code> and <code>$bgcolor</code> 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>
]]></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. 1 print &#34;Hello, World!&#34;; Alternatively we could write it this way: 1 echo &#34;Hello, World!&#34;; Both Yield Hello, World! If <a href="http://camwebdesign.com/techniques/hello-world-php-style/" class="more-link">(more...)</a>]]></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 in the examples <span id="more-563"></span>below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Hello, World!&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Alternatively we could write it this way:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Hello, World!&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Both Yield <code>Hello, World!</code></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 <code>print()</code> and <code>echo()</code> language constructs&#8221;?</p>
<p>The answer, not much &#8211; BUT &#8211; <code>echo</code> is faster than <code>print</code>.  <code>Print</code> returns an int value and <code>echo</code> returns no value.  Example: <code>$value = print "Hello World";</code> here <code>$value</code> will be set to <code>1</code>.  So <code>print</code> can be used in complex expression where you can&#8217;t use <code>echo</code>.</p>
<p>We can however, use <code>echo</code> is some creative short hand statements, like this one.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'hi'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot;Hello World!&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Goodbye World!&quot;</span> <span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Suppose the variable <code>$text</code> was set to &#8220;hi&#8221;, this would print <code>Hello World!</code>.  If <code>$text</code> was set to anything else then it will print <code>Goodbye World!</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://camwebdesign.com/techniques/hello-world-php-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

