This code works perfectly for jpgs and gifs, yet it dies for pngs. It dies out saying my message "Error MT 5"

$target_id = imagecreatetruecolor($dest_x, $dest_y) or die("Error MT 2");
$target_pic = imagecopyresampled($target_id,$source_id_original, 0, 0, 0, 0, $dest_x, $dest_y, $size[0],$size[1]) or die("Error MT 3");
$thumblink = $thumb_dir.$prefix.$name;
if (ereg("\.gif$", $name))
{
	$source_id = imagegif($target_id,$thumblink, $quality);
	$source_id_original = imagecreatefromgif($thumblink);
}
if (ereg("\.jpg$", $main) or ereg("\.jpeg$", $main)) 
{
	$source_id = imagejpeg($target_id,$thumblink, $quality);
	$source_id_original = imagecreatefromjpeg($thumblink);
}
if (ereg("\.png$", $name))
{
	$source_id = imagepng($target_id,$thumblink, $quality) or die("Error MT 4");
	$source_id_original = imagecreatefrompng($thumblink) or die("Error MT 5");
}

    First thing I would do is use the [man]gd_info[/man] function to verify that your GD installation supports PNG images. If that's not the problem, then you might want to turn on all error reporting to see if PHP outputs any info to help you determine what the problem is:

    <?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    

    (Once you finish debugging, you may then want to comment those lines out.)

      I def have PNG support from phpinfo and gd_info. Here are some errors:

      Warning: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib error in /var/www/vhosts/behance.net/httpdocs/includes/form_functions.php on line 122
      
      Warning: imagepng() [function.imagepng]: gd-png error: setjmp returns error n line 122
      
      Warning: imagecreatefrompng() [function.imagecreatefrompng]: gd-png: fatal libpng error: Read Error: truncated data in  on line 123
      
      Warning: imagecreatefrompng() [function.imagecreatefrompng]: gd-png error: setjmp returns error condition in  on line 123
      
      Warning: imagecreatefrompng() [function.imagecreatefrompng]: '/root/httpdocs/images/temp/500001183768352.png' is not a valid PNG file in / on line 123
      

      the last error really confuses me because it was made in photoshop from a screenshot

        quality

        Compression level: from 0 (no compression) to 9. 

        for imagepng

          Write a Reply...