<?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>Web Cash &#187; display</title>
	<atom:link href="http://www.earn-web-cash.com/tag/display/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.earn-web-cash.com</link>
	<description>Writing, Designing, and Making Money Online</description>
	<lastBuildDate>Sun, 04 Dec 2011 22:52:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>How to Use PHP To Dynamically Resize an Image</title>
		<link>http://www.earn-web-cash.com/2008/01/30/resize-images-php/</link>
		<comments>http://www.earn-web-cash.com/2008/01/30/resize-images-php/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 01:26:57 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/01/30/resize-images-php/</guid>
		<description><![CDATA[One of the most annoying things about working with images is getting them into the right size. Screenshots start out huge &#8211; and you need to resize them to an appropriate size for your website. Some blogs automatically resize the pictures for you into a thumbnail &#8211; like the image to the right. What if [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/01/dzone-screenshot.png' title='Screenshot of a Dzone Page'><img class="alignright" src='http://www.earn-web-cash.com/wp-content/uploads/2008/01/dzone-screenshot.thumbnail.png' alt='Screenshot of a Dzone Page' /></a>One of the most annoying things about working with images is getting them into the right size.  Screenshots start out huge &#8211; and you need to resize them to an appropriate size for your website.</p>
<p>Some blogs automatically resize the pictures for you into a thumbnail &#8211; like the image to the right.  What if you want the image a different size, though?  You could allow the browser to resize it for you, or &#8211; better yet &#8211; write your own php script to resize the image dynamically.<br />
<span id="more-87"></span></p>
<h5>Why You Shouldn&#8217;t Let the Browser Resize Images</h5>
<p><img src='http://www.earn-web-cash.com/wp-content/uploads/2008/01/dzone-screenshot.png' class='alignright' style='width: 200px; height: 150px'; />Look at the original picture &#8211; the small thumbnail created by WordPress.  Notice how large it is &#8211; 13.9kb.  When WordPress resizes the image, it also reduces the file size.  If I were to include the fullsize image and resize it using css height and width attributes, the file size would <strong>not</strong> be cut down.  </p>
<p>Want proof?  Look at the second image to the right &#8211; that&#8217;s simply resized by the browser.  It&#8217;s a whopping 284.21kb.</p>
<p><img src='/scripts/resize-image.php?image=http://www.earn-web-cash.com/wp-content/uploads/2008/01/dzone-screenshot.png' class='alignright' />If we write our own php script to resize the image dynamically, we can control both the image size <strong>and</strong> the file size.  Check out the third image to the right &#8211; which was resized with a php script.  You&#8217;ll notice that it looks nicer too &#8211; the browser isn&#8217;t designed to resize images.</p>
<h5>Using the PHP GD Library to Resize the Image</h5>
<p>So how do we do this?  We&#8217;re going to make use of the PHP GD library to manipulate the image, and a $_GET parameter to tell it which image to re-size.</p>
<p>Let&#8217;s walk through using the GD library to re-size an image.  Then we&#8217;ll see how to include that in your HTML to actually do the resizing for you.</p>
<p>First, we need to open up the original file and get it&#8217;s size and type characteristics.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$src_img</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$srcsize</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><code>imagecreatfrompng()</code> creates an image object and stores it in $src_image.  If the file was a different type we could replace &#8220;png&#8221; with &#8220;jpeg&#8221; or &#8220;gif.&#8221;  <code>getimagesize()</code> stores an array in $srcsize that contains the width of the image ($srcsize[0]), the height of the image ($srcsize[1]), and the filetype of the image ($srcsize[2]).</p>
<p>Now we need to create new dimensions for the new image and actually create an image.  We&#8217;ll resize it to 200 pixels wide &#8211; and then adjust the height to maintain the ratio.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$dest_x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">200</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dest_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$srcsize</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: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dst_img</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The calculations should be self explanatory.  <code>imagecreatetruecolor()</code> creates a new image object for us with the given dimensions &#8211; which we will soon fill in with our resized image.</p>
<p>The next step is to place the resized image into <code>$dst_img</code> and output the image as Image content.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src_img</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: #339933;">,</span> <span style="color: #cc66cc;">0</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: #000088;">$srcsize</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: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;content-type: image/png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><code>imagecopyresampled()</code> copies an image ($dst_img) into a new image ($src_img) with a set of given attributes (including our sizes).  The &#8220;Header&#8221; line tells the browser that this is an image &#8211; so that it&#8217;s not displayed as a bunch of gibberish.  Finally, the <code>imagepng()</code> function actually displays the image.</p>
<p>Now, we need to clean up and destroy the image objects.  Otherwise, we could end up sapping a lot of memory from the server.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h5>Displaying the Script in HTML</h5>
<p>If you load the script directly, you should simply see the image.  It creates an image resource and displays it in the browser &#8211; as if &#8220;resize-image.php&#8221; was really &#8220;image.png.&#8221;</p>
<p>Therefore all we need to do to include this new image in an HTML page is use the php script as the <code>src</code> attribute of our <code>&lt;img&gt;</code> tag.  Like so&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'resize-image.php'</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>The script will execute, create an image, and use that as the <code>src</code>.</p>
<p>The last thing we need to do is modify our script so that we can pass it some information.  </p>
<p>It wouldn&#8217;t do much good if we had to write a new php script for every image we wanted to resize.  Instead, we can use the $_GET array to send a variable (the image filename) to our image resizing script.</p>
<p>Here&#8217;s the entire image resizing script, with the $_GET variable used for the filename.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//  Create source image and dimensions</span>
<span style="color: #000088;">$src_img</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefrompng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$srcsize</span> <span style="color: #339933;">=</span> <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'image'</span><span style="color: #009900;">&#93;</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: #cc66cc;">200</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dest_y</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">200</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$srcsize</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: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dst_img</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatetruecolor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dest_x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Resize image</span>
<span style="color: #990000;">imagecopyresampled</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #339933;">,</span> <span style="color: #000088;">$src_img</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: #339933;">,</span> <span style="color: #cc66cc;">0</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: #000088;">$srcsize</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: #000088;">$srcsize</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Output image</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;content-type: image/png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Destroy images</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$src_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dst_img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To use this, you need to slightly modify your HTML and add an &#8220;image&#8221; parameter to the URL of your script.  Like so&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'resize-image.php?image=image.png'</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>There ya go!  Now you can resize images on the fly.</p>
<h5>Next Steps to Take&#8230;</h5>
<p>This is of course a basic introduction to the topic.  You can add a lot of functionality to resize-image.php.</p>
<p>For example, you could take extra parameters &#8211; like a width and/or height.  You might also want to include a bunch of error checking &#8211; make sure the file exists, make sure the new dimensions are appropriate, etc.  </p>
<p>You could also use a <code>switch()</code> statement to open different types of images &#8211; based on the contents of $srcsize[2].  Remember, you can use the GD library to do more than work with .png files.  By replacing &#8216;png&#8217; with &#8216;jpeg&#8217; or &#8216;gif&#8217; you can use the same functions to work with these file types.  For example, <code>imagecreatefromjpeg</code> is equivalent to <code>imagecreatefrompng</code>.</p>
<p>In the near future, I plan on extending this example into a full-fledged script for immediate download and use.  So stay tuned &#8211; and leave any comments with suggestions for what the script should be able to do.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/01/30/resize-images-php/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Check Your Websites Appearance in Other Browsers with Browsershots</title>
		<link>http://www.earn-web-cash.com/2008/01/23/website-in-browsers/</link>
		<comments>http://www.earn-web-cash.com/2008/01/23/website-in-browsers/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 22:55:11 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Online Tools]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/01/23/website-in-browsers/</guid>
		<description><![CDATA[One of the most frustrating aspects of web design is trying to make your website look good in every browser. If you use some advanced css techniques, you never know how an older browser or a different platform is going to handle it. You can test how your site displays in a few browsers &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most frustrating aspects of web design is trying to make your website look good in every browser.  If you use some advanced css techniques, you never know how an older browser or a different platform is going to handle it.</p>
<p>You can test how your site displays in a few browsers &#8211; for example, I often check mine out in Windows IE, Ubuntu Firefox, and Ubuntu Opera.  But how am I going to check it on Mac browsers like Safari?<br />
<span id="more-58"></span><br />
Enter <a href="http://www.browsershots.com" title="Site to check your page in different browsers">Browsershots</a>.</p>
<p>The premise is very simple.  You check off a list of browsers and platforms, enter your website&#8217;s url, and click submit.  Then the servers open your site, take a screenshot, and upload the display to Browsershots.</p>
<p><a href='http://www.earn-web-cash.com/wp-content/uploads/2008/01/teachbabel-msie55.jpg' title='Browsershots Screenshot of Babel'><img src='http://www.earn-web-cash.com/wp-content/uploads/2008/01/teachbabel-msie55.thumbnail.jpg' alt='Browsershots Screenshot of Babel' / class="alignright"></a>You can then view the screenshots and see how your website appeared in those browsers.  You can check out some <a href="http://browsershots.org/http://www.teachbabel.com/">sample displays</a> for an <a href="http://www.teachbabel.com">education related website</a> that I created.</p>
<p>Your options are pretty extensive.  At the moment you can choose from 36 Linux browsers, 12 Windows browsers, and 4 Mac OS browsers.</p>
<p>After you submit your request, you need to wait until your website comes up in the queue.  Each server (factory, as they call it at Browsershots) has its own queue.  A lot of the servers will be done in a couple of minutes, but some queues can be one to two hours long.</p>
<p>One of the downsides to the site is that your request will expire in 30 minutes.  The completed screenshots will stay up there, but if you have any requests left in the queue they will be canceled.</p>
<p>You can refresh your request by clicking a button, but if you get stuck in a 90 minute queue you&#8217;ll have to remember to refresh your request several times.</p>
<p>All in all, very useful tool.  I plan to use it to test out any future design projects.  So the next time you want to see how a foreign browser would display your site, head over to <a href="http://www.browsershots.com">Browsershots</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/01/23/website-in-browsers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

