How to make text to image command

09/06/2020

Hello and welcome to this website! This website will be full of detailed tutorials and tips for BDFD! Tutorials here will be very detailed, so you understand what we're doing! Today, we are gonna make a command that generates images from our text input!

As you can see on the image i provided, this command is a little unique from the others you might have seen. You can specify the font you want in the command! That was just a little touch i added, but everybody apparently likes it, so i decided to make a tutorial on it! Let's break this command down!

First of all, we need a website, that puts the text we input onto the image! Unfortunately, the only way most bots (even the ones that aren't made with BDFD) can communicate with websites only through URLs, so we have to find an API that we can communicate with using its URL. That's called Signed URL API. I made a more complex article about API here. Today, we're gonna use flamingtext.com script that generates images based of what is in the URL. Let me explain.

Let's take this URL for example:

https://flamingtext.com/net-fu/proxy_form.cgi?script=smurfs-logo&text=bdfd&_loc=generate&imageoutput=true

Notice how i highlited the words smurfs and bdfd. If you copy this URL and open the website, it shows this:

Woah! It generated the word bdfd in the smurfs font! You can change the bdfd in the URL to anything you want (instead of spaces use %20) and it will generate you an image with that! You can also change the font, but make sure that the font is valid and exists on the flamingtext.com website.

So now that you understood how does the command work, let's make it. Start with $nomention. Take the URL that i showed you, replace the "smurfs" with $message[1] ($message[1] gives you the 1st word from the whole $message and we need that so users can specify their font). Also replace the "bdfd" with the rest of our message. You could do $message[2] $message[3] $message[4] etc, but that would make the command long, and we can't use spaces anyway, look here if you're interested why. Instead, we could use $replaceText to replace all spaces with %20, but we also need to remove the $message[1]! That was really hard for me at first, but then i figured i could use $replaceText to replace $message[1] in $message with nothing, which gives me the rest. So combining 2 replaceText elements gives us this: $replaceText[$replaceText[$message; ;%20;-1];$message[1];;1]

Pretty simple in theory, but the text explaining it is really long. :D Oh, and put the URL in $image[url].

So here is our creation: $image[https://flamingtext.com/net-fu/proxy_form.cgi?script=$message[1]-logo&text=$replaceText[$replaceText[$message; ;%20;-1];$message[1];;1]%20&_loc=generate&imageoutput=true]

You could just finish with this, but the command wouldn't work properly if given a wrong font or just 1 argument, so let's add $argsCheck.

There is lots of fonts, but our command will support 21 of them. That's still a lot though, isn't it? Anyway, here is our code to check the arguments: $argsCheck[>2;Usage: `!textimage type(fluffy/smurfs/3d/comics/chrominium/clan/neon/water/glow/amped/birdy/steel/uprise/fortune/minions/star-wars/orlando/funtime/cookies/sugar/matrix) text`]

Also make it ignore completely wrong fonts with this code: $onlyIf[$checkContains[$message;fluffy;smurfs;3d;comics;chrominium;clan;neon;water;glow;amped;birdy;steel;uprise;fortune;minions;star-wars;orlando;funtime;cookies;sugar;matrix]==true;I don't think that $message[1] is a valid font! The fonts you can use are: `fluffy` `smurfs` `3d` `comics` `chrominium` `clan` `neon` `water` `glow` `amped` `birdy` `steel` `uprise` `fortune` `minions` `star-wars` `orlando` `funtime` `cookies` `sugar` `matrix`]

And there we have it! Text to image command where users can specify a font! I hope you enjoyed and if there is any problem, ping me (tobiagamesyt#5852) in the official BDFD server! You can also try this command on my bot in the official BDFD testing server!

Create your website for free! This website was made with Webnode. Create your own for free today! Get started