Hice una función para manejar archivos jpg y png, pero me sale un error al intentar cargar un archivo png.creando archivos png
Ésta es la función:
function createImg ($type, $src, $dst, $width, $height, $quality) {
$newImage = imagecreatetruecolor($width,$height);
if ($type == "jpg/jpeg") {
//imagecreatefromjpeg() returns an image identifier representing the image obtained from the given filename.
$source = imagecreatefromjpeg($src);
}
else if ($type == "png") {
//imagecreatefrompng() returns an image identifier representing the image obtained from the given filename.
$source = imagecreatefrompng($src);
}
imagecopyresampled($newImage,$source,0,0,0,0,$width,$height,getWidth($src),getHeight($src));
if ($type == "jpg/jpeg") {
//imagejpeg() creates a JPEG file from the given image.
imagejpeg($newImage,$dst,$quality);
}
else if ($type == "png") {
//imagepng() creates a PNG file from the given image.
imagepng($newImage,$dst,$quality);
}
return $dst;
}
funciona como debería con jpg, png, pero con consigo este error msg:
Advertencia: imagepng() [function.imagepng ]: gd-png: error de libpng fatal: zlib no pudo inicializar el compresor - error de transmisión en E: ... \ php \ functions.upload.php en la línea 48
Advertencia: imagepng() [function.imagepng] : error gd-png: setjmp vuelve condición de error en E: ... \ php \ functions.upload.php en la línea 48
EDIT:
acabo de cambiar quitado la imagepng(); y usé solo imagejpeg y funcionó así, solo quiero que se guarden los archivos jpg de todos modos. ¡Gracias!
lo que esta en la línea 48 –