title: How to create retina image from JPEG with PHP
body: <p>A few months ago i wrote the following script to convert an uploaded image with <code>PHP to Retina</code> and <code>non</code> retina images. The iphone app that was working with this script only used PNG images, so i wrote the script to work with PNG's.</p>
  
  <pre><code>$filename = dirname(__FILE__)."/uploads/" . $_FILES['myFile']['name'];
  $filename = str_replace('.png', '_retina.png', $filename);
  file_put_contents($filename, file_get_contents($_FILES['myFile']['tmp_name']));
  
  $image_info = getimagesize($filename);
  $image = imagecreatefrompng($filename);
  
  $width = imagesx($image);
  $height = imagesy($image);
  
  $new_width = $width/2.0;
  $new_height = $height/2.0;
  
  $new_image = imagecreatetruecolor($new_width, $new_height);
  
  imagealphablending($new_image, false);
  imagesavealpha($new_image, true);
  $color = imagecolortransparent($new_image, imagecolorallocatealpha($new_image, 0, 0, 0, 127));
  imagefill($new_image, 0, 0, $color);
  
  imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  
  $new_filename = str_replace('_retina.png', '.png', $filename);
  
  imagepng($new_image, $new_filename);
  </code></pre>
  
  <p>Now i need the same script but then to be used with Jpeg images. Because the iphone app will load images with a higher resolution we chose Jpeg. But i can't figure out how to make that work.</p>
  
  <p><strong>What i've tried so far:</strong></p>
  
  <ul>
  <li>Replacing <code>imagecreatefrompng</code> with the jpeg version</li>
  <li>Replacing <code>imagepng</code> with the jpeg version</li>
  </ul>
  
  <p>Does anybody have a working example or useful link that can set me to the right direction?</p>