Remote Image Library is a Luau library designed to generate EditableImage instances from PNG files from remote URLs, binary strings and pixel arrays.
The EditableImage instance can be parented to a MeshPart, ImageLabel, ImageButton and Decal to replace its image. For more details on the EditableImage class, visit https://create.roblox.com/docs/reference/engine/classes/EditableImage.
Remote Image Library features:
- Loading PNGs from;
- Urls,
- Binary Strings
- Pixel Arrays,
- HTTP request queuing to prevent violating the rate limits.
- An optional custom
http_get_async
override to integrate with your own queue / proxy. - Usage on both client & server with authentication.
Warning
This library was created as a demonstration, it is the responsibility of the user to ensure its use doesn't violate Roblox's TOS.
The simplest use of Remote Image Library is on the server. Please not that as of 2 December 2023, EditableImages do not replicate between the server->client boundry.
local remote_img = require(path.to.library);
local spawn_location = workspace:WaitForChild("SpawnLocation");
local editable_image = remote_img.create_image("https://i.imgur.com/eX24dFX.png");
editable_image.Parent = spawn_location:WaitForChild("Decal");
-- SERVER:
local remote_img = require(path.to.library);
remote_img.serve(function(player : Player, url : string)
local is_https = remote_img.builtin.protocols(url, {"https"});
local is_imgur = remote_img.builtin.hosts(url, { -- Limit to imgur
"i.imgur.com"
});
local is_player_allowed = remote_img.builtin.user_ids(player, { -- Limit players.
56098303
});
return is_https -- Request must be using HTTPS
and is_imgur -- and must be to i.imgur.com
and is_player_allowed; -- and made by @plainenglish
end);
-- CLIENT:
local remote_img = require(path.to.library);
local spawn_location = workspace:WaitForChild("SpawnLocation");
local editable_image = remote_img.create_image("https://i.imgur.com/eX24dFX.png");
editable_image.Parent = spawn_location:WaitForChild("Decal");
To use a custom http_get function, set the _G.REMOTE_IMG_CUSTOM_GET function to your own implementation. The API should match the original, see API Reference below.
_G.REMOTE_IMG_CUSTOM_GET = function(url : string) : string
print(url, "requested.");
end
Tip
This will not replace the original function meaning you can use it in your override.
This library relies upon MaximumADHD's Roblox-PNG-Library to get pixel data from PNG files.
You can install Roblox Image Library by downloading the prebuilt model file from the GitHub release page. You may also install it with the following methods:
To embed Remote Image Library into your project, download the ./src
directory and copy it into your project.
To build the library from source, ensure you have rojo installed and run the following commands:
# Check rojo is installed
rojo --version #> Rojo 7.4.0-rc3
# Clone the git repo
git clone https://github.com/MaximumADHD/Roblox-PNG-Library.git
# Move into the downloaded repo
cd Remote-Image-Library
# Build the library, it will be available at ./remote_image.rbxmx
rojo build -o "remote_img.rbxmx"
- create_image
- serve
- create_image_from_array
- create_image_from_string
- builtin.protocols
- builtin.hosts
- builtin.paths
- builtin.user_ids
- builtin.allow_all
- http_get_async
The
create_image
function generates an EditableImage instance from the passed URL string.create_image(url : string) : EditableImage
url : string
- The URL to request image data from.
EditableImage
- The generated Editable Image Instance.local editable_image = remote_img.create_image("https://i.imgur.com/eX24dFX.png"); editable_image.Parent = game.Workspace.SpawnLocation.Decal;
The
serve
function allows clients to usecreate_image
with an optional authentication function.serve(auth : (Player, string) -> (boolean)?) : nil
url : string
- The URL to request image data from.
EditableImage
- The generated Editable Image Instance.remote_img.serve(remote_img.builtin.allow_all);
The
create_image_from_array
function creates an EditableImage from a pixel array.create_image_from_array(pixel_array : string, width : number, height : number) : EditableImage
pixel_array : {number}
- The flat pixel array ({r, g, b, a, r, g, b, a...}
)width : number
- The width of the image.height : number
- The height of the image.
EditableImage
- The generated Editable Image Instance.local red_pixels = {1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}; local editable_image = remote_img.create_image_from_array(red_pixels, 2, 2); editable_image.Parent = game.Workspace.SpawnLocation.Decal;
The
create_image_from_string
function generates an EditableImage instance from the passed binary string (or buffer).create_image_from_string(data : string | buffer) : EditableImage
data : string | buffer
- The binary string containing the image data.
EditableImage
- The generated Editable Image Instance.local editable_image = remote_img.create_image_from_string("\x89\x50\x4E\x47..."); editable_image.Parent = game.Workspace.SpawnLocation.Decal;
The
builtin.protocols
function returns true if the passed url's protocol is within the passed array.builtin.protocols(url : string, protocols : {string}) : boolean
url : string
- The image url.protocols : {string}
- The allowed protocols.
boolean
- Whether url's protocol is contained within protocols.local is_https = remote_img.builtin.protocols("https://i.imgur.com/eX24dFX.png", {"https"});
The
builtin.hosts
function returns true if the passed url's host is within the passed array.Note: This function checks the urls entire host, including subdomain.
builtin.hosts(url : string, hosts : {string}) : boolean
url : string
- The image url.hosts : {string}
- The allowed hosts.
boolean
- Whether url's protocol is contained within hosts.local is_imgur = remote_img.builtin.hosts("https://i.imgur.com/eX24dFX.png", {"i.imgur.com"});
The
builtin.paths
function returns true if the passed url's path is within the passed array.builtin.paths(url : string, paths : {string}) : boolean
url : string
- The image url.paths : {string}
- The allowed paths.
boolean
- Whether url's protocol is contained within hosts.local is_bunny = remote_img.builtin.hosts("https://i.imgur.com/eX24dFX.png", {"eX24dFX.png"});
The
builtin.user_ids
function returns true if the Player's UserId is within the passed array.builtin.user_ids(player : Player, user_ids : {number}) : boolean
player : Player
- The player.user_ids : {number}
- The allowed user ids.
boolean
- Whether player's user id is found.local is_plain = remote_img.builtin.user_ids(game.Players.LocalPlayer, {56098303});
The
builtin.allow_all
function always returns true.builtin.allow_all() : boolean
boolean
- Truelocal _true = remote_img.builtin.allow_all();
The
http_get_async
function queues a HTTP get request with the internal http queue and returns the result. Throws an error if unsuccessful.http_get_async(url : string) : string
url : string
- The target url
string
- The response body.local google_homepage = remote_img.http_get_async("https://google.com/");