<?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>Webdevelopment at huuah.com &#187; image</title>
	<atom:link href="http://huuah.com/tag/image/feed/" rel="self" type="application/rss+xml" />
	<link>http://huuah.com</link>
	<description>webdevelopment, cms, php, javascript etc</description>
	<lastBuildDate>Sun, 20 Nov 2011 20:30:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Faster image scaling within TYPO3 extension</title>
		<link>http://huuah.com/faster-image-scaling-within-typo3-extension/</link>
		<comments>http://huuah.com/faster-image-scaling-within-typo3-extension/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 20:28:43 +0000</pubDate>
		<dc:creator>js - huuah</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[TYPO3]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://huuah.com/?p=387</guid>
		<description><![CDATA[<p>During the development of a gallery extension for TYPO3, I was having some performance issues when during the on-the-fly image scaling.</p>
<p>When displaying the images in the frontend, I would scale the images to a size specified in the plugin configuration. I was using the following code:</p>
<p>The $row[image] would&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>During the development of a gallery extension for TYPO3, I was having some performance issues when during the on-the-fly image scaling.</p>
<p>When displaying the images in the frontend, I would scale the images to a size specified in the plugin configuration. I was using the following code:</p>
<pre class="brush: php; title: ; notranslate">
...
$imageConf['file'] = $row[image];
$imageConf['file.']['maxH'] = $this-&gt;conf[largeMaxH];
$imageConf['file.']['maxW'] = $this-&gt;conf[largeMaxW];
$thumbnailImage = $this-&gt;cObj-&gt;IMG_RESOURCE($imageConf);
...
</pre>
<p>The $row[image] would contain the image file to be displayed and the maxH and maxW is being set to the image sizes from the plugin configuration. When loading the page every image would be resized to the correct size, but when a single gallery reached about 100+ images this process started to perform very poorly. Actually is was slow &#8211; very slow.</p>
<p>What to do?! </p>
<p>Well, I figured out that I would try to make a function, where the image only would get resized once and then reused. I created an extra database field (a blob-field would be preferred) for storing the cached information.</p>
<p>Generating the images is still done with the above example, but now the filename for the resized image is being saved in the database. I choose a setup using a multidimensional array with keys representing the image height and width like this:</p>
<pre class="brush: php; highlight: [7]; title: ; notranslate">
...
$imageConf['file'] = $row[image];
$imageConf['file.']['maxH'] = $this-&gt;conf[largeMaxH];
$imageConf['file.']['maxW'] = $this-&gt;conf[largeMaxW];
$thumbnailImage = $this-&gt;cObj-&gt;IMG_RESOURCE($imageConf);

$cached[$this-&gt;conf[thumbnailMaxW]][$this-&gt;conf[thumbnailMaxH]] = $thumbnailImage;
...
</pre>
<p>Until now there is no change in the performance as every image still is being resized on the fly. The last piece of the puzzle is to check whether or not there exists a cached image. To do this I am using two check:</p>
<pre class="brush: php; highlight: [1,2,10]; title: ; notranslate">
$thumbnailImage = $cached[$this-&gt;conf[largeMaxW]][$this-&gt;conf[largeMaxH]];
if ($thumbnailImage == &quot;&quot; || ! file_exists($thumbnailImage)) {
  $imageConf['file'] = $row[image];
  $imageConf['file.']['maxH'] = $this-&gt;conf[largeMaxH];
  $imageConf['file.']['maxW'] = $this-&gt;conf[largeMaxW];
  $thumbnailImage = $this-&gt;cObj-&gt;IMG_RESOURCE($imageConf);

  $cached[$this-&gt;conf[thumbnailMaxW]][$this-&gt;conf[thumbnailMaxH]] = $thumbnailImage;

  $updateCache = 1;
}
</pre>
<p>First check is to see if the database contains information about a cached image and the second check is to see if the cache image still exists within the typo3temp directory. If one or both of these check fails, then a new cached image will be generated and the $updateCache is set to 1 indicating that the database should be updated later on in the script.</p>
<p>It&#8217;s a while since I made the actual code and I cannot remember the exact render times, but there was a massive performance boost in my extension.</p>
]]></content:encoded>
			<wfw:commentRss>http://huuah.com/faster-image-scaling-within-typo3-extension/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

