Unverified Commit d70440ac authored by Bennett Piater's avatar Bennett Piater
Browse files

finish adapting enhance/grayscale

parent 25d5918b
......@@ -34,7 +34,7 @@ async function processImage(filename, data) {
.toBuffer((err, buffer) => {
if (err)
return;
writeToKafka("topic3", filename + ".enhanced.jpg", '{"data": "' + buffer.toString("base64") + '"}');
writeToKafka("topic3", filename + ".enhanced.jpg", JSON.stringify({data: buffer.toString("base64")}));
})
}
......
......@@ -7,7 +7,7 @@ async function writeToKafka(topic, key, json) {
brokers: ['ark-01.srvs.cloudkafka.com:9094', 'ark-02.srvs.cloudkafka.com:9094', 'ark-03.srvs.cloudkafka.com:9094'],
ssl: true,
sasl: {
mechanism: 'scram-sha-256',
mechanism: 'plain',
username: 'mra5q18k',
password: 'SddBJrfRgVWkWYCYhaw-J_5pDDDamZsS'
}
......@@ -23,24 +23,22 @@ async function writeToKafka(topic, key, json) {
}]
})
await producer.disconnect()
return {};
}
function main({img}) {
// TODO decide how data gets passed in
const image = Buffer.from(img, "base64");
async function processImage(filename, data) {
const image = Buffer.from(data, "base64");
return new Promise((resolve, reject) => {
gm(image, "test.jpg")
.monochrome()
.toBuffer((err, buffer) => {
if (err)
reject({ "error": err });
else {
writeToKafka("topic3", filename + ".grayscaled.jpg", '{"data": "' + buffer.toString("base64") + '"}');
resolve({});
}
});
});
gm(image, "test.jpg")
.monochrome()
.toBuffer((err, buffer) => {
if (err)
return;
writeToKafka("topic3", filename + ".gray.jpg", JSON.stringify({data: buffer.toString("base64")}));
})
}
function main({messages}) {
messages.forEach(msg => processImage(msg.key, msg.value.data))
}
exports.main = main
const gm = require('gm').subClass({imageMagick: true});
function main({img}) {
let data = Buffer.from(img, "base64");
// First, watermark the image
return new Promise((resolve, reject) => {
gm(data, "test.png")
.fontSize(20)
.fill("#FF0000")
.drawText(10, 10, "Bennett")
.toBuffer((err, buffer) => {
if (err)
reject({ "error": err });
else
resolve({ "img": buffer.toString("base64") });
});
});
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment