Php : Convert a blob into an image file

前端 未结 4 631
醉酒成梦
醉酒成梦 2020-11-29 09:23

Is this possible with php and a mysql database to Convert a blob into an image file?

4条回答
  •  暖寄归人
    2020-11-29 10:03

    You can use a few different methods depending on what php image library you have installed. Here's a few examples.

    Note, the echo is just a trick I use to display multiple images from the same php script when looping through a MySQL result resource. You could just as well output via header() as @NAVEED had shown.

    GD:

    $image = imagecreatefromstring($blob); 
    
    ob_start(); //You could also just output the $image via header() and bypass this buffer capture.
    imagejpeg($image, null, 80);
    $data = ob_get_contents();
    ob_end_clean();
    echo '';
    

    ImageMagick (iMagick):

    $image = new Imagick();
    $image->readimageblob($blob);
    echo '';
    

    GraphicsMagick (gMagick):

    $image = new Gmagick();
    $image->readimageblob($blob);
    echo '';
    

提交回复
热议问题