<?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>MaggsWeb:7 &#187; image resize</title>
	<atom:link href="http://www.maggsweb.com/tag/image-resize/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.maggsweb.com</link>
	<description>www.maggsweb.com</description>
	<lastBuildDate>Sat, 21 Aug 2010 20:50:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>imageResize (inline)</title>
		<link>http://www.maggsweb.com/php/imageresize-inline/</link>
		<comments>http://www.maggsweb.com/php/imageresize-inline/#comments</comments>
		<pubDate>Wed, 23 May 2007 20:51:08 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[image resize]]></category>

		<guid isPermaLink="false">http://www.cmaggs.co.uk/?p=14</guid>
		<description><![CDATA[Can&#8217;t rely on the size of an uploaded image and don&#8217;t want to resize it? This function takes the larger size of the width and height and applies a formula accordingly. Then gets the new value and applies the percentage, then rounds the value. It returns the new sizes in html image tag format so [...]]]></description>
			<content:encoded><![CDATA[<p>Can&#8217;t rely on the size of an uploaded image and don&#8217;t want to resize it?</p>
<p>This function takes the larger size of the width and height and applies a formula accordingly.  Then gets the new value and applies the percentage, then rounds the value.  It returns the new sizes in html image tag format so that you can plug this function inside an image tag.</p>
<p><span id="more-14"></span></p>
<p>This is so this script will work dynamically with any size image, although relies on the use of <strong>getimagesize</strong>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p14code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p143"><td class="code" id="p14code3"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> imageResize<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: #339933;">,</span> <span style="color: #000088;">$target</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #b1b100;">if</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: #000088;">$height</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$percentage</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$width</span><span style="color: #009900;">&#41;</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;">$percentage</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</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: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$width</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/round" onclick="pageTracker._trackPageview('/outgoing/www.php.net/round?referer=');"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$width</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$percentage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$height</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/round" onclick="pageTracker._trackPageview('/outgoing/www.php.net/round?referer=');"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$height</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$percentage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">&quot;width=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$width</span><span style="color: #000099; font-weight: bold;">\&quot;</span> height=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$height</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Use:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p14code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p144"><td class="code" id="p14code4"><pre class="php" style="font-family:monospace;">$imagepath = &quot;/images/etc/image.jpg&quot;;
$image = getimagesize($imagepath);
// For Testing
// echo &quot;&lt;br /&gt;&quot;.$imagepath];
// echo &quot;&lt;br /&gt; 0 = &quot;.$logo[0];
// echo &quot;&lt;br /&gt; 1 = &quot;.$logo[1];
// echo &quot;&lt;br /&gt; 2 = &quot;.$logo[2];
// echo &quot;&lt;br /&gt; 3 = &quot;.$logo[3];
&nbsp;
&lt;img     src='$imagepath'
           alt=''
           title='' imageResize($image[0], $image[1],100) /&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/php/imageresize-inline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
