diff options
author | Volpeon <git@volpeon.ink> | 2021-10-22 07:11:25 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2021-10-22 07:11:25 +0200 |
commit | a022d881f8112804a8f168dd55db9b5c6add2562 (patch) | |
tree | 13de0007447c6288804b43b681fa280137a02c70 /src | |
parent | Blacklist 672088 (diff) | |
download | feralbot-a022d881f8112804a8f168dd55db9b5c6add2562.tar.gz feralbot-a022d881f8112804a8f168dd55db9b5c6add2562.tar.bz2 feralbot-a022d881f8112804a8f168dd55db9b5c6add2562.zip |
Add image dimension check
Diffstat (limited to 'src')
-rw-r--r-- | src/services/jobs.ts | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/services/jobs.ts b/src/services/jobs.ts index 354c66d..878593b 100644 --- a/src/services/jobs.ts +++ b/src/services/jobs.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import * as e621 from "../api/e926"; | 1 | import * as e621 from "../api/e926"; |
2 | import * as mastodon from "../api/mastodon"; | 2 | import * as mastodon from "../api/mastodon"; |
3 | import config from "../config"; | 3 | import config from "../config"; |
4 | import { imageSize } from "image-size"; | ||
4 | import Sharp from "sharp"; | 5 | import Sharp from "sharp"; |
5 | 6 | ||
6 | export async function postSpecificPicture(id: number) { | 7 | export async function postSpecificPicture(id: number) { |
@@ -33,11 +34,15 @@ async function handlePost(post: e621.Post) { | |||
33 | 34 | ||
34 | let file = await e621.client.get(post.file.url).buffer(); | 35 | let file = await e621.client.get(post.file.url).buffer(); |
35 | 36 | ||
36 | if (Buffer.byteLength(file) > 1024 * 1024 * 9) { | 37 | const dims = imageSize(file); |
38 | const width = dims.width ?? 0; | ||
39 | const height = dims.height ?? 0; | ||
40 | |||
41 | if (Buffer.byteLength(file) > 1024 * 1024 * 9 || width > 2000 || height > 2000) { | ||
37 | console.log(`Compressing...`); | 42 | console.log(`Compressing...`); |
38 | 43 | ||
39 | file = await Sharp(file) | 44 | file = await Sharp(file) |
40 | .resize(1800, 1800, { fit: "inside", withoutEnlargement: true }) | 45 | .resize(2000, 2000, { fit: "inside", withoutEnlargement: true }) |
41 | .jpeg({ quality: 80, mozjpeg: true }) | 46 | .jpeg({ quality: 80, mozjpeg: true }) |
42 | .toBuffer(); | 47 | .toBuffer(); |
43 | } | 48 | } |