Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   PHP (https://www.clubdelphi.com/foros/forumdisplay.php?f=15)
-   -   Como subir imagenes de tamaño definido, transparentes o no. PNG, JPG y GIF (https://www.clubdelphi.com/foros/showthread.php?t=67982)

CniL 18-05-2010 02:16:50

Como subir imagenes de tamaño definido, transparentes o no. PNG, JPG y GIF
 
Bueno, no me atribuyo la autoría de este código, si compilarlo, ya que son piezas de varios códigos y me ayuda bastante a la hora de crear servicios de subida de imágenes donde el cliente no tenga que preocuparse más que de subir el archivo.

Código PHP:

    if($_FILES['*NOMBRE DE VARIABLE DEL POST*']['name'])
        {
        
$tmpname=$_FILES['logo']['tmp_name'];
        
$datos getimagesize($tmpname);
//LOS NOMBRES SON ESTANDAR SEGÚN FECHA, de modo tal no se repitan los nombres (Tambien pueden dejar los nombres originales)
        
if($datos[2]==1){$nombre="img-".date("Y-m-d-H-i-s")."1.gif";}
        if(
$datos[2]==2){$nombre="img-".date("Y-m-d-H-i-s")."1.jpg";}
        if(
$datos[2]==3){$nombre="img-".date("Y-m-d-H-i-s")."1.png";}
//AHORA LLAMO LA FUNCIÓN
        
$datos2=crearimagen($tmpname,*TAMAÑO FIJO X,TAMAÑO FIJO Y,"../imagenes",$nombre);
        
$evento="./imagenes/".$datos2;
//acá ya puedo subir a una base de datos el nombre de la imagen
        
}

// ESTA ES LA FUNCIÓN
function crearimagen($imagen,$anchura,$altura,$directorio,$nombre)
    {
    
$datos getimagesize($imagen);
    if(
$datos[2]==1){$img = @imagecreatefromgif($imagen);}
    if(
$datos[2]==2){$img = @imagecreatefromjpeg($imagen);}
    if(
$datos[2]==3){$img = @imagecreatefrompng($imagen);}
    
$thumb imagecreatetruecolor($anchura,$altura); 
    if(
$datos[2]==3)
        {
        
imagealphablending($thumbfalse);
        
imagesavealpha($thumbtrue);
        }
    
$colorTransparancia=imagecolortransparent($img);
    if(
$colorTransparancia!=-1)
        {
        
$colorTransparente imagecolorsforindex($img$colorTransparancia);
        
$idColorTransparente imagecolorallocatealpha($thumb$colorTransparente['red'], $colorTransparente['green'], $colorTransparente['blue'], $colorTransparente['alpha']);
        
imagefill($thumb00$idColorTransparente);
        
imagecolortransparent($thumb$idColorTransparente);
        }
    
imagecopyresized($thumb$img0000$anchura$altura$datos[0], $datos[1]);
    if(
$datos[2]==1){imagegif($thumb"./".$directorio."/".$nombre);}
    if(
$datos[2]==2){imagejpeg($thumb"./".$directorio."/".$nombre75);}
    if(
$datos[2]==3){imagepng($thumb"./".$directorio."/".$nombre); }
    
unlink($imagen);
    return(
$nombre);
    } 


CniL 18-05-2010 02:17:38

Bueno, demás decir que Pueden modificarlo a gusto y tiene algunas consultas no necesarias, lo importante es la función.


La franja horaria es GMT +2. Ahora son las 01:19:03.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi