diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index d53ae45..b66be82 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,11 @@ pnpm i > 3. 使用vnc客户端连接至云桌面 > > 右键Applications > Shells > Bash打开终端,然后进入Yunzai目录下运行node app即可。 +> +> 4. 执行pnpm i时,sharp安装失败 > +> sharp不影响chatgpt聊天,仅影响Dalle2绘图功能。ubuntu可以执行`apt install libvips-dev`之后再`pnpm i` +> > 实测该方案资源占用低,运行稳定,基本1核2G的轻量云服务器就足够了。 --- diff --git a/package.json b/package.json index 29ae2e5..2e352cf 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,10 @@ "puppeteer-extra-plugin-recaptcha": "^3.6.6", "puppeteer-extra-plugin-stealth": "^2.11.1", "random": "^4.1.0", - "sharp": "^0.31.3", "undici": "^5.19.1", "uuid": "^9.0.0" + }, + "optionalDependencies": { + "sharp": "^0.31.3" } } \ No newline at end of file diff --git a/utils/dalle.js b/utils/dalle.js index eb25eba..ccdc5c2 100644 --- a/utils/dalle.js +++ b/utils/dalle.js @@ -2,7 +2,7 @@ import { Configuration, OpenAIApi } from 'openai' import { Config } from './config.js' import fs from 'fs' import { mkdirs } from './common.js' -import sharp from 'sharp' + export async function createImage (prompt, n = 1, size = '512x512') { const configuration = new Configuration({ apiKey: Config.apiKey @@ -56,6 +56,13 @@ export async function imageVariation (imageUrl, n = 1, size = '512x512') { async function resizeAndCropImage (inputFilePath, outputFilePath, size = 512) { // 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 maxDimension = Math.max(metadata.width, metadata.height) logger.mark(`original picture size is ${metadata.width} x ${metadata.height}`)