Ver Mensaje Individual
  #10 (permalink)  
Antiguo 18/03/2011, 14:57
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: Redimensionar y subir imagen bmp

El problema es que la librería GD no tiene soporte para BMP, tienes que usar una función para transformar ese BMP, una idea es algo así:
Código PHP:
Ver original
  1. function ConvertBMP2GD($src, $dest = false) {
  2. if(!($src_f = fopen($src, "rb"))) {
  3. return false;
  4. }
  5. if(!($dest_f = fopen($dest, "wb"))) {
  6. return false;
  7. }
  8. $header = unpack("vtype/Vsize/v2reserved/Voffset", fread($src_f,
  9. 14));
  10. $info = unpack("Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vimportant",
  11. fread($src_f, 40));
  12.  
  13. extract($info);
  14. extract($header);
  15.  
  16. if($type != 0x4D42) {    // signature "BM"
  17. return false;
  18. }
  19.  
  20. $palette_size = $offset - 54;
  21. $ncolor = $palette_size / 4;
  22. $gd_header = "";
  23. // true-color vs. palette
  24. $gd_header .= ($palette_size == 0) ? "\xFF\xFE" : "\xFF\xFF";
  25. $gd_header .= pack("n2", $width, $height);
  26. $gd_header .= ($palette_size == 0) ? "\x01" : "\x00";
  27. if($palette_size) {
  28. $gd_header .= pack("n", $ncolor);
  29. }
  30. // no transparency
  31. $gd_header .= "\xFF\xFF\xFF\xFF";
  32.  
  33. fwrite($dest_f, $gd_header);
  34.  
  35. if($palette_size) {
  36. $palette = fread($src_f, $palette_size);
  37. $gd_palette = "";
  38. $j = 0;
  39. while($j < $palette_size) {
  40. $b = $palette{$j++};
  41. $g = $palette{$j++};
  42. $r = $palette{$j++};
  43. $a = $palette{$j++};
  44. $gd_palette .= "$r$g$b$a";
  45. }
  46. $gd_palette .= str_repeat("\x00\x00\x00\x00", 256 - $ncolor);
  47. fwrite($dest_f, $gd_palette);
  48. }
  49.  
  50. $scan_line_size = (($bits * $width) + 7) >> 3;
  51. $scan_line_align = ($scan_line_size & 0x03) ? 4 - ($scan_line_size &
  52. 0x03) : 0;
  53.  
  54. for($i = 0, $l = $height - 1; $i < $height; $i++, $l--) {
  55. // BMP stores scan lines starting from bottom
  56. fseek($src_f, $offset + (($scan_line_size + $scan_line_align) *
  57. $l));
  58. $scan_line = fread($src_f, $scan_line_size);
  59. if($bits == 24) {
  60. $gd_scan_line = "";
  61. $j = 0;
  62. while($j < $scan_line_size) {
  63. $b = $scan_line{$j++};
  64. $g = $scan_line{$j++};
  65. $r = $scan_line{$j++};
  66. $gd_scan_line .= "\x00$r$g$b";
  67. }
  68. }
  69. else if($bits == 8) {
  70. $gd_scan_line = $scan_line;
  71. }
  72. else if($bits == 4) {
  73. $gd_scan_line = "";
  74. $j = 0;
  75. while($j < $scan_line_size) {
  76. $byte = ord($scan_line{$j++});
  77. $p1 = chr($byte >> 4);
  78. $p2 = chr($byte & 0x0F);
  79. $gd_scan_line .= "$p1$p2";
  80. }
  81. $gd_scan_line = substr($gd_scan_line, 0, $width);
  82. }
  83. else if($bits == 1) {
  84. $gd_scan_line = "";
  85. $j = 0;
  86. while($j < $scan_line_size) {
  87. $byte = ord($scan_line{$j++});
  88. $p1 = chr((int) (($byte & 0x80) != 0));
  89. $p2 = chr((int) (($byte & 0x40) != 0));
  90. $p3 = chr((int) (($byte & 0x20) != 0));
  91. $p4 = chr((int) (($byte & 0x10) != 0));
  92. $p5 = chr((int) (($byte & 0x08) != 0));
  93. $p6 = chr((int) (($byte & 0x04) != 0));
  94. $p7 = chr((int) (($byte & 0x02) != 0));
  95. $p8 = chr((int) (($byte & 0x01) != 0));
  96. $gd_scan_line .= "$p1$p2$p3$p4$p5$p6$p7$p8";
  97. }
  98. $gd_scan_line = substr($gd_scan_line, 0, $width);
  99. }
  100.  
  101. fwrite($dest_f, $gd_scan_line);
  102. }
  103. fclose($src_f);
  104. fclose($dest_f);
  105. return true;
  106. }
  107.  
  108. function imagecreatefrombmp($filename) {
  109. $tmp_name = tempnam("/tmp", "GD");
  110. if(ConvertBMP2GD($filename, $tmp_name)) {
  111. $img = imagecreatefromgd($tmp_name);
  112. unlink($tmp_name);
  113. return $img;
  114. }
  115. return false;
  116. }

Tomado de: http://bytes.com/topic/php/answers/3...bmp-support-gd

Con eso puedes transformar la imagen a bmp y usar directamente cualquier código actual cambiando la función por imagecreatefrombmp.

Saludos.