Is there any way to show a pictures from url

decinbr

Veteran
Veteran
Joined
Mar 20, 2015
Messages
125
Reaction score
9
First Language
brazil
Primarily Uses
Is there any way to show picture from url link? In order to show news abou the game to the players
 

Hyouryuu-Na

Very very lazy
Veteran
Joined
Jun 15, 2017
Messages
1,081
Reaction score
2,682
First Language
Not English
Primarily Uses
RMMV
Yes, it's possible. You can do it using the following snippet. Note that I did not write it. I merely dug through stack exchange and put it together and so, no need to credit me. Save this as a .js file and put it inside js/plugins and turn it ON in the plugin manager. You can call it with img.save(url,destination)
Example: img.save("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png","img/pictures/test.png");
This will save the google logo to the pictures folder inside img folder as test.png
Every time the function is called, the image will be redownloaded so you can easily replace the file in the link. I guess if you keep the image in github as public, then the link will be same even if you replace the image. Idk, you have to think that through. And you can show it using the show picture command or script call if needed.
JavaScript:
/*url= The url of the image.
//dest= Where you want to save the image.
Example:img.save("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png","img/pictures/test.png");
This will save the google logo to the pictures folder inside img folder as test.png
*/

class img {
    static save(url, dest) {
        function toDataUrl(url, callback) {
            var xhr = new XMLHttpRequest();
            xhr.onload = function() {
                var reader = new FileReader();
                reader.onloadend = function() {
                    callback(reader.result);
                }
                reader.readAsDataURL(xhr.response);
            };
            xhr.open('GET', url);
            xhr.responseType = 'blob';
            xhr.send();
        }
        toDataUrl(url, function(data64) {
            console.log(data64);
            var fs = require('fs');
            var img = data64;
            var data = img.replace(/^data:image\/\w+;base64,/, "");
            var buf = new Buffer(data, 'base64');
            console.log(buf);
            fs.writeFileSync(dest, buf);
        });
    }
}
Reference:
Getting the image data(2nd reply)
Saving the image data
 

Hyouryuu-Na

Very very lazy
Veteran
Joined
Jun 15, 2017
Messages
1,081
Reaction score
2,682
First Language
Not English
Primarily Uses
RMMV
You've made a mistake. The url will be inside "".
Correction:
img.save("https://raw.githubusercontent.com/Decinbr/FW-Updater/master/GGolem(1).png","img/pictures/test.png")

After that, it should currently be in your pictures folder named as test.png. You have to manually show it using the 'show picture' command. The idea is to download the image first and then show it so this script call will download it and then you have to show it.

Btw, can you give me more info about what you're trying to do? I think there can be better solutions for your problem if you elaborate a bit.
 
Last edited:

decinbr

Veteran
Veteran
Joined
Mar 20, 2015
Messages
125
Reaction score
9
First Language
brazil
Primarily Uses
Worked like a charm! Thanks for your life!
One more doubt... Can i show a message from github and be showed inside game?
 

Hyouryuu-Na

Very very lazy
Veteran
Joined
Jun 15, 2017
Messages
1,081
Reaction score
2,682
First Language
Not English
Primarily Uses
RMMV
A text file? Yeah, you can. I'm getting ready to sleep so can't test it out but this code is pretty straightforward.
See the first reply. If you have problems, I'll try to help tomorrow or maybe someone else can.
 

decinbr

Veteran
Veteran
Joined
Mar 20, 2015
Messages
125
Reaction score
9
First Language
brazil
Primarily Uses
I will wait you, because im newbie on these things. I am immensely grateful to you!!
 

Hyouryuu-Na

Very very lazy
Veteran
Joined
Jun 15, 2017
Messages
1,081
Reaction score
2,682
First Language
Not English
Primarily Uses
RMMV
I'm not good with js either but I can frankencode parts together XD
So this is what I managed to do. You can paste this under the previous snippet I posted or make a new .js file with only this.
JavaScript:
class text {
    static set(variable, url) {
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url);
        xhr.onload = function() {
            $gameVariables.setValue(variable, xhr.responseText);
        }
        xhr.send();
    }
}
Example of usage: text.set(1,"https://12Me21.github.io/test.txt");
This will set the text in that text file in game variable 1.
Btw, note that getting text takes time so you have to include a wait between calling this function and and showing the text. Otherwise, you won't get the text. It can be from 10-60 frames depending on how big the text is. For images too, you have to include the wait and I've seen instead of show text command, script call works better in this case for some reason.
1610025070847.png
This is quite inconvenient but I don't know any other way. You could request for a full plugin instead of these tiny snippets in the plugin requests section for better solutions.
 

decinbr

Veteran
Veteran
Joined
Mar 20, 2015
Messages
125
Reaction score
9
First Language
brazil
Primarily Uses
I got this error... Screenshot_1.png
 

decinbr

Veteran
Veteran
Joined
Mar 20, 2015
Messages
125
Reaction score
9
First Language
brazil
Primarily Uses
Its me again lol.
Is working in my project editor, but when i deploy the game to windows i get this error...

Screenshot_1.png
 

Latest Threads

Latest Profile Posts

Gameboy Tiles, Cure Writer's Block, Animations on Menu, Generate Tasks | RPG Maker News #40

How would you judge a game you played? Art/Graphics? Story? Gameplay?
Learn MV sales goal = 2%
NSFW game sales goal = 2500% (no jokes) :guffaw:
After gathering, sorting out & reconsidering hundreds of enemy battlers over the last two das, finally my favorite part begins: Inventing names and lore for them all :D

Forum statistics

Threads
111,377
Messages
1,060,592
Members
144,706
Latest member
DonTonyPepperoni
Top