webp support + other fixes
This commit is contained in:
parent
77cb76e48f
commit
f20031b673
@ -11,25 +11,32 @@ import validators
|
||||
import wget
|
||||
import subprocess
|
||||
import glob, os
|
||||
import requests
|
||||
|
||||
def main(imgPath, delay, ASCIIWIDTH, COLORCHAR, FILLER, fileType):
|
||||
if validators.url(imgPath) == True:
|
||||
for f in glob.glob("P*.png"):
|
||||
os.remove(f)
|
||||
for f in glob.glob("P*.jpg"):
|
||||
os.remove(f)
|
||||
if os.path.exists("image.png"):
|
||||
os.remove("image.png")
|
||||
if os.path.exists("image.jpg"):
|
||||
os.remove("image.jpg")
|
||||
if os.path.exists("image.webp"):
|
||||
os.remove("image.webp")
|
||||
if os.path.exists("output.txt"):
|
||||
os.remove("output.txt")
|
||||
if validators.url(imgPath) == True:
|
||||
print('URL')
|
||||
print('Downloading image to ' + "/home/node/app/image." + fileType)
|
||||
wget.download(imgPath, "/home/node/app/image." + fileType)
|
||||
#subprocess.run(["wget", imgPath, "-o", "image." + fileType])
|
||||
#wget.download(imgPath, "/home/node/app/image." + fileType)
|
||||
imagefile = requests.get(imgPath)
|
||||
open("/home/node/app/image." + fileType, "wb").write(imagefile.content)
|
||||
if fileType == "png":
|
||||
print('PNG')
|
||||
imgPath = "/home/node/app/image.png"
|
||||
if fileType == "jpg":
|
||||
print('JPG')
|
||||
imgPath = "/home/node/app/image.jpg"
|
||||
if fileType == "webp":
|
||||
print('WEBP')
|
||||
imgPath = "/home/node/app/image.webp"
|
||||
|
||||
im = Image.open(imgPath, 'r')
|
||||
im = ImageOps.scale(im, ASCIIWIDTH / im.width)
|
||||
|
@ -1,3 +1,4 @@
|
||||
Pillow==8.0.1
|
||||
validators==0.20.0
|
||||
wget==3.2
|
||||
requests==2.22.0
|
10
bot.js
10
bot.js
@ -9,7 +9,7 @@ var config = { //edit your shit here
|
||||
server: "irc.supernets.org",
|
||||
port: 6697,
|
||||
SSL: true,
|
||||
channels: ['#fascinus'],
|
||||
channels: ['#dev'],
|
||||
botName: "fascinus",
|
||||
userName: "fascinus",
|
||||
realName: "Sneed"
|
||||
@ -107,11 +107,14 @@ async function rspam(chan, amt) {
|
||||
}
|
||||
|
||||
async function art(chan, url) {
|
||||
|
||||
var ext = path.extname(url)
|
||||
if (ext === ".png") {
|
||||
var filetype = "png"
|
||||
} else if (ext === ".jpg") {
|
||||
var filetype = "jpg"
|
||||
} else if (ext === ".webp") {
|
||||
var filetype = "webp"
|
||||
} else {
|
||||
bot.say(chan, "Image must be PNG or JPG");
|
||||
return
|
||||
@ -122,7 +125,7 @@ async function art(chan, url) {
|
||||
pythonProcess.stdout.on('data', (data) => {
|
||||
console.log(data.toString())
|
||||
});
|
||||
await timer(1000);
|
||||
await timer(5000);
|
||||
fs.stat('output.txt', function(err, stat) {
|
||||
if (err == null) {
|
||||
console.log('File exists');
|
||||
@ -134,9 +137,10 @@ async function art(chan, url) {
|
||||
bot.say(chan, line);
|
||||
});
|
||||
} else if (err.code === 'ENOENT') {
|
||||
console.log(err);
|
||||
bot.say(chan, "Error")
|
||||
} else {
|
||||
bot.say(chan, "Error")
|
||||
bot.say(chan, "Other Error")
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user