title: php resize script doesn't work for transparent gif's
body: <p>How Can I get this working for transparent gif's and png's?</p>
  
  <pre><code>function resizeImage($image,$newImage,$target_width,$target_height, $type="") {
      if (is_file($image)) {
          if($type == ".gif"){
              $image_org=@imagecreatefromgif($image);
          }else{
              $image_org=@imagecreatefromjpeg($image);
          }
          if ($image_org) {
              list($w,$h,$type,$attr) = getimagesize($image);
              $factor=C_Image_Custom::calcRescaleFactor($w,$h,$target_width,$target_height);
  
              if ($factor&gt;1) {
                  $image_w = $w / $factor;
                  $image_h = $h / $factor;
              } else {
                  $image_w = $w;
                  $image_h = $h;
              }       
  
          //Note: PHP with GD2.0 required for imagecreatetruecolor
          $img_copy = imagecreatetruecolor($image_w, $image_h);
          imagecopyresampled($img_copy, $image_org, 0, 0, 0, 0, $image_w, $image_h, $w, $h);
  
              if (@imagejpeg($img_copy, $newImage, 80)) {
                  chmod($newImage,0777);
              }   else {
                  echo("&lt;b&gt;Error: &lt;/b&gt;Unable to create image $newImage. Check directory permissions.");
              }   
  
            imagedestroy($image_org);
              imagedestroy($img_copy);
          }   
      }   
  </code></pre>