title: PHP image Streaming in Joomla with MVC
body: <p>Hello I have a problem that has me a bit stumped!</p>
  
  <p>I'm attempting to implement image streaming inside a joomla component. 
  The Image folder is shared by a number of sites on the server outside the Virtual Host so cannot be accessed from the site directly.</p>
  
  <p>I have tried the following which works:</p>
  
  <p>testfile.php</p>
  
  <pre><code>&lt;img src="testImgGen.php" /&gt;
  </code></pre>
  
  <p>testImgGen.php</p>
  
  <pre><code>?php
  $im = imagecreatefrompng("c:xampp/htdocs/docs/images/282/Img1.png");
  header('Content-Type: image/png');
  imagepng($im);
  imagedestroy($im);
  exit; 
  ?&gt;
  </code></pre>
  
  <p>This works fine</p>
  
  <p>so Attempting to Implement inside Joomla component:
  src link inside view :</p>
  
  <pre><code>"&lt;img src='?option=com_cat&amp;view=item&amp;task=prevIMG&amp;tmpl=Component&amp;fid=282&amp;file=Img1.png' /&gt;"
  </code></pre>
  
  <p>inside the controller: </p>
  
  <pre><code>function prevIMG(){
  require_once(JPATH_COMPONENT.DS.'models'.DS.'details.php');
  $model=new CatModelCat_details ;
  $model-&gt;prevImg();
  }
  </code></pre>
  
  <p>Inside the Model: </p>
  
  <pre><code>function prevImg(){
      $doc =&amp; JFactory::getDocument();
      $doc-&gt;setMimeEncoding('image/png');
      $img = "C:xampp/htdocs/docs/images/".$_GET[fid]."/".$_GET[file];
      $im = imagecreatefrompng($img);
      imagepng($im);
      imagedestroy($im);
          }
  </code></pre>
  
  <p>and this is returning ... nothing 
  I have tried readfile()/get_contents_fromfile()
  I've Created Blank Templates that pass through no headers and have used "header('Content-Type: image/png');" 
  I'm starting to get to the bash head against desk stage!<br>
  if anyone has any advise/if I'd be great full to hear it! </p>
  
  <p>I have occasional had the image output as a string! or I get  "interpreted as doc with mime type image" or "interpreted as image with mime type test/html"</p>
  
  <p>Cheers </p>
  
  <p>Kiran</p>