title: Failing in creating thumbs for all mysql post img attachments
body: <p>I am trying to save a copy of all attached images in my site.</p>
  
  <p>Load time si too big so I thought generating thumbnails to show in listing pages was not a bad idea,</p>
  
  <p>This is how I'm trying:</p>
  
  <pre><code> &lt;?php
      include('basedatos.php');
      class ImgResizer {
          var $originalFile = '$newName';
          function ImgResizer($originalFile = '$newName') {
              $this -&gt; originalFile = $originalFile;
          }
          function resize($newWidth, $targetFile) {
  
              if (empty($newWidth) || empty($targetFile)) {
                  return false;
              }
              $src = imagecreatefromjpeg($this -&gt; originalFile);
              list($width, $height) = getimagesize($this -&gt; originalFile);
              $newHeight = ($height / $width) * $newWidth;
              $tmp = imagecreatetruecolor($newWidth, $newHeight);
              imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
              if (exif_imagetype($tmp) != IMAGETYPE_JPEG) {
                  imagecreatefromjpeg($tmp, $targetFile, 95);
              }else if(exif_imagetype($tmp) != IMAGETYPE_PNG){
                  imagecreatefrompng($tmp, $targetFile, 95);
              }else if(exif_imagetype($tmp) != IMAGETYPE_GIF){
                  imagecreatefromgif($tmp, $targetFile, 95);
              }else die('invalid image format');
  
          }
  
      }
      $query = "SELECT * FROM media where iframe &lt;&gt; 1";
      $mediafiles = mysql_query($query);
      while($details = mysql_fetch_array($mediafiles))
      {   // Copy each file from its temp directory to $ROOT
  
          $temp = '/home/deia1/public_html/'.$details['url'];
          $path = '/home/deia1/public_html/files/uploads/thumbs/'.str_replace('files/uploads/','',$details['url']);
  
          echo "$temp&lt;br&gt;";
          if(is_dir('/home/deia1/public_html/files/uploads/thumbs/')){
              echo "$path&lt;br&gt;";
  
                  $work = new ImgResizer($temp);
                  $work -&gt; resize(300, $path);
  
          }
      }
           ?&gt;
  </code></pre>
  
  <p>Notices i have two echo's there,</p>
  
  <p>Thats what they log (for the first item, the rest of the errors look pretty much the same):</p>
  
  <blockquote>
    <p>/home/deia1/public_html/files/uploads/Detalle-Magrana.jpg</p>
    
    <p>/home/deia1/public_html/files/uploads/thumbs/Detalle-Magrana.jpg</p>
    
    <p>Warning: Wrong parameter count for imagecreatefrompng() in
    /home/deia1/public_html/includes/thumbs.php on line 21
    /home/deia1/public_html/files/uploads/video.png
    /home/deia1/public_html/files/uploads/thumbs/video.png</p>
    
    <p>Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]:
    gd-jpeg: JPEG library reports unrecoverable error: in
    /home/deia1/public_html/includes/thumbs.php on line 13</p>
    
    <p>Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]:
    '/home/deia1/public_html/files/uploads/video.png' is not a valid JPEG
    file in /home/deia1/public_html/includes/thumbs.php on line 13</p>
  </blockquote>
  
  <p>Any idea what am I doing wrong?</p>
  
  <p>-EDIT-</p>
  
  <p>I need to save a resized copy of the image in /thumbs/ path, I don't want to resize the original image.</p>
  
  <p>-EDIT2-</p>
  
  <p>This is the error I get with current code that @Bass Jobsen  suggested for the PNG files, and they generate white images. for jpg seems to work ferfectly:</p>
  
  <pre><code>Warning: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib failed to initialize compressor -- stream error in /home/deia1/public_html/includes/thumbs.php on line 60
  
  Warning: imagepng() [function.imagepng]: gd-png error: setjmp returns error condition in /home/deia1/public_html/includes/thumbs.php on line 60
  </code></pre>