• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM HTML5 Download Image

Drell

Member
I'm developing a board game that encompasses deck building, so I've built a deck builder which uses surface_save to create printable pages to test out different deck builds. Because some of my team uses Macs (and I don't have one), I'm trying out using an HTML5 build to be used across systems. However, surface_save doesn't seem to be functioning properly due to the way HTML5 and JS work. Is there a way I can give the user the option to download surfaces as .png? Will I need to use JS to do this?
 

Mert

Member
This is happening because Javascript works on clients(on devices), not on the server. This means that you cannot save any file to the server.
However, luckily I have a solution for this (Which I'm using on my Facebook Instant Games extension)

surface_to_base64(surface_index);
Code:
/// @function surface_to_base64(surface)
/// @description Converts a surface into a base64 string. Used for sending Images to Facebook Instant Games.
/// @param {real} surface Surface ID that'll be converted.
var __tempbuff = buffer_create(512,buffer_grow,1);
buffer_get_surface(__tempbuff, argument0, buffer_surface_copy, 0, 0);
var bufferBase64 = buffer_base64_encode(__tempbuff, 0, buffer_get_size(__tempbuff));
buffer_delete(__tempbuff);

//return "data:image/png;base64," + bufferBase64; >> For FBIG
return bufferBase64;
So, after creating your surface, simply use this function with your newly created surface and get the base64 data. At this time, you must store this string for further displaying. You can store this string on browser's local storage or as a cookie with this extension


FROM BASE64 to BUFFER
Code:
/// @function base64_to_surface(surface)
/// @description Converts a base64 string to a surface. Used for receiving Images from Facebook Instant Games.
/// @param {string} base64 string that'll be converted into a surface.
var __tempbuff = buffer_create(512,buffer_grow,1);
buffer_get_surface(__tempbuff, argument0, buffer_surface_copy, 0, 0);

return __tempbuff;
Provide the base64 string as the argument. It returns a surface ID for displaying the image. Don't forget the destroy the surface once you're done with it.

Good luck

Edit : I just checked that I have an extension project for "downloading .png images from surfaces". I'll look into it, in case you'd need a solid image file.
 

Drell

Member
This is happening because Javascript works on clients(on devices), not on the server. This means that you cannot save any file to the server. . .
I'm not sure we're on the same page: I don't need to store the file to be used later by the program, the user needs to store the file locally so they can print it it out. I'm basically looking for a "save as" feature so that my less tech savvy dev team can easily download and print out deck pages. Currently, the cards are added to a deck, and when you click the print icon, it runs this code:


Code:
with(deckbox){
    for(var ii=0;ii<ceil(ds_list_size(deck_current)/9);ii++){
        var surf = surface_create(784,1012);
        surface_set_target(surf);
        
        var iii = ii*3;
        
        for(var n=iii; n<iii+3; n++)
            for(var i=0; i<3; i++)
                if ds_list_size(deck_current) > i+n*3
                    draw_sprite(ds_list_find_value(deck_current,i+n*3),-1,10+i*260,10+(n-iii)*340);
                    
        surface_save(surf,"decks\deck_page_" + string(ii) + ".png");
        surface_reset_target();
        surface_free(surf);
    }
}
So basically, I want to take surface_save() and throw it into a function/script that'll allow the user to choose where the file is saved.
 

rIKmAN

Member
I'm developing a board game that encompasses deck building, so I've built a deck builder which uses surface_save to create printable pages to test out different deck builds. Because some of my team uses Macs (and I don't have one), I'm trying out using an HTML5 build to be used across systems. However, surface_save doesn't seem to be functioning properly due to the way HTML5 and JS work. Is there a way I can give the user the option to download surfaces as .png? Will I need to use JS to do this?
YellowAfterlife has an extension that allows you to use a Save As dialog on HTML5 to let the user choose where to save a file.

https://yellowafterlife.itch.io/screenshot-save-dialog
 

Drell

Member
YellowAfterlife has an extension that allows you to use a Save As dialog on HTML5 to let the user choose where to save a file.

https://yellowafterlife.itch.io/screenshot-save-dialog
I just tested it and unfortunately it doesn't seem to work properly. It saves a png, but it's just a black screen. Perhaps my using GM:S 1.4 is the problem, but this doesn't currently work for me.

EDIT: It works fine in the example included with the extension, but not with my game for whatever reason.
 
Last edited:

rIKmAN

Member
I just tested it and unfortunately it doesn't seem to work properly. It saves a png, but it's just a black screen. Perhaps my using GM:S 1.4 is the problem, but this doesn't currently work for me.
It's a GMS 1.4 extension (see the gmez / gmz file extensions) but it also works in GMS2.
The extension just facilitates the saving of a file via a Save As dialog and has nothing to do with the image you are actually saving - if it's a black screen then you need to take a look at what and how you are actually saving the image.

Frosty just posted the reason as I was replying, and a quick look at the comments for the extension in the link I gave shows there may be a workaround that YellowAfterlife posted: https://itch.io/t/503396/turning-webgl-off-fixed-it-but
This seems to have been an issue in GMS2 as well but has been marked as fixed in 2.2.4: https://bugs.yoyogames.com/view.php?id=31170, but as FrostyCat has said it won't be getting fixed in 1.4.
 

Drell

Member
You need to turn off WebGL for surface-to-base64 to work, otherwise it will give a black screen every time. GMS 1.4 had this problem the last time I tried it, and you should not expect any fixes going that way given that it has been past sunset for over a year.
Ah that makes sense. Thanks!

EDIT: Fun fact for anyone who finds this thread useful: the screen_save_dialog function doesn't work correctly in the draw event, but seems to work fine in the step event.
 
Last edited:
Top