but now what i want it to do is see what type of image it is, and if its a jpg, do imagejpg, if its a gif, do imagegif and if its a png do imagepng.
now so far this totally works. except for with PNG, it gives me this error:
so here is my code:Fatal error: imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png: fatal libpng error: zlib error in /website/file.php on line 155
Code: Select all
//the uploaded file name:
$filename = basename( $_FILES['uploadedfile']['name']);
$width = 200;
$height = 200;
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
$image_p = imagecreatetruecolor($width, $height);
//get evrything into variables..
$newname2 = explode('.', $filename, 2);
$name1 = $newname2[0]; // if filename == "test1.jpg", will print: "test1"
$ext1 = $newname2[1]; // if filename == "test1.jpg", will print: "jpg"
//my if statements for image types
if ( $newname2[1] == "jpg" ) {
$image = imagecreatefromjpeg($filename);
}
if ( $newname2[1] == "png" ) {
$image = imagecreatefrompng($filename);
}
if ( $newname2[1] == "gif" ) {
$image = imagecreatefromgif($filename);
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
//now add the 1st part of the filename, plus the _thm, PLUS the extention
$newname3 = $name1 . "_thm" . "." . $ext1;
//code that actually saves it as a new file:
if ( $newname2[1] == "jpg" ) {
imagejpeg($image_p, $newname3, 100);
}
if ( $newname2[1] == "png" ) {
imagepng($image_p, $newname3, 100);
}
if ( $newname2[1] == "gif" ) {
imagegif($image_p, $newname3, 100);
}and again, the GIF and JPG work perfectly. but not the PNG.
little help?