summaryrefslogtreecommitdiffstats
path: root/src/services
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2021-10-22 07:11:25 +0200
committerVolpeon <git@volpeon.ink>2021-10-22 07:11:25 +0200
commita022d881f8112804a8f168dd55db9b5c6add2562 (patch)
tree13de0007447c6288804b43b681fa280137a02c70 /src/services
parentBlacklist 672088 (diff)
downloadferalbot-a022d881f8112804a8f168dd55db9b5c6add2562.tar.gz
feralbot-a022d881f8112804a8f168dd55db9b5c6add2562.tar.bz2
feralbot-a022d881f8112804a8f168dd55db9b5c6add2562.zip
Add image dimension check
Diffstat (limited to 'src/services')
-rw-r--r--src/services/jobs.ts9
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 @@
1import * as e621 from "../api/e926"; 1import * as e621 from "../api/e926";
2import * as mastodon from "../api/mastodon"; 2import * as mastodon from "../api/mastodon";
3import config from "../config"; 3import config from "../config";
4import { imageSize } from "image-size";
4import Sharp from "sharp"; 5import Sharp from "sharp";
5 6
6export async function postSpecificPicture(id: number) { 7export 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 }