Spring Boot集成easyposter快速入門Demo

1.什么是easyposter?

easyposter是一個簡單的,便于擴展的繪制海報工具包

使用場景

在日常工作過程中,通常一些C端平臺會伴隨著海報生成與分享業務。因為隨著移動互聯網的迅猛發展,社交分享已成為我們日常生活的重要組成部分。海報分享作為一種直觀、生動的分享方式,被廣泛應用于各類應用場景中,如產品推廣、活動宣傳、內容分享等。本文主要介紹通過Java進行海報生成的原理解析與代碼示例。

2.代碼工程

實驗目的

使用easyposter生成一張文章海報圖

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>springboot-demo</artifactId><groupId>com.et</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>poster</artifactId><properties><maven.compiler.source>11</maven.compiler.source><maven.compiler.target>11</maven.compiler.target></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>com.github.quaintclever</groupId><artifactId>easyposter</artifactId><version>1.2</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency></dependencies>
</project>

controller

package com.et.poster.controller;import com.et.poster.service.PosterUtil;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;@RestController
public class HelloWorldController {@RequestMapping("/hello")public Map<String, Object> showHelloWorld(){Map<String, Object> map = new HashMap<>();map.put("msg", "HelloWorld");return map;}@RequestMapping(path = "/genPoster",produces = MediaType.IMAGE_PNG_VALUE)@ResponseBodypublic byte[] genposterpng( HttpServletRequest request,HttpServletResponse response) {try {byte[] bytes = PosterUtil.test(); OutputStream out = null;try {out = response.getOutputStream();out.write(bytes);  out.flush();} catch (IOException ex) {ex.printStackTrace();}return null;} catch (Exception e) {e.printStackTrace();return null;}}
}

生成海報工具類

package com.et.poster.service;import com.quaint.poster.core.impl.PosterDefaultImpl;
import lombok.extern.slf4j.Slf4j;import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URL;
import java.util.Random;/*** @author quaint* @date 21 February 2020* @since 1.0*/
@Slf4j
public class PosterUtil {public static String ossDomain="http://qdliuhaihua.oss-cn-qingdao-internal.aliyuncs.com/";public static void main(String[] args) throws Exception{//String in1pathString = PosterUtil.class.getResource("/static/css/fonts/simkai.ttf").getFile();//System.out.printf(in1pathString);test();}public   static  byte[] test() throws IOException, IllegalAccessException, FontFormatException {BufferedImage background = ImageIO.read(new URL("http://image.liuhaihua.cn/bg.jpg"));File file2=  new File("/Users/liuhaihua/Downloads/2.jpg");BufferedImage mainImage = ImageIO.read(file2);BufferedImage siteSlogon = ImageIO.read(new URL("http://image.liuhaihua.cn/site.jpg"));BufferedImage xx = ImageIO.read(new URL("http://image.liuhaihua.cn/xx.jpg"));File file5=  new File("/Users/liuhaihua/IdeaProjects/springboot-demo/poster/src/main/resources/image/wx_300px.png");BufferedImage qrcode = ImageIO.read(file5);SamplePoster poster = SamplePoster.builder().backgroundImage(background).postQrcode(qrcode).xuxian(xx).siteSlogon(siteSlogon).postTitle("Java generate poster in 5 miniutes").postDate("2022年11月14日 pm1:23 Author:Harries").posttitleDesc("Demand Background\u200B We often encounter such a demand in multi-terminal application development: when users browse products, they feel good and want to share them with friends. At this time, the terminal (Android, Apple, H5, etc.) generates a beautiful product poster and shares it with others through WeChat or other channels. You may also encounter the demand: make a personal business card and print it out or share it with others. The effect is probably like this: It may also be like this (the above pictures are all mine...").mainImage(mainImage).build();PosterDefaultImpl<SamplePoster> impl = new PosterDefaultImpl<>();BufferedImage test = impl.annotationDrawPoster(poster).draw(null);//ImageIO.write(test,"png",new FileOutputStream("/Users/liuhaihua/annTest.png"));ByteArrayOutputStream stream = new ByteArrayOutputStream();ImageIO.write(test, "png", stream);return stream.toByteArray();}}

以上只是一些關鍵代碼,所有代碼請參見下面代碼倉庫

代碼倉庫

  • GitHub - Harries/springboot-demo: a simple springboot demo with some components for example: redis,solr,rockmq and so on.

3.測試

啟動Spring Boot應用程序

測試生成海報

訪問http://127.0.0.1:8088/genPoster,返回圖片如下圖

genPoster

4.引用

  • GitHub - quaintclever/easyposter: 一個簡單的,便于擴展的awt繪制海報小項目
  • Spring Boot集成easyposter快速入門Demo | Harries Blog?

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/44793.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/44793.shtml
英文地址,請注明出處:http://en.pswp.cn/web/44793.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

visual studio 2019版下載以及與UE4虛幻引擎配置(過程記錄)(官網無法下載visual studio 2019安裝包)

一、概述 由于需要使用到UE4虛幻引擎&#xff0c;我使用的版本是4.27版本的&#xff0c;其官方默認的visual studio版本是2019版本的&#xff0c;相應的版本對應關系可以通過下面的官方網站對應關系查詢。https://docs.unrealengine.com/4.27/zh-CN/ProductionPipelines/Develo…

MMSegmentation筆記

如何訓練自制數據集&#xff1f; 首先需要在 mmsegmentation/mmseg/datasets 目錄下創建一個自制數據集的配置文件&#xff0c;以我的蘋果葉片病害分割數據集為例&#xff0c;創建了mmsegmentation/mmseg/datasets/appleleafseg.py 可以看到&#xff0c;這個配置文件主要定義…

python:使用matplotlib庫繪制圖像(四)

作者是跟著http://t.csdnimg.cn/4fVW0學習的&#xff0c;matplotlib系列文章是http://t.csdnimg.cn/4fVW0的自己學習過程中整理的詳細說明版本&#xff0c;對小白更友好哦&#xff01; 四、條形圖 1. 一個數據樣本的條形圖 條形圖&#xff1a;常用于比較不同類別的數量或值&…

3dmax-vray5大常用材質設置方法

3dmax云渲染平臺——渲染100 以高性價比著稱&#xff0c;是預算有限的小伙伴首選。 15分鐘0.2,60分鐘內0.8;注冊填邀請碼【7788】可領30元禮包和免費渲染券 提供了多種機器配置選擇(可以自行匹配環境)最高256G大內存機器&#xff0c;滿足不同用戶需求。 木紋材質 肌理調整&…

函數語意學(The Sematics of Function)

1、非靜態成員函數轉化為非成員函數 c 設計準則之一就是&#xff1a;非靜態成員函數至少和非成員函數有相同的效率。 也就是說下面兩個函數具有相同的效率&#xff1a; float magnitude(const Point3d * this){...}; float Point3d::magnitude(){...};以 float Point3d::mag…

練習9.5 彩票分析

練習 9.14&#xff1a;彩票 創建?個列表或元素&#xff0c;其中包含 10 個數和 5 個字 ?。從這個列表或元組中隨機選擇 4 個數或字?&#xff0c;并打印?條消息&#xff0c; 指出只要彩票上是這 4 個數或字?&#xff0c;就中?獎了。 練習 9.15&#xff1a;彩票分析 可以使…

面試題 05. 替換空格

05. 替換空格 題目描述示例 題解 題目描述 請實現一個函數&#xff0c;把字符串 s 中的每個空格替換成"%20"。 示例 示例1 輸入&#xff1a;s “We are happy.” 輸出&#xff1a;“We%20are%20happy.” 題解 class Solution { public:string replaceSpace(stri…

jQuery 元素選擇器集合

jQuery 提供了一套非常強大的元素選擇器&#xff0c;它們可以以各種方式定位和操作網頁文檔中的元素。 以下是 jQuery 中的一些常用選擇器&#xff1a; 1、基本選擇器 #id&#xff1a;選擇 ID 為 id 的元素。.&#xff08;類選擇器&#xff09;&#xff1a;選擇具有特定類的…

2.5 OJ 網站的使用與作業全解

目錄 1 OJ 網站如何使用 1.1 注冊賬戶 1.2 登錄賬戶 1.3 做題步驟 2 本節課的 OJ 作業說明 3 章節綜合判斷題 4 課時2作業1 5 課時2作業2 6 課時2作業3 1 OJ 網站如何使用 〇J 是英文 Online Judge 的縮寫&#xff0c;中文翻譯過來是在線判題。當用戶將自己編寫的代碼…

基于XC7VX690T FPGA+ZU15EG SOC的6U VPX總線實時信號處理平臺(支持4路光纖)

6U VPX架構&#xff0c;符合VITA46規范板載高性能FPGA處理器&#xff1a;XC7VX690T-2FFG1927I板載1片高性能MPSOC&#xff1a;XCZU15EG-2FFVB1156I板載1片MCU&#xff0c;進行健康管理、時鐘配置等V7 FPGA外掛2個FMC接口兩片FPGA之間通過高速GTH進行互聯 基于6U VPX總線架構的通…

從零開始做題:神奇的棋盤

題目 打開得到一副adfgvx加密棋盤 觀察txt數據只有1-5&#xff0c;猜測是數字字母坐標轉換&#xff0c;用notepad批量操作一下 解題 AGAXXDAGGVGGVDVADAVXDGADVGDVAADDDDFXAFAFDGDVXXDGGDGGDXDDFDDXVGXADGVDFXVVAADDXDXXADDVGGGXGXXXXGXXGGXGDVVVGGGAGAAAAGAAGGAGDDDAGAGGG…

解釋如單例、工廠、觀察者等常見設計模式在Android開發中的應用。

在Android開發中&#xff0c;設計模式的應用是提升代碼質量、增強可維護性和可擴展性的重要手段。單例模式&#xff08;Singleton&#xff09;、工廠模式&#xff08;Factory&#xff09;、觀察者模式&#xff08;Observer&#xff09;等是其中最為常見且實用的設計模式。下面我…

如何對已經存在的表進行加分區方案分區函數

我參考網上的&#xff0c;寫了2給存儲過程&#xff0c;一個初始創建文分區方案分區函數&#xff1b;一個可以通過作業新增文件組文件件&#xff1b; 但是初始沒有綁定表&#xff0c;網上的都是在創建表是綁定分區方案&#xff0c;但是我的表是已經存在的&#xff0c;怎么綁定 …

Python實現網站IP地址查詢

使用socket庫實現網站的ip地址查詢&#xff0c;以便于使用CC攻擊和DDoS攻擊&#xff08;鬧著玩的&#xff09; import socket def get_website_ip(website): try: ip socket.gethostbyname(website) return ip except socket.gaierror: retur…

最小數字游戲(Lc2974)——模擬+優先隊列(小根堆)、排序+交換

你有一個下標從 0 開始、長度為 偶數 的整數數組 nums &#xff0c;同時還有一個空數組 arr 。Alice 和 Bob 決定玩一個游戲&#xff0c;游戲中每一輪 Alice 和 Bob 都會各自執行一次操作。游戲規則如下&#xff1a; 每一輪&#xff0c;Alice 先從 nums 中移除一個 最小 元素&…

力扣 383贖金信

思路&#xff0c;用unordered_map存儲magazine中字符以及字符出現的次數 遍歷ransomNote中每個字符&#xff0c;如果能在map中找到&#xff0c;則對應value減一&#xff0c;如果字符對應的value小于零&#xff0c;意味著magazine中找不到與ransomNote里這個字符對應的字符&…

翁愷-C語言程序設計-05-3. 求a的連續和

05-3. 求a的連續和 輸入兩個整數a和n&#xff0c;a的范圍是[0,9]&#xff0c;n的范圍是[1,8]&#xff0c;求數列之和S aaaaaa…aaa…a&#xff08;n個a&#xff09;。如a為2、n為8時輸出的是222222…22222222的和。 輸入格式&#xff1a; 輸入在一行中給出兩個整數&#xf…

VUE_TypeError: Cannot convert a BigInt value to a number at Math.pow 解決方法

錯誤信息 TypeError: Cannot convert a BigInt value to a number at Math.pow vue 或 react package.json添加 "browserslist": {"production": ["chrome > 67","edge > 79","firefox > 68","opera >…

實戰演練-2021年電賽國一之三端口DC-DC變換器

文章目錄 前言一、題目二、題目分析1、題目要求解析2、題目方案選定方案一(使用buck-boost電路&#xff0b;雙向DC-DC電路&#xff08;前端&#xff09;)方案二(使用同步整流Boost升壓電路&#xff0b;雙向DC-DC電路&#xff08;前端&#xff09;)方案三(使用同步整流Boost升壓…

實時聊天 Vue + Vuex + sockjs-client + stompjs進行websocket連接

實時聊天 知識點WebSocket介紹SockJSSTOMP 開發環境功能實現安裝應用在vuex中創建vue中的引入、監聽、實例化與收發、訂閱消息引入組件實例化與訂閱計算屬性監聽收到消息封裝的發送消息的公共方法發送消息 完整的代碼 知識點 WebSocket介紹 WebSocket 是一種在 Web 應用中實現…