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