Init branch, WIP

Needs new library to merge images
This commit is contained in:
Logan Cusano
2023-03-11 23:07:48 -05:00
parent 8ed0b969dd
commit 9e2814cb2c
4 changed files with 75 additions and 4 deletions

View File

@@ -57,7 +57,7 @@ module.exports = {
log.DEBUG("Images in the result: ", imagesInResult);
if (imagesInResult == 1) dalleEmbed.setImage(imageResults.results.data[0].url);
if (imagesInResult != 0) dalleEmbed.setImage(imageResults.results.data[0].url);
await interaction.editReply({ embeds: [dalleEmbed], ephemeral: false });
});

View File

@@ -134,13 +134,13 @@ exports.submitTextPromptTransaction = async (prompt, temperature, max_tokens, di
pricePerImage = 800;
break;
default:
log.DEBUG("256px defaulted");
log.DEBUG("256px defaulted");
pricePerImage = 800;
break;
}
if (!images_to_generate) images_to_generate = 1;
if (!image_size) images_to_generate = "256x256";
if (!image_size) image_size = "256x256";
totalTokensToBeUsed = pricePerImage * images_to_generate;

View File

@@ -27,7 +27,8 @@
"node-html-markdown": "~1.3.0",
"node-html-parser": "~6.1.5",
"gpt-3-encoder": "~1.1.4",
"user-agents": "~1.0.1303"
"user-agents": "~1.0.1303",
"canvas": "~2.11.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",

70
utilities/mergeImages.js Normal file
View File

@@ -0,0 +1,70 @@
const { createCanvas, loadImage } = require("canvas");
const fs = require("fs");
/**
*
* @param {Array} images The array of images to be merged together
* @param {function} callback The callback function to call with the merged images
* @returns {*} A PNG encoded image
*/
exports.mergeImages = async (images, callback) => {
if (!images) return callback(new Error("No images provided to merge"), undefined);
const numberOfImages = images.length;
const finalImageWidth = 1024;
const finalImageHeight = 1024;
switch(numberOfImages) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
break;
}
const imagePosition = {
w: 400,
h: 88,
x: 400,
// Calculate the Y of the image based on the number of
// lines in the title.
y: titleText.length === 2 ? 75 : 100,
};
}
// Do the same with the title's Y value.
const titleY = titleText.length === 2 ? 300 : 350;
const titleLineHeight = 100;
// And the author's Y value.
const authorY = titleText.length === 2 ? 525 : 500;
const canvas = createCanvas(width, height);
const context = canvas.getContext("2d");
context.fillStyle = "#764abc";
context.fillRect(0, 0, width, height);
context.font = "bold 70pt 'PT Sans'";
context.textAlign = "center";
context.fillStyle = "#fff";
context.fillText(titleText[0], 600, titleY);
if (titleText[1]) context.fillText(titleText[1], 600, titleY + titleLineHeight);
context.font = "40pt 'PT Sans'";
context.fillText(`by ${post.author}`, 600, authorY);
await loadImage("./assets/logo.png").then((image) => {
const { w, h, x, y } = imagePosition;
context.drawImage(image, x, y, w, h);
});
const buffer = canvas.toBuffer("image/png");
fs.writeFileSync("./image.png", buffer);