<?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>Georgi Mitev &#124; Learn Scripts Tutorials &#124; PHP Cron Mysql Flash &#187; resize image script</title>
	<atom:link href="http://georgi-mitev.com/tag/resize-image-script/feed/" rel="self" type="application/rss+xml" />
	<link>http://georgi-mitev.com</link>
	<description>Georgi Mitev&#039;s blog for scripts tutorials and something else</description>
	<lastBuildDate>Thu, 29 Apr 2010 09:00:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dynamically (on request) Resize Images with PHP</title>
		<link>http://georgi-mitev.com/2009/03/19/resize-image-using-php/</link>
		<comments>http://georgi-mitev.com/2009/03/19/resize-image-using-php/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 07:51:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[joomla resize image]]></category>
		<category><![CDATA[php resize image]]></category>
		<category><![CDATA[resize image]]></category>
		<category><![CDATA[resize image script]]></category>
		<category><![CDATA[resize script]]></category>

		<guid isPermaLink="false">http://georgi-mitev.com/?p=142</guid>
		<description><![CDATA[Hello   today i&#8217;m going to talk about resizing your the images in your site.
So let&#8217;s say for example that you have a CMS system &#8211; like Joomla for example. In the administration you usually have functionality like &#8211; uploading images and linking them in your content.
But often the problem with that is that [...]]]></description>
			<content:encoded><![CDATA[<p>Hello <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  today i&#8217;m going to talk about resizing your the images in your site.<br />
So let&#8217;s say for example that you have a CMS system &#8211; like Joomla for example. In the administration you usually have functionality like &#8211; uploading images and linking them in your content.<br />
But often the problem with that is that usually the customers will upload too large images (copied in raw jpeg directly from their cameras) and when they link them to the content of their website, it get&#8217;s really messy.<br />
Anyway you can fix this by writing some script that directly resize the image to some resolution like 500px/* for example, but what will happen if you want to put <a href="http://www.huddletogether.com/projects/lightbox/">lightbox </a>or something other to show the image in large resolution, or you just want to put some function to download the original file etc. You simply can&#8217;t because the image was resized at the moment it was uploaded on the server.</p>
<p><strong>How about dinamically resize the image at the very  moment that client requests it? </strong></p>
<p>So that way we wont have a big image that the client has to download, and at the same time we will still have the original, good resolution copy of the image, in case that we need it. We can also use the following PHP script for creating thumbnails.</p>
<p>Well &#8211; as you will see below it&#8217;s not hard at all to do it,  i mean not hard at all <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span id="more-142"></span>So what we are about to do is create a PHP file that we are going to use for resize of the image.</p>
<p>We are going to pass the images to it like $_GET parameters, for example:</p>
<p>resizeImage.php?image=/images/file.jpg</p>
<p>and the image on our site will look like &lt;img src=&#8221;resizeImage.php?image=/images/file.jpg&#8221; alt=&#8221;#&#8221; /&gt;</p>
<p>so let&#8217;s get to the script:<br />
filename: resizeImage.php<br />
<code>$f = htmlspecialchars($_GET['image']);</code></p>
<p>$im = imagecreatefromjpeg($f);<br />
//we create the image from the $_GET path<br />
$a  = getimagesize($f);</p>
<p>$newwidth = 400;<br />
//we decide to make the picture 400px width and depends on the width/height ratio we calculate what should be the height<br />
if ($a[0] &gt; $a[1]) {<br />
$percentage = $a[0] / $a[1];<br />
$newheight = 400 / $percentage;<br />
} else {<br />
$percentage = $a[1] / $a[0];<br />
$newheight = 400 * $percentage;<br />
}</p>
<p>$d=imagecreatetruecolor($newwidth,$newheight);</p>
<p>imagecopyresized($d, $im, 0, 0, 0, 0, $newwidth, $newheight, $a[0], $a[1]);</p>
<p>header(&#8220;Content-type: image/jpeg&#8221;);<br />
//we modify the header to treat resizeImage.php as image </p>
<p>imagejpeg($d, null, 90 );<br />
//here we show our modified image at quality 90</p>
<p>imagedestroy($im);<br />
//we free the memory (not necessary, but it&#8217;s good practic)<br />
imagedestroy($d);<br />
?&gt;</p>
<p>So that&#8217;s about it <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I hope it was useful for you.<br />
Anyway i wrote another script that replaces all the content from your site ( for example joomla site)<br />
and basically does the following: when we have <img src="file.jpg" alt="" /> it uses regular expression to replace it like this <img src="imageResize.php?img=file.jpg" alt="" /> and basically it does all the work for you with the replacing <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
if you need it i can post it here as well <img src='http://georgi-mitev.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>have a nice one -)</p>
]]></content:encoded>
			<wfw:commentRss>http://georgi-mitev.com/2009/03/19/resize-image-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
