Last active
October 14, 2020 15:51
-
-
Save rjindael/9fe5ab8ac9751b1e1debdc93e36d039e to your computer and use it in GitHub Desktop.
ThumbnailGenerator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ThumbnailGenerator | |
// Carrot | |
const express = require("express") | |
const bodyParser = require("body-parser") | |
const fs = require("fs") | |
const app = express() | |
const port = process.env.PORT || 3000 | |
app.use(bodyParser.json({ limit: '50mb' })) | |
app.use((req, res, next) => { | |
var data = "" | |
req.setEncoding("utf8") | |
req.on("data", (chunk) => { | |
data += chunk | |
}) | |
req.on("end", () => { | |
req.body = data | |
next() | |
}) | |
}) | |
app.post("/upload", (req, res) => { | |
let thumbnail = JSON.parse(req.body) | |
let name = "thumbnail-" + Date.now() | |
if (thumbnail.format == "OBJ") { | |
let click = JSON.parse(thumbnail.click) | |
// Create directory | |
fs.mkdirSync("thumbnails/" + name) | |
// Save files | |
for (const [file, payload] of Object.entries(click.files)) { | |
fs.writeFile("thumbnails/" + name + "/" + file, payload.content, (error) => { | |
if (error) throw error | |
console.log("Wrote " + "thumbnails/" + name + "/" + file) | |
}) | |
} | |
} | |
else | |
{ | |
name += "." + thumbnail.format.toLowerCase() | |
fs.writeFile("thumbnails/" + name, thumbnail.click, "base64", (error) => { | |
if (error) throw error | |
console.log("Wrote " + name) | |
}) | |
} | |
}) | |
app.listen(port, () => console.log(`Started ThumbnailServer on port ${port}...`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
ThumbnailGenerator | |
by Carrot | |
Usage: render(player_id, format, x, y, sky, old) | |
Example: render(1, "PNG", 512, 512, false, true) will generate a 512x512 PNG that looks like an old Roblox thumbnail for the Roblox user | |
Most likely, you will never need to set "sky" to true. | |
You can also render OBJ files | |
--]] | |
local HttpService = game:GetService("HttpService") | |
local ScriptContext = game:GetService("ScriptContext") | |
local Lighting = game:GetService("Lighting") | |
local Players = game:GetService("Players") | |
local RunService = game:GetService("RunService") | |
local ContentProvider = game:GetService("ContentProvider") | |
local ThumbnailGenerator = game:GetService("ThumbnailGenerator") | |
local URL = "http://127.0.0.1:3000" | |
HttpService.HttpEnabled = true | |
ScriptContext.ScriptsDisabled = true | |
ContentProvider:SetBaseUrl(URL) | |
local function oldify(player) | |
Lighting.Outlines = false | |
-- Create the old sky | |
local sky = Instance.new("Sky") | |
sky.SkyboxBk = "rbxasset://textures/sky/null_plainsky512_bk.jpg" | |
sky.SkyboxDn = "rbxasset://textures/sky/null_plainsky512_dn.jpg" | |
sky.SkyboxFt = "rbxasset://textures/sky/null_plainsky512_ft.jpg" | |
sky.SkyboxLf = "rbxasset://textures/sky/null_plainsky512_lf.jpg" | |
sky.SkyboxRt = "rbxasset://textures/sky/null_plainsky512_rt.jpg" | |
sky.SkyboxUp = "rbxasset://textures/sky/null_plainsky512_up.jpg" | |
sky.Name = "OldSky" | |
sky.Parent = Lighting | |
-- Set the player's bodyparts to become "old" | |
for _, object in pairs(player:GetChildren()) do | |
if object:IsA("BasePart") then | |
object.Material = Enum.Material.SmoothPlastic -- classic shine | |
-- Create the studs | |
local top = Instance.new("Texture") | |
local bottom = Instance.new("Texture") | |
top.Name = "TopStud" | |
bottom.Name = "BottomStud" | |
top.Texture = "rbxasset://textures/studs/top.png" | |
bottom.Texture = "rbxasset://textures/studs/bottom.png" | |
top.Face = "Top" | |
bottom.Face = "Bottom" | |
top.StudsPerTileU = 1 | |
top.StudsPerTileV = 1 | |
bottom.StudsPerTileU = 1 | |
bottom.StudsPerTileV = 1 | |
top.Parent = object | |
bottom.Parent = object | |
elseif object:IsA("Hat") then | |
for _, innerchild in pairs(object:GetChildren()) do | |
if innerchild:IsA("BasePart") then | |
innerchild.Material = Enum.Material.SmoothPlastic | |
end | |
end | |
end | |
end | |
-- Set face | |
-- but first, find it | |
local face | |
for _, object in pairs(player.Head:GetChildren()) do | |
if object:IsA("Texture") or object:IsA("Decal") then | |
face = object | |
end | |
end | |
if face.Texture:lower():find("face.png") then -- only set the face if it's the default one; else, leave it alone | |
face.Texture = "rbxasset://textures/face_old.png" | |
end | |
end | |
local function render(id, format, x, y, sky, old) | |
print("Generating thumbnail for user ".. id .."...") | |
local Player = Players:CreateLocalPlayer(id) | |
Player:LoadCharacter() | |
RunService:Run() | |
if old then | |
oldify(workspace.Player1) | |
end | |
local result = HttpService:JSONEncode({["format"] = format, ["click"] = ThumbnailGenerator:Click(format, x, y, not sky)}) | |
print("Uploading thumbnail...") | |
HttpService:PostAsync( | |
URL .. "/upload", | |
result, | |
Enum.HttpContentType.TextPlain | |
) | |
print("Uploaded thumbnail successfully!") | |
end | |
render(1552220976, "PNG", 512, 512, false, false) | |
-- EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment