Save image from one format to another with php gd2

后端 未结 3 1728
梦谈多话
梦谈多话 2021-01-23 08:10

I have a database with a column filled with image binaries data. After I made some research I figuried out how to detect in which image format is the data. Lets say in of the re

3条回答
  •  醉梦人生
    2021-01-23 08:56

    If you only want to convert the image data to JPEG then all you need is imagecreatefromstring and imagejpeg. Basically:

    imagejpeg(imagecreatefromstring($gif_bindata), "temp.jpeg");
    $jpeg_bindata = file_get_contents("temp.jpeg");
    

    It's that simple because imagecreatefromstring detects the file type automatically (the first few bytes contain enough magic bytes to make detection feasible). And obviously you might want to use a real temporary filename instead.

提交回复
热议问题