title: How to hide image path from source code using PHP
body: <p>I want to hide image path from website. To do that first I did this:</p>
  
  <pre><code>&lt;?php
  // get image path
  $path = 'images/profiles/uploads/' . $list['thumbnail'];
  $type = pathinfo($path, PATHINFO_EXTENSION);
  $data = file_get_contents($path);
  $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
  ?&gt;
  </code></pre>
  
  <p>But this is very slow, So I try to implement like this, but code is not working: </p>
  
  <p><code>download.php</code>:</p>
  
  <pre><code>function setImgDownload($imagePath) {           
      $image = imagecreatefromjpeg($imagePath);
      header('Content-Type: image/jpeg');
      imagejpeg($image);
  }
  </code></pre>
  
  <p><code>mypage.php</code>:</p>
  
  <pre><code>&lt;?php include('download.php'); ?&gt;
  &lt;img src="&lt;?php setImgDownload('images/Chrysanthemum.jpg') ?&gt;" width="300"/&gt;
  </code></pre>
  
  <p>If I put function and call function at the same page it's working:</p>
  
  <pre><code>function setImgDownload($imagePath) {
      $image = imagecreatefromjpeg($imagePath);
      header('Content-Type: image/jpeg');
      imagejpeg($image);
  }
  
  setImgDownload('images/Chrysanthemum.jpg');
  </code></pre>
  
  <p>How to keep function in separate page?</p>