mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
use sharp
to transform to jpeg
This commit is contained in:
parent
65cab457ff
commit
86321e56d1
@ -30,7 +30,8 @@
|
||||
"passport": "0.5.2",
|
||||
"passport-jwt": "4.0.0",
|
||||
"passport-local": "1.0.0",
|
||||
"path-to-regexp": "6.2.0"
|
||||
"path-to-regexp": "6.2.0",
|
||||
"sharp": "^0.31.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"cross-env": "^7.0.3",
|
||||
|
@ -1,5 +1,9 @@
|
||||
const tf = require("@tensorflow/tfjs-node")
|
||||
import * as nsfwjs from "nsfwjs/dist"
|
||||
import sharp from "sharp"
|
||||
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
|
||||
import readImage from "../read-image"
|
||||
import imageByteArray from "../image-byte-array"
|
||||
@ -17,6 +21,22 @@ export default async (payload) => {
|
||||
|
||||
const model = await nsfwjs.load()
|
||||
|
||||
// check if image is not a jpg
|
||||
if (image.indexOf(".jpg") === -1) {
|
||||
// convert image to jpg
|
||||
const converted = await sharp(image)
|
||||
.jpeg()
|
||||
.toBuffer()
|
||||
|
||||
// write converted image to disk (use cache)
|
||||
const destination = path.resolve(global.uploadCachePath, `${Date.now()}.jpg`)
|
||||
|
||||
fs.writeFileSync(destination, converted)
|
||||
|
||||
// set image to the converted image
|
||||
image = destination
|
||||
}
|
||||
|
||||
const logo = readImage(image)
|
||||
const input = imageToInput(logo, channels)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user