mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: let sharp be optional
This commit is contained in:
parent
5fceef37ec
commit
94c655367e
4 changed files with 15 additions and 2 deletions
0
.npmrc
Normal file
0
.npmrc
Normal file
|
|
@ -72,7 +72,11 @@ pnpm i
|
||||||
> 3. 使用vnc客户端连接至云桌面
|
> 3. 使用vnc客户端连接至云桌面
|
||||||
>
|
>
|
||||||
> 右键Applications > Shells > Bash打开终端,然后进入Yunzai目录下运行node app即可。
|
> 右键Applications > Shells > Bash打开终端,然后进入Yunzai目录下运行node app即可。
|
||||||
|
>
|
||||||
|
> 4. 执行pnpm i时,sharp安装失败
|
||||||
>
|
>
|
||||||
|
> sharp不影响chatgpt聊天,仅影响Dalle2绘图功能。ubuntu可以执行`apt install libvips-dev`之后再`pnpm i`
|
||||||
|
>
|
||||||
> 实测该方案资源占用低,运行稳定,基本1核2G的轻量云服务器就足够了。
|
> 实测该方案资源占用低,运行稳定,基本1核2G的轻量云服务器就足够了。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,10 @@
|
||||||
"puppeteer-extra-plugin-recaptcha": "^3.6.6",
|
"puppeteer-extra-plugin-recaptcha": "^3.6.6",
|
||||||
"puppeteer-extra-plugin-stealth": "^2.11.1",
|
"puppeteer-extra-plugin-stealth": "^2.11.1",
|
||||||
"random": "^4.1.0",
|
"random": "^4.1.0",
|
||||||
"sharp": "^0.31.3",
|
|
||||||
"undici": "^5.19.1",
|
"undici": "^5.19.1",
|
||||||
"uuid": "^9.0.0"
|
"uuid": "^9.0.0"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"sharp": "^0.31.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ import { Configuration, OpenAIApi } from 'openai'
|
||||||
import { Config } from './config.js'
|
import { Config } from './config.js'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import { mkdirs } from './common.js'
|
import { mkdirs } from './common.js'
|
||||||
import sharp from 'sharp'
|
|
||||||
export async function createImage (prompt, n = 1, size = '512x512') {
|
export async function createImage (prompt, n = 1, size = '512x512') {
|
||||||
const configuration = new Configuration({
|
const configuration = new Configuration({
|
||||||
apiKey: Config.apiKey
|
apiKey: Config.apiKey
|
||||||
|
|
@ -56,6 +56,13 @@ export async function imageVariation (imageUrl, n = 1, size = '512x512') {
|
||||||
|
|
||||||
async function resizeAndCropImage (inputFilePath, outputFilePath, size = 512) {
|
async function resizeAndCropImage (inputFilePath, outputFilePath, size = 512) {
|
||||||
// Determine the maximum dimension of the input image
|
// Determine the maximum dimension of the input image
|
||||||
|
let sharp
|
||||||
|
try {
|
||||||
|
sharp = await import('sharp')
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('sharp未安装,请执行 pnpm install sharp@0.31.3')
|
||||||
|
throw new Error('sharp未安装,请执行 pnpm install sharp@0.31.3')
|
||||||
|
}
|
||||||
const metadata = await sharp(inputFilePath).metadata()
|
const metadata = await sharp(inputFilePath).metadata()
|
||||||
const maxDimension = Math.max(metadata.width, metadata.height)
|
const maxDimension = Math.max(metadata.width, metadata.height)
|
||||||
logger.mark(`original picture size is ${metadata.width} x ${metadata.height}`)
|
logger.mark(`original picture size is ${metadata.width} x ${metadata.height}`)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue