Buen dia.
Tengo un BMP de 4bits que quiero convertir a JPG, hice este codigo pero no lo consigo :(
<?php
$jpgfile= 'imagen.jpg';
$bmpfile= 'imagen.bmp';
# creamos jpg
$img= imagecreatefromwbmp($bmpfile);
imagejpeg($img, $jpgfile, 50); # crear imagen jpg
imagedestroy($img);
?>
En el Log de Apache recibo:
PHP Warning: imagecreatefromwbmp(): 'imagen.bmp' is not a valid WBMP file in /home/diabliyo/public_html/index.php on line 22, referer: http://localhost/test/index.php
[Mon Jan 06 17:53:49 2014] [error] [client 127.0.0.1] PHP Warning: imagejpeg() expects parameter 1 to be resource, boolean given in /home/diabliyo/public_html/index.php on line 23, referer: http://localhost/test/index.php
[Mon Jan 06 17:53:49 2014] [error] [client 127.0.0.1] PHP Warning: imagedestroy() expects parameter 1 to be resource, boolean given in /home/diabliyo/public_html/index.php on line 24, referer: http://localhost/test/index.php
Saludos !
De momento lo he resuelto usando un programa externo, pero aun estoy con la duda si es posible resolverlo con las funciones de PHP.
La forma como lo resolvi fue usando el programa "convert" incluido en gnu/linux:
<?php
$jpgfile= 'imagen.jpg';
$bmpfile= 'imagen.bmp';
# creamos jpg
system( "convert ". $bmpfile. " ". $jpgfile );
?>
BMP y WBMP son distintos formatos y la libreria gd no soporta imagenes bitmap.
Edito: Esta clase soporta imagenes bmp utilizando GD2BMPstring.
https://github.com/Oberto/php-image-magician/
Cita de: EFEX en 7 Enero 2014, 01:18 AM
BMP y WBMP son distintos formatos y la libreria gd no soporta imagenes bitmap.
Edito: Esta clase soporta imagenes bmp utilizando GD2BMPstring.
https://github.com/Oberto/php-image-magician/
Por esa razón, la función
imagecreatefromwbmp retorna false y dicho valor se almacena en la variable $img. Y a la hora de pasarla como argumentos a las funciones
imagejpeg y
imagedestroy, lanza un error porque le estas pasando un valor Booleano (False).
Si buscas imagecreatefrombmp vas a encontrar algunos scripts hechos, el problema es que funcione...
Por ej, este no soporta bmp de 32b y 16b pero de 24b si los convierte( No probe de 4bits photoshop no me dejo lol ).
https://github.com/chisimba/chisimba/blob/master/app/core_modules/files/resources/imagecreatefrombmp.php
$bmp = "image.bmp";
$output = "image.jpg";
$image = imagecreatefrombmp($bmp);
imagejpeg($image, $output);
imagedestroy($image);
La verdad ni quise mencionar la funcion imagcreatefrombmp porque no esta disponible por default :S !... solo imagecreatefromwbmp.
Saludos !