Foros del Web » Programando para Internet » PHP »

redimensionar imagen BMP

Estas en el tema de redimensionar imagen BMP en el foro de PHP en Foros del Web. Hola amigos tengo el siguiente codigo, pero consigo redimensianar todas menos el formato bmp. A ver si me podeis ayudar. Gracias Código PHP: function  redimensionar ...
  #1 (permalink)  
Antiguo 28/05/2007, 10:53
 
Fecha de Ingreso: enero-2007
Mensajes: 77
Antigüedad: 17 años, 2 meses
Puntos: 1
redimensionar imagen BMP

Hola amigos tengo el siguiente codigo, pero consigo redimensianar todas menos el formato bmp.

A ver si me podeis ayudar. Gracias

Código PHP:
function redimensionar($anchura,$hmax,$nombre)
{
    
$datos getimagesize($nombre);
    
    if(
$datos[2]==1){$img = @imagecreatefromgif($nombre);}
    if(
$datos[2]==2){$img = @imagecreatefromjpeg($nombre);}
    if(
$datos[2]==3){$img = @imagecreatefrompng($nombre);}
    if(
$datos[2]==6){$img = @imagecreatefromwbmp($nombre);}
    
    
$ratio = ($datos[0] / $anchura);
    
$altura = ($datos[1] / $ratio);
    
    if(
$altura>$hmax){$anchura2=$hmax*$anchura/$altura;$altura=$hmax;$anchura=$anchura2;}
    
    
$thumb imagecreatetruecolor($anchura,$altura);
    
    
imagecopyresampled($thumb$img0000$anchura$altura$datos[0], $datos[1]);
    
    if(
$datos[2]==1){header("Content-type: image/gif"); imagegif($thumb);}
    if(
$datos[2]==2){header("Content-type: image/jpeg");imagejpeg($thumb);}
    if(
$datos[2]==3){header("Content-type: image/png");imagepng($thumb); }
    if(
$datos[2]==6){header("Content-type: image/vnd.wap.wbmp");imagewbmp($thumb); }
    
imagedestroy($thumb);
}

if(isset(
$_GET['ancho'])&&isset($_GET['alto'])&&isset($_GET['name']))
{
    
redimensionar($_GET['ancho'],$_GET['alto'],$_GET['name']);
    exit;

  #2 (permalink)  
Antiguo 28/05/2007, 10:59
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Re: redimensionar imagen BMP

La libreria GD no tiene soporte para BMP, pero puedes usar esta funcion:
Código PHP:
function ConvertBMP2GD($src$dest false) {
if(!(
$src_f fopen($src"rb"))) {
return 
false;
}
if(!(
$dest_f fopen($dest"wb"))) {
return 
false;
}
$header unpack("vtype/Vsize/v2reserved/Voffset"fread($src_f,
14));
$info unpack("Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vimportant",
fread($src_f40));

extract($info);
extract($header);

if(
$type != 0x4D42) { // signature "BM"
return false;
}

$palette_size $offset 54;
$ncolor $palette_size 4;
$gd_header "";
// true-color vs. palette
$gd_header .= ($palette_size == 0) ? "\xFF\xFE" "\xFF\xFF";
$gd_header .= pack("n2"$width$height);
$gd_header .= ($palette_size == 0) ? "\x01" "\x00";
if(
$palette_size) {
$gd_header .= pack("n"$ncolor);
}
// no transparency
$gd_header .= "\xFF\xFF\xFF\xFF";

fwrite($dest_f$gd_header);

if(
$palette_size) {
$palette fread($src_f$palette_size);
$gd_palette "";
$j 0;
while(
$j $palette_size) {
$b $palette{$j++};
$g $palette{$j++};
$r $palette{$j++};
$a $palette{$j++};
$gd_palette .= "$r$g$b$a";
}
$gd_palette .= str_repeat("\x00\x00\x00\x00"256 $ncolor);
fwrite($dest_f$gd_palette);
}

$scan_line_size = (($bits $width) + 7) >> 3;
$scan_line_align = ($scan_line_size 0x03) ? - ($scan_line_size &
0x03) : 0;

for(
$i 0$l $height 1$i $height$i++, $l--) {
// BMP stores scan lines starting from bottom
fseek($src_f$offset + (($scan_line_size $scan_line_align) *
$l));
$scan_line fread($src_f$scan_line_size);
if(
$bits == 24) {
$gd_scan_line "";
$j 0;
while(
$j $scan_line_size) {
$b $scan_line{$j++};
$g $scan_line{$j++};
$r $scan_line{$j++};
$gd_scan_line .= "\x00$r$g$b";
}
}
else if(
$bits == 8) {
$gd_scan_line $scan_line;
}
else if(
$bits == 4) {
$gd_scan_line "";
$j 0;
while(
$j $scan_line_size) {
$byte ord($scan_line{$j++});
$p1 chr($byte >> 4);
$p2 chr($byte 0x0F);
$gd_scan_line .= "$p1$p2";
}
$gd_scan_line substr($gd_scan_line0$width);
}
else if(
$bits == 1) {
$gd_scan_line "";
$j 0;
while(
$j $scan_line_size) {
$byte ord($scan_line{$j++});
$p1 chr((int) (($byte 0x80) != 0));
$p2 chr((int) (($byte 0x40) != 0));
$p3 chr((int) (($byte 0x20) != 0));
$p4 chr((int) (($byte 0x10) != 0));
$p5 chr((int) (($byte 0x08) != 0));
$p6 chr((int) (($byte 0x04) != 0));
$p7 chr((int) (($byte 0x02) != 0));
$p8 chr((int) (($byte 0x01) != 0));
$gd_scan_line .= "$p1$p2$p3$p4$p5$p6$p7$p8";
}
$gd_scan_line substr($gd_scan_line0$width);
}

fwrite($dest_f$gd_scan_line);
}
fclose($src_f);
fclose($dest_f);
return 
true;
}

function 
imagecreatefrombmp($filename) {
$tmp_name tempnam("/tmp""GD");
if(
ConvertBMP2GD($filename$tmp_name)) {
$img imagecreatefromgd($tmp_name);
unlink($tmp_name);
return 
$img;
}
return 
false;

Esta es la fuente:
http://www.thescripts.com/forum/thread3033.html
  #3 (permalink)  
Antiguo 28/05/2007, 11:10
 
Fecha de Ingreso: enero-2007
Mensajes: 77
Antigüedad: 17 años, 2 meses
Puntos: 1
Re: redimensionar imagen BMP

y tampoco podria hacer que todos los bmp de un directorio combertirlos a jpg?

mediante un scrip, asi le doy la vuelta a la tortilla
  #4 (permalink)  
Antiguo 28/05/2007, 11:24
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Re: redimensionar imagen BMP

Como te digo, la libreria GD, que es sobre lo que las funciones de imagenes de PHP estan programadas, no tiene soporte para BMP, por eso te digo que utilices esa funcion que te implementa un imagecreatefrombmp, que le falta a la libreria GD.
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.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 16:01.