Pregunta

Yo uso imagecreatefromjpeg, imagecreatefromgif y funciones imagecreatefrompng para crear imágenes en miniatura de image/jpeg, image/gif y mimos image/png.

Me gustaría también para crear imágenes en miniatura de los archivos .BMP.

he comprobado un archivo y descubrí que su mimo es image/x-ms-bmp.

Sin embargo, no puedo encontrar una función imagecreatefrom... apropiado.

Para sugerir.

¿Fue útil?

Solución

PHP no han incorporado en las funciones de imagen de BMP.

Ha habido unos pocos intentos de crear funciones para hacer esto.

Se puede encontrar una versión robusta y bien documentado en este comentario en la documentación de PHP: http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214

Esta es la función de ese comentario sin la excelente documentación que hace mucho más tiempo, pero mucho más fácil de leer:

public function imagecreatefrombmp($p_sFile)
{
    $file    =    fopen($p_sFile,"rb");
    $read    =    fread($file,10);
    while(!feof($file)&&($read<>""))
        $read    .=    fread($file,1024);
    $temp    =    unpack("H*",$read);
    $hex    =    $temp[1];
    $header    =    substr($hex,0,108);
    if (substr($header,0,4)=="424d")
    {
        $header_parts    =    str_split($header,2);
        $width            =    hexdec($header_parts[19].$header_parts[18]);
        $height            =    hexdec($header_parts[23].$header_parts[22]);
        unset($header_parts);
    }
    $x                =    0;
    $y                =    1;
    $image            =    imagecreatetruecolor($width,$height);
    $body            =    substr($hex,108);
    $body_size        =    (strlen($body)/2);
    $header_size    =    ($width*$height);
    $usePadding        =    ($body_size>($header_size*3)+4);
    for ($i=0;$i<$body_size;$i+=3)
    {
        if ($x>=$width)
        {
            if ($usePadding)
                $i    +=    $width%4;
            $x    =    0;
            $y++;
            if ($y>$height)
                break;
        }
        $i_pos    =    $i*2;
        $r        =    hexdec($body[$i_pos+4].$body[$i_pos+5]);
        $g        =    hexdec($body[$i_pos+2].$body[$i_pos+3]);
        $b        =    hexdec($body[$i_pos].$body[$i_pos+1]);
        $color    =    imagecolorallocate($image,$r,$g,$b);
        imagesetpixel($image,$x,$height-$y,$color);
        $x++;
    }
    unset($body);
    return $image;
}

Otros consejos

¿Qué tal algo como este tipo se describe:

http://www.php.net/manual/en/ function.imagecreate.php # 53879

No es un proyecto de código abierto, PHP imagen Mago, que le permite leer y escribir archivos BMP. Ver aquí: https://stackoverflow.com/a/11531747/577306

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top