Respuesta: libreria gd aki te dejo mi codigo k me da algunos errores como :
Warning: getimagesize() [function.getimagesize]: Unable to access ../img/06452d54
donde crees que esta el problema, no le veo fallos al codigo pro eso toy mu perdio, un saludo
//----------------------------------------
$logo = substr(md5(uniqid(rand())),0,8).$_FILES['logo_img_emp']['name'];
$img_1 = substr(md5(uniqid(rand())),0,8).$_FILES['img1_emp']['name'];
$img_2 = substr(md5(uniqid(rand())),0,8).$_FILES['img2_emp']['name'];
$img_3 = substr(md5(uniqid(rand())),0,8).$_FILES['img3_emp']['name'];
$img_4 = substr(md5(uniqid(rand())),0,8).$_FILES['img4_emp']['name'];
//subimos las 4 fotos
if (is_uploaded_file($_FILES['logo_img_emp']['tmp_name'])) {
copy($_FILES['logo_img_emp']['tmp_name'],'../img/'.$logo);
}
if (is_uploaded_file($_FILES['img1_emp']['tmp_name'])) {
copy($_FILES['img1_emp']['tmp_name'],'../img/'.$img_1);
}
if (is_uploaded_file($_FILES['img2_emp']['tmp_name'])) {
copy($_FILES['img2_emp']['tmp_name'],'../img/'.$img_2);
}
if (is_uploaded_file($_FILES['img3_emp']['tmp_name'])) {
copy($_FILES['img3_emp']['tmp_name'],'../img/'.$img_3);
}
if (is_uploaded_file($_FILES['img4_emp']['tmp_name'])) {
copy($_FILES['img4_emp']['tmp_name'],'../img/'.$img_4);
}
# ruta de la imagen a redimensionar
$imagen="../img/".$logo;
#ruta de la imagen final, si se pone el mismo nombre que la imagen, esta se sobreescribe
$imagen_final=$logo;
$ancho_nuevo=80;
$alto_nuevo=60;
## FIN CONFIGURACION #############################
redim ($imagen,$imagen_final,$ancho_nuevo,$alto_nuevo);
function redim($ruta1,$ruta2,$ancho,$alto)
{
# se obtene la dimension y tipo de imagen
$datos=getimagesize ($ruta1);
$ancho_orig = $datos[0]; # Anchura de la imagen original
$alto_orig = $datos[1]; # Altura de la imagen original
$tipo = $datos[2];
if ($tipo==1){ # GIF
if (function_exists("imagecreatefromgif"))
$img = imagecreatefromgif($ruta1);
else
return false;
}
else if ($tipo==2){ # JPG
if (function_exists("imagecreatefromjpeg"))
$img = imagecreatefromjpeg($ruta1);
else
return false;
}
else if ($tipo==3){ # PNG
if (function_exists("imagecreatefrompng"))
$img = imagecreatefrompng($ruta1);
else
return false;
}
# Se calculan las nuevas dimensiones de la imagen
if ($ancho_orig>$alto_orig)
{
$ancho_dest=$ancho;
$alto_dest=($ancho_dest/$ancho_orig)*$alto_orig;
}
else
{
$alto_dest=$alto;
$ancho_dest=($alto_dest/$alto_orig)*$ancho_orig;
}
// imagecreatetruecolor, solo estan en G.D. 2.0.1 con PHP 4.0.6+
$img2=@imagecreatetruecolor($ancho_dest,$alto_dest ) or $img2=imagecreate($ancho_dest,$alto_dest);
// Redimensionar
// imagecopyresampled, solo estan en G.D. 2.0.1 con PHP 4.0.6+
@imagecopyresampled($img2,$img,0,0,0,0,$ancho_dest ,$alto_dest,$ancho_orig,$alto_orig) or imagecopyresized($img2,$img,0,0,0,0,$ancho_dest,$a lto_dest,$ancho_orig,$alto_orig);
// Crear fichero nuevo, según extensión.
if ($tipo==1) // GIF
if (function_exists("imagegif"))
imagegif($img2, $ruta2);
else
return false;
if ($tipo==2) // JPG
if (function_exists("imagejpeg"))
imagejpeg($img2, $ruta2);
else
return false;
if ($tipo==3) // PNG
if (function_exists("imagepng"))
imagepng($img2, $ruta2);
else
return false;
return true;
}
?> |