2021年5月2日星期日

Convert small text to base64 encoded inline image for embed in to HTML in Java [closed]

I'm trying to send an Email with a small text (4 letters). I need to convert that text to base 64 encoded inline image and embed it into the HTML email, rather than putting it as a text. Please refer to the following example.

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGwAAAA4CAYAAAAYeR0sAAAE3ElEQVR42u1bb2SVURh/XXPdDzMmM8kVyczMRPowSSKTSa64rslMRiZJEkkmk8uVPmQSM8kkYybXlYxMH5LEzCRJzEwmGTOZTC51jp7L9fSc9z3v+XP17j4/fl92z3me857fOc95zvO+CwIGg8FgMBgMBoPBYDAYDMZf3BN8KFhK4NgzgmcFhwWvCY4KFgT7GjyOAfAredynI/mAv4GbFnZSgt/Ahg33afo7IlgRrNaNH/Or4Lhgm2exziC/z305Oiz4w5FgvSETF4c6gj2IafO74DlPc9gB9r0LJh2tIkc2ghUaJFglpO+viB036mEey4Qf54J1Cn4iHNkINtkAwe4T7eWiG0P9ugTvoOhRo8vzZUzxDE4F6xFcUziyEQyv/BHBVgOq0EeM91VEn244V+v7fHR4nPz0LdgFwZ2Q1W0jGB58j+OoMIfsr2kmEyeJ5zxtORaZYC2FzKO1YAcE5zXCkalg+5GdXcditRFn06UY/d+ivlOW47mL7C25EqwV0lpqV20R546pYDlkZ9GxYHkiuUjH6D+N+lcsxtJPhOVRV4K9UOykFYjBOUeC3UF2HjoW7KjgY8EFCL2vY/YvEZNsugHW0aLf71OwXdhxKcXOMBUMh9u854tqOmb7J2h8ZUO/M8hOgSg+OBNsVvBQRCgzFWwd2en6z8pXX9D4ig7C8jNFtchKsAoY7tU8ezYNV7sq4ZAL5CqMoQILaB4m7FSDxKLuSt0GSdUWKnm1+xAsKnS4EOwMkXDIBfJSIyuVK3/Io1hXCJ+PDOwsRlwLnAkWNECwy8jGRkR5iGI54gIcB1nYVR8IPzJZycS0dwPZmCTaJEqwpxqC7ALD2ryxEG0AylBhPiYNkpVeuELUbHxWCJ4owVQ3frmaz6NJSoPPBUWfOcPniCo8zxkkQmlUb63C9SJIsmApIvz91DyXcopaXM7gOW7HCL2dmjbxK5zxkLaJESwLxdT6UDQQo/+g4lJvkgleg+cZhB0nJ/x7QL8bi6pznkZ93ke0T1RIrK/3HXNwGf1taIdCBqou2P56oC4cy9c09RX+HagK7TnBbMpOeEJvOvZRJHyUNKs2Yxr2m0qwIPj3ReOsBx/LyIf02YLaXERtXmrabjrB8CW74sHHBWKXDaCqTP3C2YYzOq3BMSK5wW1Se0mw52gcLzz4aCUEG45xNbBlYS8JVg7cVNOj8CvkHGsKwVKQbclCrvyY86DhOFbQOGaI4usg7Aj5Ic4RR4LdajbBcLIwbTCGFuLyjTOzLfT7hIGfjohJPAGh2IS4bvmNaHPifxAMJwtfDMYwTExkV0Sq/cHAzwjh56ijUJuYLPEWMQknY4bUj6j/W0UlA/vptwy7aw7nMVGlqSpRWtKtipcIIQaJdu3Bv5X4FeIepcJdws/1ZhRM4pGiyBr13qmo6KfCREBX4aNEGyf6fYoh9p4TrC2gvyRehcpBBiUYeaLqUKvvdYT4kbuWepUjQ+oQEqAFEgqqvbwQu/7INXGVDlkc3VCks1WYpO1A/SZ6Q6PAWkvvVy38yN98/O9WIktT8uvidwb3kzcgRJz0fMHAz7LmomgawerT52WNCVwK7D7AyWv6WYHQ7BMNE8wnsjCp8tCfgkv1BPwt69hPATLOaWAR/pYNGAwGg8FgMBgMBoPBYDAYnvEHY5c6vYPBHHQAAAAASUVORK5CYII=" alt="One Time Password" />  

What is the best way to do that? Are there any libraries that I can use?

I'm using Spring Boot and Thymeleaf as the template engine for generating Emails.

https://stackoverflow.com/questions/67356768/convert-small-text-to-base64-encoded-inline-image-for-embed-in-to-html-in-java May 02, 2021 at 09:09PM

没有评论:

发表评论