fix wip aggregate pictures
This commit is contained in:
parent
7ef228aa49
commit
4026118826
@ -91,9 +91,12 @@ http://localhost:8000
|
||||
|
||||
# Notes
|
||||
|
||||
ce site n'a pas besoin d'être hébergé sur le serveur de l'instance qu'il utilise
|
||||
ce site n'a pas besoin d'être hébergé sur le serveur de l'instance qu'il utilise.
|
||||
|
||||
Venez causer sur mastodon!
|
||||
Ceci utilise un fichier sqlite comme base de données, vous pouvez faire des ajouts en base avec un bon IDE sans avoir à
|
||||
|
||||
Ceci utilise un fichier sqlite et des jsons comme base de données, vous pouvez faire des ajouts en base avec un bon IDE
|
||||
sans avoir à
|
||||
développer d'interface web.
|
||||
Les merge requests sont bienvenues.
|
||||
|
||||
|
BIN
documents/generated_pictures/combined_images.jpg
Normal file
BIN
documents/generated_pictures/combined_images.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
83
gather_pics.js
Normal file
83
gather_pics.js
Normal file
@ -0,0 +1,83 @@
|
||||
const sharp = require('sharp');
|
||||
const axios = require('axios');
|
||||
const fs = require('fs').promises;
|
||||
const path = require('path');
|
||||
|
||||
async function downloadImage(url, destination) {
|
||||
try {
|
||||
const response = await axios({
|
||||
url,
|
||||
method: 'GET',
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
await fs.writeFile(destination, response.data);
|
||||
} catch (error) {
|
||||
console.error(`Erreur lors du téléchargement de l'image ${url}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function generateImage(imageUrls, outputPath) {
|
||||
const tempDir = path.join(__dirname, 'temp');
|
||||
await fs.mkdir(tempDir, {recursive: true});
|
||||
|
||||
const images = [];
|
||||
|
||||
for (const imageUrl of imageUrls) {
|
||||
try {
|
||||
const tempPath = path.join(tempDir, `${Date.now()}-${Math.random().toString(36).substr(2, 9)}.jpg`);
|
||||
await downloadImage(imageUrl, tempPath);
|
||||
images.push(sharp(tempPath));
|
||||
} catch (error) {
|
||||
console.error(`Impossible de télécharger l'image ${imageUrl}. Elle sera ignorée.`);
|
||||
}
|
||||
}
|
||||
|
||||
if (images.length === 0) {
|
||||
throw new Error("Aucune image n'a pu être téléchargée.");
|
||||
}
|
||||
|
||||
const firstImage = await images[0].metadata();
|
||||
const width = firstImage.width;
|
||||
const height = firstImage.height;
|
||||
|
||||
const composite = sharp({
|
||||
create: {
|
||||
width: width * images.length,
|
||||
height,
|
||||
channels: 4,
|
||||
background: {r: 255, g: 255, b: 255, alpha: 1}
|
||||
}
|
||||
});
|
||||
|
||||
const compositeOperations = await Promise.all(images.map(async (image, index) => ({
|
||||
input: await image.toBuffer(),
|
||||
top: 0,
|
||||
left: width * index
|
||||
})));
|
||||
|
||||
await composite.composite(compositeOperations).toFile(outputPath);
|
||||
|
||||
// Supprimer les images temporaires
|
||||
for (const image of images) {
|
||||
image.destroy();
|
||||
}
|
||||
|
||||
const files = await fs.readdir(tempDir);
|
||||
for (const file of files) {
|
||||
await fs.unlink(path.join(tempDir, file));
|
||||
}
|
||||
}
|
||||
|
||||
// Exemple d'utilisation
|
||||
const imageUrls = [
|
||||
'https://mastodon.cipherbliss.com/system/cache/accounts/avatars/000/012/606/original/37deaa900b17861d.png',
|
||||
'https://mastodon.cipherbliss.com/system/cache/accounts/avatars/000/012/606/original/37deaa900b17861d.png',
|
||||
'https://mastodon.cipherbliss.com/system/cache/accounts/avatars/000/012/606/original/37deaa900b17861d.png',
|
||||
];
|
||||
|
||||
const outputPath = path.join(__dirname, 'documents', 'generated_pictures', 'combined_images.jpg');
|
||||
|
||||
generateImage(imageUrls, outputPath)
|
||||
.then(() => console.log('Image générée avec succès!'))
|
||||
.catch((err) => console.error('Erreur lors de la génération de l\'image:', err));
|
4136
package-lock.json
generated
4136
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -11,7 +11,6 @@
|
||||
"@databases/sqlite": "^4.0.0",
|
||||
"cookie-parser": "~1.4.4",
|
||||
"debug": "~2.6.9",
|
||||
"dotenv": "^16.0.1",
|
||||
"express": "~4.16.1",
|
||||
"http-errors": "~1.6.3",
|
||||
"jade": "~1.11.0",
|
||||
@ -30,8 +29,10 @@
|
||||
"axios": "^1.6.7",
|
||||
"cheerio": "^1.0.0-rc.12",
|
||||
"csv-parser": "^3.1.0",
|
||||
"dotenv": "^16.4.7",
|
||||
"fs": "^0.0.1-security",
|
||||
"https": "^1.0.0",
|
||||
"mastodon-api": "^1.3.0",
|
||||
"node-fetch": "^3.2.10",
|
||||
"nodemon": "^2.0.22",
|
||||
"path": "^0.12.7",
|
||||
|
@ -1,13 +1,13 @@
|
||||
import fs from "fs";
|
||||
import path from 'path';
|
||||
import {getRandomElementOfArray, listFilesOfFolder} from '../libs/utils.mjs'
|
||||
import {getRandomElementOfArray, listFilesOfFolder} from '../helpers/libs/utils.mjs'
|
||||
import Masto from "mastodon";
|
||||
import pictureFolderDescriptions from "../helpers/libs/describe_picture_folders.mjs"
|
||||
|
||||
const __dirname = path.resolve();
|
||||
|
||||
// choisir un type de publication au hasard dans les dossiers "picture"
|
||||
|
||||
import pictureFolderDescriptions from "../libs/describe_picture_folders.mjs"
|
||||
const typeOfFolder = getRandomElementOfArray(Object.keys(pictureFolderDescriptions))
|
||||
|
||||
console.log(typeOfFolder)
|
||||
@ -17,6 +17,7 @@ const folderMemePublished = 'assets/pictures/meme/published/'
|
||||
const list_unpublished_images = listFilesOfFolder(folderMemeUnpublished)
|
||||
|
||||
const reallySendPost = false;
|
||||
|
||||
// const reallySendPost = true;
|
||||
|
||||
|
||||
@ -28,7 +29,7 @@ function postLink() {
|
||||
let selectedImage = 'meme_default.jpg';
|
||||
if (list_unpublished_images.length) {
|
||||
selectedImage = getRandomElementOfArray(list_unpublished_images)
|
||||
}else{
|
||||
} else {
|
||||
console.log("----- nothing to publish -----")
|
||||
return;
|
||||
}
|
||||
@ -57,7 +58,7 @@ function postLink() {
|
||||
api_url: process.env.INSTANCE_MASTODON + '/api/v1/',
|
||||
});
|
||||
|
||||
masto.post('media', {file: fs.createReadStream( folderMemeUnpublished + configPost.image)})
|
||||
masto.post('media', {file: fs.createReadStream(folderMemeUnpublished + configPost.image)})
|
||||
.then(resp => {
|
||||
id = resp.data.id;
|
||||
configPost.media_ids = [id]
|
||||
@ -82,7 +83,8 @@ function postLink() {
|
||||
* move to published
|
||||
* @param imageName
|
||||
*/
|
||||
function moveImageToPublishedFolder(imageName){
|
||||
function moveImageToPublishedFolder(imageName) {
|
||||
return fs.renameSync(folderMemeUnpublished + imageName, folderMemePublished + imageName)
|
||||
}
|
||||
|
||||
postLink();
|
Loading…
x
Reference in New Issue
Block a user