Foros del Web » Programando para Internet » PHP »

Redimensionar GIFs con fondos transparentes

Estas en el tema de Redimensionar GIFs con fondos transparentes en el foro de PHP en Foros del Web. Hola chicos, yo de nuevo, ahora con un problemita con la redimension de imagenes GIF transparentes. Bueno, al redimensionar una imagen GIF con fondo transparente, ...
  #1 (permalink)  
Antiguo 07/10/2009, 11:27
Avatar de JessicaTJ  
Fecha de Ingreso: enero-2007
Ubicación: 127.0.0.1
Mensajes: 472
Antigüedad: 17 años, 3 meses
Puntos: 25
Redimensionar GIFs con fondos transparentes

Hola chicos, yo de nuevo, ahora con un problemita con la redimension de imagenes GIF transparentes.

Bueno, al redimensionar una imagen GIF con fondo transparente, este se pierde, encontre esto:

Código PHP:
<?php
$imagen 
imagecreatefromgif('imagen.gif');
$back imagecolorallocatealpha($imagen255255255127);
imagefill($imagen11$back);
?>
Pero no encuentro la manera de integrarlo al codigo que utilizo, una clase que encontre aki en los foros, vendria a ser esta:

Código PHP:
<?php
    
class Imagen {
          var 
$entrada "";
          var 
$width 0;
          var 
$height 0;
          var 
$tipo 0;

          function 
Imagen($ent) {
                   
$this->entrada $ent;
                   list(
$wid$hei$tip) = getimagesize($ent);
                   
$this->width $wid;
                   
$this->height $hei;
                   
$this->tipo $tip;
          }

          function 
getThumb($w$h$salida$opc false) {
                   
$ent $this->entrada;
                   
$tip $this->tipo;
                   
$wid $this->width;
                   
$hei $this->height;

                   if (
$w) {
                      
$newwidth $w;
                      
$newheight round(($hei $wid) * $newwidth);
                   }  elseif (
$h) {
                      
$newheight $h;
                      
$newwidth round(($wid $hei) * $newheight);
                   }
                   
// Cargar la imagen
                   
$thumb imagecreatetruecolor($newwidth$newheight);
                   if (
$tip == 1) {
                      
$source imagecreatefromgif($ent);
                   }  elseif (
$tip == 2) {
                      
$source imagecreatefromjpeg($ent);
                   }  elseif (
$tip == 3) {
                      
$source imagecreatefrompng($ent);
                   }

                   
// Redimensionar
                   
imagecopyresampled($thumb$source0000$newwidth$newheight$wid$hei);

                   
// Mostrar la nueva imagen
                   
if ($opc) return $thumb;
                   else return 
imagejpeg($thumb$salida);
          }

          function 
getNothumb($w$h$salida$opc false) {
                   
$ent $this->entrada;
                   
$tip $this->tipo;
                   
$wid $this->width;
                   
$hei $this->height;

                   if (
$h) {
                      
$newheight $h;
                      
$newwidth round(($wid $hei) * $newheight);
                   }  else if (
$w) {
                      
$newwidth $w;
                      
$newheight round(($hei $wid) * $newwidth);
                   }
                   
// Cargar la imagen
                   
$thumb imagecreatetruecolor($newwidth$newheight);
                   if (
$tip == 1) {
                      
$source imagecreatefromgif($ent);
                   }  elseif (
$tip == 2) {
                      
$source imagecreatefromjpeg($ent);
                   }  elseif (
$tip == 3) {
                      
$source imagecreatefrompng($ent);
                   }

                   
// Redimensionar
                   
imagecopyresampled($thumb$source0000$newwidth$newheight$wid$hei);

                   
// Mostrar la nueva imagen
                   
if ($opc) return $thumb;
                   else return 
imagejpeg($thumb$salida);
          }

          function 
getCorte($we$he$salida$opc false) {
                   
$img $this->entrada;
                   
$wid $this->width;
                   
$hei $this->height;
                   
$tip $this->tipo;

                   if (
$wid $we $hei $he) {
                      
$hp $hei;
                      
$wp round(($we $he) * $hp);
                   }  else {
                      
$wp $wid;
                      
$hp round(($he $we) * $wp);
                   }

                   
$lp round(($wid $wp) / 2);
                   
$tp round(($hei $hp) / 2);

                   
$thumb imagecreatetruecolor($we$he);
                   if (
$tip == 1) {
                     
$source imagecreatefromgif($img);
                    }  elseif (
$tip == 2) {
                     
$source imagecreatefromjpeg($img);
                   }  elseif (
$tip == 3) {
                     
$source imagecreatefrompng($img);
                   }

                   
imagecopyresampled($thumb$source00$lp$tp$we$he$wp$hp);

                   if (
$opc) return $thumb;
                   else return 
imagejpeg($thumb$salida);
          }
    }

    if (isset(
$_GET["img"])) {
       
$img = new Imagen($_GET["img"]);
       
$tip $_GET["tip"];
       
$w $_GET["w"];
       
$h $_GET["h"];

       
header("Content-type: image/jpeg");
       if (
$tip == 0) {
          
imagejpeg($img->getThumb($w$h""true));
       }  elseif (
$tip == 1) {
          
imagejpeg($img->getNothumb($w$h""true));
       }  elseif (
$tip == 2) {
          
imagejpeg($img->getCorte($w$h""true));
       }
    }
?>
Ke esta aki:
http://www.forosdelweb.com/f91/redim...on-php-665923/

Alguna idea de como integrar la funcion para que los GIFs con fondo transparentes los redimensione tambien con el fondo transparente?

De corazon de nuevo agradecere mil su ayuda
  #2 (permalink)  
Antiguo 07/10/2009, 13:32
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Redimensionar GIFs con fondos transparentes

Tal vez te pueda servir esto: http://www.forosdelweb.com/f18/aport...te-1-a-692558/

Frase que use para buscar y encontrar ese resultado: php gif transparente
__________________
- León, Guanajuato
- GV-Foto
  #3 (permalink)  
Antiguo 07/10/2009, 13:47
Avatar de JessicaTJ  
Fecha de Ingreso: enero-2007
Ubicación: 127.0.0.1
Mensajes: 472
Antigüedad: 17 años, 3 meses
Puntos: 25
Hola Triby, gracias por tu respuesta.

De hecho si lo lei antes de postear, pero de nuevo me kede en las nubes, no pude implementarlo en el script que coloke.

Alguna otra pista de como hacerlo?

Nup, me volvi a kedar en las mismas xD

Alguien que sepa como tratar imagenes y si podria ayudarme por favor?

Última edición por GatorV; 12/10/2009 a las 10:32
  #4 (permalink)  
Antiguo 12/10/2009, 10:20
Avatar de JessicaTJ  
Fecha de Ingreso: enero-2007
Ubicación: 127.0.0.1
Mensajes: 472
Antigüedad: 17 años, 3 meses
Puntos: 25
Respuesta: Redimensionar GIFs con fondos transparentes

Nada de nada

Algun alma caritativa ahi afuera que pueda ayudarme?
De verdad agradecere muchisimo su ayuda
__________________
٩(͡๏̯͡๏)۶ || ٩(͡๏̯͡๏)۶
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:40.