diff --git a/README.md b/README.md index 3e37be1..fb547bf 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ -[在线体验](https://design.palxp.com/) | [文档网站](https://xp.palxp.com/) | [项目架构及目录讲解](https://xp.palxp.com/#/articles/1689321259854) +[在线体验](https://design.palxp.com/) | [文档网站](https://xp.palxp.com/) | [项目架构及目录](https://xp.palxp.com/#/articles/1689321259854) ## 迅排设计 -一款漂亮且功能强大的在线海报图片设计器,仿稿定设计。适用于海报图片生成、电商分享图、文章长图、视频/公众号封面等多种场景。 +一款漂亮且功能强大的在线海报图片设计器,仿稿定设计。 -![](https://xp.palxp.com/images/2023-7-17-1689558055663.png) +适用于海报图片生成、电商分享图、文章长图、视频/公众号封面等多种场景。 + +![](https://xp.palxp.com/images/2023-7-16-1689500112694.gif) - 丝滑的操作体验,丰富的交互细节,基础功能完善 - 采用服务端生成图片,确保多端出图统一性,支持各种 CSS 特性 @@ -12,14 +14,16 @@ ### 技术栈概括 -前端:Vue3 、Vite2 、Vuex 、ElementPlus +- Vue3 、Vite2 、Vuex 、ElementPlus -图片生成:Puppeteer、Express +- 图片生成:Puppeteer、Express -一些可独立的功能会被抽取出来作为单独的库引入使用,仓库地址:[front-end-arsenal](https://github.com/palxiao/front-end-arsenal),[组件文档网站](https://fe-doc.palxp.com/#/) +一些可独立的功能会被抽取出来作为单独的库引入使用,仓库地址:[front-end-arsenal](https://github.com/palxiao/front-end-arsenal)([组件文档网站](https://fe-doc.palxp.com/#/)) > 环境需求:**Node.js v16** 以上版本 +## 快速开始 + ### 拉取源码 ``` @@ -43,28 +47,22 @@ npm run serve > > ![](https://xp.palxp.com/images/2023-7-16-1689498291322.png) -### 运行结果 - -![](https://xp.palxp.com/images/2023-7-16-1689500112694.gif) - 合成图片时本地会启动一个 Chrome 浏览器实例。 -### 打包前端页面 +### 打包 ``` -npm run v-build -``` - -### 打包图片生成服务 - -``` -cd sreenshot -npm run build +npm run v-build <- 前端页面 +npm run build <- 图片生成服务( sreenshot 目录下) ``` ### 服务端 -可参考接口 API 文档自行实现服务端。 +可参考[接口 API 文档](https://xp.palxp.com/apidoc/index.html)自行实现服务端。 + +### 图片生成服务 + +代码位于 `screenshots` 目录下,[接口 API 文档](https://xp.palxp.com/apidoc/screenshot.html)。 ### 服务器配置 diff --git a/screenshot/README.md b/screenshot/README.md index ac87de9..5a138cb 100644 --- a/screenshot/README.md +++ b/screenshot/README.md @@ -3,7 +3,7 @@ * @Date: 2022-02-01 13:41:59 * @Description: * @LastEditors: ShawnPhang - * @LastEditTime: 2023-07-04 19:04:44 + * @LastEditTime: 2023-07-18 16:30:53 --> # Node截图服务 @@ -15,6 +15,10 @@ ts-node 直接运行,并监听文件修改自动热重启 使用 webpack 打包文件 +### build:apidoc + +生成 API 文档 + ### npm run serve (不使用) webpack/tsc 编译 ts,supervisor/pm2 监听编译后文件变动重启服务,gulp 自动化任务 diff --git a/screenshot/test/gif.js b/screenshot/test/gif.js deleted file mode 100644 index 94db45d..0000000 --- a/screenshot/test/gif.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - * @Author: ShawnPhang - * @Date: 2022-04-19 14:19:13 - * @Description: - * @LastEditors: ShawnPhang - * @LastEditTime: 2022-04-21 18:38:10 - */ -// const fs2 = require('fs') -const path = require('path') -const puppeteer = require('puppeteer') - -const GIFEncoder = require('gif-encoder-2') -const { createWriteStream } = require('fs') -const PNG = require('png-js') - -const params = { width: 1242/3, height: 2208/3 } - -function decode(png) { - return new Promise((r) => { - png.decode((pixels) => r(pixels)) - }) -} - -async function gifAddFrame(page, encoder) { - const pngBuffer = await page.screenshot({ clip: { width: params.width, height: params.height, x: 0, y: 0 } }) - const png = new PNG(pngBuffer) - await decode(png).then((pixels) => encoder.addFrame(pixels)) -} - -;(async () => { - const browser = await puppeteer.launch({ - headless: true, - slowMo: 0, - }) - const page = await browser.newPage() - page.setViewport({ width: params.width, height: params.height }) - await page.goto('http://localhost:3000/draw?tempid=519', { - waitUntil: ['networkidle0'], - timeout: 60000, - }) - - const dstPath = path.join(__dirname, `test.gif`) - // create a write stream for GIF data - const writeStream = createWriteStream(dstPath) - writeStream.on('close', () => { - console.log('create is done') - }) - // createWriteStream().pipe(fs2.createWriteStream('test.gif')) - - // setting gif encoder - // record gif - var encoder = new GIFEncoder(params.width, params.height) - encoder.createReadStream().pipe(writeStream) - encoder.start() - encoder.setRepeat(0) - encoder.setDelay(200) - // encoder.setQuality(10) // default - - for (let i = 0; i < 5; i++) { - await gifAddFrame(page, encoder) - } - - // finish encoder, test.gif saved - encoder.finish() - - await browser.close() -})() diff --git a/screenshot/test/images.js b/screenshot/test/images.js deleted file mode 100644 index cc52c28..0000000 --- a/screenshot/test/images.js +++ /dev/null @@ -1,16 +0,0 @@ -/* - * @Author: ShawnPhang - * @Date: 2022-02-28 15:35:59 - * @Description: - * @LastEditors: ShawnPhang - * @LastEditTime: 2022-02-28 16:52:35 - */ - -const path = '/Users/mac/Documents/workSpace/Products/Management-Center/screenshot-service/static/screenshot-1-new.jpg' - -const images = require('images') - -const path233 = require('path') -// let tinyJpg = images(path233.resolve(__dirname, `../static/screenshot-1.png`)).size(300).encode('jpg', { quality: 20 }) -// images(tinyJpg).save(path) -let tinyJpg = images(path233.resolve(__dirname, `../static/screenshot-1.png`)).size(300).save(path, { quality: 30 }) diff --git a/test/png.html b/test/png.html deleted file mode 100644 index a257d57..0000000 --- a/test/png.html +++ /dev/null @@ -1,248 +0,0 @@ - - - - - - - - Document - - - - - - -

- - - - - \ No newline at end of file diff --git a/test/test.html b/test/test.html deleted file mode 100644 index 2eee9e3..0000000 --- a/test/test.html +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - Document - - - - -
-
-
-
-
asd
-
-
-
-
- -