将图像添加到div中并使用jQuery将base64字符串转换为缩略图

时间:2014-10-13 03:20:37

标签: javascript jquery base64

收到var img的base64字符串。然后我需要转换成图像并将其显示为缩略图。这是我的实施:

var img = "base64 string";

<div id="img_preview" style="width:250px; height:250px;"></div>

这是字符串;

/9j/4AAQSkZJRgABAgAAAQABAAD//gAEKgD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdCIFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApkZXNjAAAA/AAAAF5jcHJ0AAABXAAAAAt3dHB0AAABaAAAABRia3B0AAABfAAAABRyWFlaAAABkAAAABRnWFlaAAABpAAAABRiWFlaAAABuAAAABRyVFJDAAABzAAAAEBnVFJDAAABzAAAAEBiVFJDAAABzAAAAEBkZXNjAAAAAAAAAANjMgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB0ZXh0AAAAAEZCAABYWVogAAAAAAAA9tYAAQAAAADTLVhZWiAAAAAAAAADFgAAAzMAAAKkWFlaIAAAAAAAAG+iAAA49QAAA5BYWVogAAAAAAAAYpkAALeFAAAY2lhZWiAAAAAAAAAkoAAAD4QAALbPY3VydgAAAAAAAAAaAAAAywHJA2MFkghrC/YQPxVRGzQh8SmQMhg7kkYFUXdd7WtwegWJsZp8rGm/fdPD6TD////bAEMACQYHCAcGCQgICAoKCQsOFw8ODQ0OHBQVERciHiMjIR4gICUqNS0lJzIoICAuPy8yNzk8PDwkLUJGQTpGNTs8Of/bAEMBCgoKDgwOGw8PGzkmICY5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5O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wyx49jUssGxBSHzM9l/c6w7CFy3/R8RRdYIxFqyu+pdwmM0h4UALj7zWNFDte5bIWgvf8AF+YRwjoU0D6HphKr9IdpVqtvJX4Q5QC8p+MhZWAsrnyllxGpjYDC0ypQ0J8Dp+RZxcmnuEH0RSCehjiKUy+fUrIk6MYl5iDuz4RFoFQVrbAPhP8A2UWbHdnCDo7yCxoRi6Xuxy1jA9ZLgsootuj+HGfEGxhA24BvPEPPgcfnP6ZQzB9E2SnlLwTEgXAgHxE8yipjcZXxHU//2Q==

2 个答案:

答案 0 :(得分:11)

修改,更新

尝试

js

var base64_string = "/9j/4AAQSkZJRgABAgAAAQABAAD//...";
var img = document.createElement("img");
// added `width` , `height` properties to `img` attributes
img.width = "250px";
img.height = "250px";
img.src = "data:image/png;base64," + base64_string;
var preview = document.getElementById("img_preview");
preview.appendChild(img);

js(jquery library)

$("<img>", {
  "src": "data:image/png;base64," + base64_string,
  // added `width` , `height` properties to `img` attributes
  "width": "250px", "height": "250px"})
.appendTo("#img_preview");

var base64_string = "/9j/4AAQSkZJRgABAgAAAQABAAD//gAEKgD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdCIFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWxjbXMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAApkZXNjAAAA/AAAAF5jcHJ0AAABXAAAAAt3dHB0AAABaAAAABRia3B0AAABfAAAABRyWFlaAAABkAAAABRnWFlaAAABpAAAABRiWFlaAAABuAAAABRyVFJDAAABzAAAAEBnVFJDAAABzAAAAEBiVFJDAAABzAAAAEBkZXNjAAAAAAAAAANjMgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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9VWA44rWGkzIbiUK4+3mW3l4jrx6G8nf2oBhWHDPMAWdg4933Cl03hu3nqHBwLSsVz3Xmed4n/JWh+rp6TyRdI2IA80Yw1+ktaHoekLxnkX9j2FnXVFl55EPBzIvvu6ghe1Y1Nwrrmu/mGWhtVb2lUvq43tCFqerBdFPPI30TUWXU+pht0x/wnDX7lh/CJp88+46COqISgoyK6Bc9HxD5VbDCgKpyIotuWl8Bi5WX+WOkoAe5yCpZGgZ5KhsvgjBCxA1YRWoXH1G1b4+ZjGdDt9gYZbtjdHlMLL99NPCi3mTkoZQukhvyvuFxEp9NJy8FO+ZiYQoNbeLY6zuRbln00/OwnVIkFqjb5V/uO2IBLUvt5qMwV5ZiRtadPUGgsX6v/ofDLALhtAjfY6001d7C3Wyx49jUssGxBSHzM9l/c6w7CFy3/R8RRdYIxFqyu+pdwmM0h4UALj7zWNFDte5bIWgvf8AF+YRwjoU0D6HphKr9IdpVqtvJX4Q5QC8p+MhZWAsrnyllxGpjYDC0ypQ0J8Dp+RZxcmnuEH0RSCehjiKUy+fUrIk6MYl5iDuz4RFoFQVrbAPhP8A2UWbHdnCDo7yCxoRi6Xuxy1jA9ZLgsootuj+HGfEGxhA24BvPEPPgcfnP6ZQzB9E2SnlLwTEgXAgHxE8yipjcZXxHU//2Q==";
























































    $("<img>", {
      "src": "data:image/png;base64," + base64_string,
      "width": "250px", "height": "250px"})
    .appendTo("#img_preview");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="img_preview" style="width:250px; height:250px;"></div>

答案 1 :(得分:4)

看看这个fiddle

您可以使用jquery .attr()

$(function () {
    var imgSrc = ""; //<-- replace with your base64 image, i don't want to clog up the answer
    var $img = $("<img/>");
    $img.attr("src", "data:image/png;base64," + imgSrc);
    $("#img_preview").append($img);
});