Skip to content

Commit

Permalink
Enhance image now use only for url and add textToImage
Browse files Browse the repository at this point in the history
  • Loading branch information
thoriqazzikraa committed Aug 24, 2023
1 parent c5e0c21 commit 7cd11b2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
`const scrape = require("scrape-websitee")`

# Endpoints
` textToImage
`scrape.textToImage(text)`

- uploadFile
`scrape.uploadFile(buffer)`

- enhanceImg
`scrape.enhanceImg(buffer)`
`scrape.enhanceImg(url)`

- twitterdl2
`scrape.twitterdl2(url)`
Expand Down
30 changes: 26 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ const pickRandom = async (ext) => {
return ext[Math.floor(Math.random() * ext.length)];
};

async function textToImage(text) {
try {
const { data } = await axios.get(
"https://tti.photoleapapp.com/api/v1/generate?prompt=" + text
);
const enhanceImages = await enhanceImg(data.result_url, 2);
const result = {
status: true,
url: enhanceImages.url,
};
return result;
} catch (err) {
const result = {
status: false,
message: String(err),
};
console.log(result);
return result;
}
}

async function uploadFile(buffer) {
const { ext, mime } = await fromBuffer(buffer);
const filePath = `temp/${Date.now()}.${ext}`;
Expand All @@ -30,13 +51,13 @@ async function uploadFile(buffer) {
return data;
}

async function enhanceImg(buffer) {
const media = await uploadFile(image);
async function enhanceImg(url, scale) {
const scaleNumber = scale ? scale : 2;
const { data } = await axios(`https://toolsapi.spyne.ai/api/forward`, {
method: "post",
data: {
image_url: media.files[0].url,
scale: 4,
image_url: url,
scale: scaleNumber,
save_params: {
extension: ".png",
quality: 95,
Expand Down Expand Up @@ -544,6 +565,7 @@ async function filmApikDl(url) {
}

module.exports = {
textToImage,
uploadFile,
enhanceImg,
twitterdl2,
Expand Down

0 comments on commit 7cd11b2

Please sign in to comment.