duanliang1019 2012-10-01 17:32
浏览 23
已采纳

将html图像数据网址转换为托管图像

I have a page that is generating image data urls from a snapshot tool and inserting the resulting string into a MySQL database via PHP. Later on I have a page that takes and uses those images. This would be fine except I need to save the resulting html to my server for some post processing and the length of the image data urls is giving me a headache and making the html files upwards of 8 to 10 MBs which slows down the entire process. The image looks something like this:

<img src="data:image/png:base64,iVBORw0K43+gAA4u...">

Where there is an extremely long string of characters making the resulting html very large. Is there a way to host this on my server as a png so the link is a normal looking image? Something like this:

<img src="http://www.mysite.com/image1.png">
  • 写回答

2条回答 默认 最新

  • dongquanlin1885 2012-10-01 17:46
    关注

    What about converting base64 to an original image, what you would be doing is saving the image as a actual file to the server.

    Php to convert base64 data to image

        function toImage($base_code){
        $img_file = imagecreatefromstring(base64_decode($base_code));
        imagejpeg($img_file, 'new.jpg');
    }
    

    Calling the function

    echo toImage($encoded_image);
    

    Make sure to only pass the base64 encoded string without the image tag

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大