title: PHP dynamic images
body: <p>I have taken over a CodeIgniter PHP site that dynamically generates resized images and thumbnails. </p>
  
  <p>Here is an example of an <code>img</code> tag in the site that generates a 100px by 100px thumbnail:</p>
  
  <pre><code>&lt;img src="/media/image/ImageName.jpg/100/100" /&gt;
  </code></pre>
  
  <p>This is generated by using the helper:</p>
  
  <pre><code>echo img('media/image/ImageName.jpg/100/100');
  </code></pre>
  
  <p>There is some logic in the image function in the media controller, which first checks a cache folder and then serves the cached image if it exists.</p>
  
  <p>It still seems that this is not an elegant approach and looking at the way other PHP frameworks like SilverStripe do it, it would be better to do something like this: </p>
  
  <pre><code>echo img_link('ImageName.jpg', 100, 100);
  </code></pre>
  
  <p>This new <code>img_link</code> function in a helper would check for the cached image first and write the link directly to the image file or generate the new image and pass the direct link to the html.</p>
  
  <p>My thoughts are that if PHP is serving every <code>img</code> using this type of code</p>
  
  <pre><code>$this-&gt;output-&gt;set_content_type('jpeg')-&gt;set_output(file_get_contents($file_path));
  </code></pre>
  
  <p>it will always be inefficient.</p>
  
  <p>Thoughts anyone?</p>