沃梦达 / 编程问答 / php问题 / 正文

Base 64 编码与加载图像文件

Base 64 encode vs loading an image file(Base 64 编码与加载图像文件)

本文介绍了Base 64 编码与加载图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在 php 中做一些事情,我必须从 sql 数据库中获取我的图像,它们将在 base64 中编码.显示这些图像的速度很关键,所以我想知道是否可以更快地将数据库数据转换为图像文件,然后将其加载到浏览器中,或者只是回显原始 base64 数据并使用:

So I am working on something in php where I have to get my images from a sql database where they will be encoded in base64. The speed of displaying these images is critical so I am trying to figure out if it would be faster turn the database data into an image file and then load it in the browser, or just echo the raw base64 data and use:

<img src="data:image/jpeg;base64,/9j/4AAQ..." />

FireFox 和其他 Gecko 浏览器都支持.

Which is supported in FireFox and other Gecko browsers.

所以回顾一下,传输实际图像文件或 base64 代码会更快吗?使用ajax加载图片需要更少的http请求吗?

So to recap, would it be faster to transfer an actual image file or the base64 code. Would it require less http request when using ajax to load the images?

图像总大小不超过 100 像素.

The images would be no more than 100 pixels total.

推荐答案

好吧,我不同意你们中的任何人.在某些情况下,您必须加载越来越多的图像.并非所有页面都包含 3 张图片.实际上,我正在一个需要加载 200 多张图片的网站上工作.当 100000 个用户在一个负载非常大的网站上请求 200 张图片时会发生什么.服务器的磁盘,返回图像应该崩溃.更糟糕的是,您必须向服务器发出如此多的请求,而不是使用 base64.对于这么多缩略图,我更喜欢 base64 表示,预先保存在数据库中.我在 http://www.stoimen.com/2009/04/23/when-you-should-use-base64-for-images/.这家伙真的是那种情况,做了一些测试.我印象深刻,也进行了测试.现实就像它说的那样.对于在一个页面中加载的这么多图像,来自服务器的一个响应确实很有帮助.

Well I don't agree with anyone of you. There are cases when you've to load more and more images. Not all the pages contain 3 images at all. Actually I'm working on a site where you've to load more than 200 images. What happens when 100000 users request that 200 images on a very loaded site. The disks of the server, returning the images should collapse. Even worse you've to make so much request to the server instead of one with base64. For so much thumbnails I'd prefer the base64 representation, pre-saved in the database. I found the solution and a strong argumentation at http://www.stoimen.com/2009/04/23/when-you-should-use-base64-for-images/. The guy is really in that case and made some tests. I was impressed and make my tests as well. The reality is like it says. For so much images loaded in one page the one response from the server is really helpful.

这篇关于Base 64 编码与加载图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Base 64 编码与加载图像文件

基础教程推荐