![](/img/trans.png)
[英]How do I convert an image from a NodeJS Buffer object to base64 in JavaScript so it can be used in the <img> src attribute?
[英]Can I make the src attribute fetch base64 data from a server or adjusting server?
我有這個圖像標簽,該標簽必須在無法使用Javascript的電子郵件中。 假設該API是我自己工作和編寫的,如何使此圖像標簽src從我的API中提取base64數據?
<img src="https://qr-generator-test.herokuapp.com/create-qr-code?data=184B2598-E19C-
4454-95CE-6BD7498F21D4" style="max-width:300px; width: 100%; padding: 0px;
text-align: center; display:block;" width="300">
還是我可以編輯我的API來做一些更聰明的事情? 有什么辦法嗎?
在您將電子郵件發送給客戶之前,將src屬性更改為有效的base64映像:
<img src="data:image/gif;base64,..." style="max-width:300px; width: 100%; padding: 0px; text-align: center; display:block;" width="300">
在這里,您必須將QR碼圖像二進制文件編碼為base64。
或將其設置為您當前的網址並按常規顯示圖像。
<img src="https://qr-generator-test.herokuapp.com/create-qr-code?data=184B2598-E19C- 4454-95CE-6BD7498F21D4" style="max-width:300px; width: 100%; padding: 0px; text-align: center; display:block;" width="300">
為此,您需要在url上返回圖像二進制數據,僅此而已。 沒有URL到另一個圖像,沒有文本,只有QR碼中的純二進制文件。
當我訪問時: https://qr-generator-test.herokuapp.com/create-qr-code?data=184B2598-E19C-%204454-95CE-6BD7498F21D4
: https://qr-generator-test.herokuapp.com/create-qr-code?data=184B2598-E19C-%204454-95CE-6BD7498F21D4
我得到一個URL,而不是有效的圖像。 https://qr-generator-test.herokuapp.com/qr-code/55m1bnju1367f7.png
指向QR碼圖像。
我希望我能澄清你的問題是什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.