将图像内容保存在html文件中

时间:2013-04-24 12:23:57

标签: html css image

是否可以在html中保存图像?我想用几张图片创建html。也许我需要用base64解码图像内容并将其粘贴到html标记中?

3 个答案:

答案 0 :(得分:6)

是的,请查看这个简单示例:http://jsfiddle.net/MH7gF/

<img alt="" src="data:image/png;base64(...)" />

还有简单的converter

答案 1 :(得分:2)

似乎您正在寻找使用CSS数据URI的。 http://css-tricks.com/data-uris/您需要将您的图像编码为base64,并使用HTML或CSS中的其中一个数据URI进行设置,因为它可以同时使用。

<img width="16" height="16" alt="star" src="data:image/gif;base64,..." />

li { 
  background: url(data:image/gif;base64,...) no-repeat left center;
}

答案 2 :(得分:0)

您想要使用图片而无需将其上传到某个地方吗?

您可以使用Mads Kristensen's image to a base64 converster工具,它会返回您上传图片的base64。

例如,我的头像:

<img alt="" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4gv4SUNDX1BST0ZJTEUAAQEAAAvoAAAAAAIAAABtbnRyUkdCIFhZWiAH2QADABsAFQAkAB9hY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAA9tYAAQAAAADTLQAAAAAp+D3er/JVrnhC+uTKgzkNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBkZXNjAAABRAAAAHliWFlaAAABwAAAABRiVFJDAAAB1AAACAxkbWRkAAAJ4AAAAIhnWFlaAAAKaAAAABRnVFJDAAAB1AAACAxsdW1pAAAKfAAAABRtZWFzAAAKkAAAACRia3B0AAAKtAAAABRyWFlaAAAKyAAAABRyVFJDAAAB1AAACAx0ZWNoAAAK3AAAAAx2dWVkAAAK6AAAAId3dHB0AAALcAAAABRjcHJ0AAALhAAAADdjaGFkAAALvAAAACxkZXNjAAAAAAAAAB9zUkdCIElFQzYxOTY2LTItMSBibGFjayBzY2FsZWQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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rRKagh2Y8sqXjHnnwqLHh3KdOTJShaH1rLjZx/m1Hr6WuT9BGx+YB+pPQO4HRP9SybK8F3mYp3IXr31c6YdSfEUhJusmAW3JkfvmnPZWFbONqHMBXPzGc1P/3JZv8Asfuml2Zg202lCOJJpyEtQMJpy4RUykErAORzFZt9I1DlukR22VqSHiScHGwrSbyyGc5wo+dZu9KFwKlW7Pgv+KqHpot+rAPEsfWl1iM0p63klC1HJ3xmvZKnA2H05ylwKwDzFdIScQhjJKicCvdZcCQ223nxrWUQFNGZ2WIaHHZER5sqWMawFEZxn50KlvwGzhlAWvwBzQwJBXjGtROAkHbNFLVb0uOF9/CWm/e0jbP4R40KrDLHQMK+TocSZY4Tkt5L8hOED3EY2pxjQlrSXErwoYxjpQM3BthgJQ2hkK2BUcnHyHP6VLjMXacGlNSBFbCTgOD2l+eOnyqw4taUjtUbMU3M1h2x1C93lR5jXqziG3iMa1+JFBf9Jh+Ln/up6ItzTtMYadxydYP7iufV1+B+1dysKvLYPYPP8TtGU+Ovah8TTTzx7o+HyrOXpKL1y4Ksctef0rRbvwD8qzn6RvxYfzV/FYZ6dAGWJq3XP2hlTQ30JYGtKlkEgAHFfS5Trq+51BCQPa09PKo8L3h+YV1HN78w/etQrsbsAmdso3CVtbOjvAMKV7LY8M0zRW2RpZK9LLSfuepNAIfw2PzD+amTfgK/OKb42lXciWDuMcbTHgElbKo619Vasn70W0aVJJ3AzjG/Slqy/CT8qZIXwk/mP7U5pIYcRdaNfedJGAghQIJqBpb/AMJqTO98/Oo1EPkzwOJ//9k=" />

对于CSS是相同的:

background-image: url(data:image/jpeg;base64,{tons of letter/numbers here});

是的,base64非常庞大。因此,不要使用很多,你的.html / css文件也会很大。