gpt4 book ai didi

grails - 如何使用 TagLib 将字节数组(Blob)呈现为图像

转载 作者:行者123 更新时间:2023-12-02 14:15:17 25 4
gpt4 key购买 nike

如何使用自定义标签渲染存储在数据库中的图像文件(Blob),我曾经渲染过 Logo ,但图像正在崩溃,输出是字节数组。

这是我尝试过的:

def logo = { attrs, body ->
if(session?.companyId && session?.companyId != 'null'){
Company company = Company.findById(session?.companyId)
if (!company || !company?.logo) {
println "No response..."
out <<"<img src='/cdc/static/images/logo.png' width='150' height='70' />"
}
else{
println "Writing..."
out << "<img src='"
out << company?.logo
out << "' width='150' height='70' />"
}
}
else{
println "No response..."
//out <<"<img src='/cdc/static/images/logo.png' width='150' height='70' />"
}
}

输出如下:

enter image description here

enter image description here

公司?.logo 呈现为 图片 而不是 字节数组 ?

最佳答案

听起来您想提供 data URI , 基本上。为此,您需要以下内容:

src="data:img/png;base64,xxx"

其中“xxx”是base64格式的数据。

例如,使用 this public domain base64 library :
out << "<img src='data:img/png;base64,"
out << Base64.encode(company?.logo)
out << "' width='150' height='70' />"

关于grails - 如何使用 TagLib 将字节数组(Blob)呈现为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24278053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com