Closed UlisesGascon closed 5 years ago
Seria bueno ver más fuentes de datos... @Fa-v y @KoolTheba
He encontrado estos, no los he revisado con detenimieto pero los dejo aquí para no perderlos
https://memegenerator.net/ https://github.com/Floby/node-meme
https://market.mashape.com/ronreiter/meme-generator https://github.com/jacebrowning/memegen https://apidocs.imgur.com/ https://mememaker.github.io/API/
Objetivos para la obtención de las imágenes
http://alpha-meme-maker.herokuapp.com/:page
con request
tags
en un Arrayimage
en img_src
memes/data.json
memes/{uuid}.jpg
detectSafeSearch
para saber si la imagen contiene contenido explícitodetectProperties
para obtener los colores predominantestinyPng
para comprimir las imágenes y generar los thumbsObjetivos para la subida de las imágenes
data.json
a firebase Realtime Databaseimg
e img_thumb
Notas
Descargar un json con Request
function downloadJSON (){
var request = require('request');
request('http://alpha-meme-maker.herokuapp.com/1', function (error, response, body) {
if(error) {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
} else {
const data = JSON.parse(body)
console.log('data:', data.data);
console.log('has next?', data.next)
}
});
}
Descargar una foto como Request
function downloadIMG (){
//@see: https://stackoverflow.com/a/12751657
var fs = require('fs'),
request = require('request');
var download = function(uri, filename, callback){
request.head(uri, function(err, res, body){
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
};
download('https://imgflip.com/s/meme/Futurama-Fry.jpg', 'Futurama-Fry.jpg', function(){
console.log('done');
});
}
Generar un UUID
function uuidGenerator (){
const uuidv4 = require('uuid/v4');
return uuidv4();
}
Guardar un JSON como fichero
function saveData(){
const fs = require("fs");
const data = { ID: 54,
bottomText: '',
image: 'https://imgflip.com/s/meme/Insanity-Wolf.jpg',
name: 'Insanity Wolf',
rank: 205,
tags: 'animal, insane, dog',
topText: '' };
fs.writeFile('data.json', JSON.stringify(data), 'utf8', (err)=>{
console.log(err ? err: "done!")
})
}
Detectar el contenido explicito
Documentación sobre credenciales
async function detectSafeSearch() {
// @see: https://github.com/googleapis/nodejs-vision/blob/master/samples/detect.js#L287
// @Ulises: export GOOGLE_APPLICATION_CREDENTIALS="secrets.json"
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient();
const fileName = 'Futurama-Fry.jpg';
// Performs safe search detection on the local file
const [result] = await client.safeSearchDetection(fileName);
const detections = result.safeSearchAnnotation;
console.log('Safe search:');
console.log(`Adult: ${detections.adult}`);
console.log(`Medical: ${detections.medical}`);
console.log(`Spoof: ${detections.spoof}`);
console.log(`Violence: ${detections.violence}`);
console.log(`Racy: ${detections.racy}`);
}
Detectar los colores dominantes
async function detectProperties() {
const vision = require('@google-cloud/vision');
const client = new vision.ImageAnnotatorClient();
const fileName = 'Futurama-Fry.jpg';
const [result] = await client.imageProperties(fileName);
const colors = result.imagePropertiesAnnotation.dominantColors.colors;
colors.forEach(color => console.log(color));
}
Comprimir imagen
function compressIMG (){
const tinify = require("tinify");
const config = require("./config")
tinify.key = config.tinypng;
tinify.fromFile("Futurama-Fry.jpg").toFile("Futurama-Fry_compressed.jpg");
console.log("Done!")
}
Generar thumb
function generateThumb () {
const tinify = require("tinify");
const config = require("./config")
tinify.key = config.tinypng;
tinify
.fromFile("Futurama-Fry.jpg")
.resize({
method: "thumb",
width: 150,
height: 100
}).toFile("Futurama-Fry_thumb.jpg");
}
Subir datos a Firebase
function saveDataFirebase(){
const firebase = require("firebase");
const config = require("./config");
firebase.initializeApp(config.firebase);
const db = firebase.database();
const ref = db.ref("memes");
const id = "Insanity_Wolf"
const data = { ID: 54,
bottomText: '',
image: 'https://imgflip.com/s/meme/Insanity-Wolf.jpg',
name: 'Insanity Wolf',
rank: 205,
tags: 'animal, insane, dog',
topText: '' }
ref.child(id).set(data)
}
Subir Imágenes a Cloud Storage
function saveFile () {
const {Storage} = require('@google-cloud/storage');
const config = require("./config");
const projectId = config.gcs.projectId;
const bucketName = config.gcs.bucketName;
const storage = new Storage({projectId});
const fileName = 'Futurama-Fry.jpg';
storage
.bucket(`gs://${bucketName}`)
.upload(`${fileName}`, {destination: `memes/${fileName}`})
.then(() => {
console.log(`${fileName} uploaded to gs://${bucketName}/memes/`);
})
.catch(err => {
console.error('ERROR:', err);
});
}
Generar URL pública imágenes de Cloud Storage
function makePublicFile () {
const {Storage} = require('@google-cloud/storage');
const config = require("./config");
const projectId = config.gcs.projectId;
const bucketName = config.gcs.bucketName;
const storage = new Storage({projectId});
const fileName = 'Futurama-Fry.jpg';
storage
.bucket(`gs://${bucketName}`)
.file(`memes/${fileName}`)
.makePublic()
.then(() => {
console.log(`gs://${bucketName}/memes/${fileName} is now public.`)
console.log(`Public URL: https://storage.googleapis.com/${bucketName}/memes/${fileName}`)
})
.catch(console.error)
}
node-exiftool
para añadir un powered-by: "Memezinga"
y memezinga-version: 1.0.0
Leer metadatos
function readMetadata () {
const exiftool = require('node-exiftool')
const exiftoolBin = require('dist-exiftool')
const ep = new exiftool.ExiftoolProcess(exiftoolBin)
ep
.open()
.then((pid) => console.log('Started exiftool process %s', pid))
.then(() => ep.readMetadata('Futurama-Fry_compressed.jpg', ['-File:all']))
.then(console.log, console.error)
.then(() => ep.close())
.then(() => console.log('Closed exiftool'))
.catch(console.error)
}
Escribir metadatos
// @TODO: Investigar
Objetivos