Quick actions

cmd+k|ctrl+k

Navigation

Languages

image

Snippet info

Language

Lua

Visibility

public

Author

scandaloussolution

Created

2024-09-21T11:21:46.163471Z

Updated

2025-01-04T15:57:44.603878Z

local HttpService = game:GetService("HttpService")

local MRMF = loadstring(HttpService:GetAsync("https://sbin.wya.rip/lib/MRMF.luau"))()

function process(images)
	local response = HttpService:RequestAsync({
		Url = "https://sbin.wya.rip/image-processing/mrmf",
		Method = "POST",
		Body = HttpService:JSONEncode(images),
		Headers = {
			["Content-Type"] = "application/json"
		}
	})
	
	return response
end

function draw(parent, pixelsize, cframe, response)
	local image = MRMF(response.buffer, true)
	local pixelarray = image.frames[1]

	local holder = Instance.new("WorldModel")
	holder.Parent = parent

	local parts = 0
	
	
	local part = Instance.new("Part")
	part.CanQuery = false
	part.CanTouch = false
	part.CanCollide = false
	part.CastShadow = false
	part.Material = Enum.Material.Air
	part.Name = "Base"
	part.Locked = true
	part.Size = Vector3.new(1, 0, 1) * pixelsize

	local function plot(x, y, width, height, color, alpha)
		if alpha <= 0.03 then
			return
		end
		local new = part:Clone()
		new.Archivable = false
		new.Size = Vector3.new(pixelsize * width, pixelsize, pixelsize * height)
		new.Color = color
		new.Transparency = 1 - alpha
		new.CFrame = cframe * CFrame.new(-pixelsize * image.width * 0.5, 0, -pixelsize * image.height * 0.5) * CFrame.new(pixelsize * (x - 1 + (width - 1) * 0.5), 0, pixelsize * (y - 1 + (height - 1) * 0.5))
		new.Parent = holder
		parts += 1
		if parts % 300 == 0 then
			task.wait()
		end
	end

	local function getColor(x, y)
		local pos = (y - 1) * image.width * 4 + (x - 1) * 4 + 1
		local r, g, b, a = pixelarray[pos], pixelarray[pos + 1], pixelarray[pos + 2], pixelarray[pos + 3]
		return r, g, b, a
	end

	local function isRegionUniform(x1, y1, x2, y2)
		local r1, g1, b1, a1 = getColor(x1, y1)
		local threshold = 0.045
		for y = y1, y2 do
			for x = x1, x2 do
				local r2, g2, b2, a2 = getColor(x, y)
				if math.abs(r1 - r2) >= threshold or math.abs(g1 - g2) >= threshold or math.abs(b1 - b2) >= threshold or math.abs(a1 - a2) >= threshold then
					return false
				end
				r1 = r1 + (r2 - r1) * 0.5
				g1 = g1 + (g2 - g1) * 0.5
				b1 = b1 + (b2 - b1) * 0.5
			end
		end
		return true, Color3.new(r1, g1, b1), a1
	end

	local function quadtree(x1, y1, x2, y2)
		if x1 > x2 or y1 > y2 then
			return
		end

		local uniform, color, alpha = isRegionUniform(x1, y1, x2, y2)
		if uniform then
			plot(x1, y1, x2 - x1 + 1, y2 - y1 + 1, color, alpha)
		else
			local midX = math.floor((x1 + x2) / 2)
			local midY = math.floor((y1 + y2) / 2)

			quadtree(x1, y1, midX, midY)
			quadtree(midX + 1, y1, x2, midY)
			quadtree(x1, midY + 1, midX, y2)
			quadtree(midX + 1, midY + 1, x2, y2)
		end
	end

	quadtree(1, 1, image.width, image.height)
	
	print("PART COUNT: " .. parts)
	print("PIXEL COUNT: " .. #pixelarray // 4)

	return holder
end

local remote = Instance.new("RemoteEvent", script)
remote.Name = "imageDrawRemoteaaaaaaa"

NLS([[local gui = Instance.new("ScreenGui")
gui.Name = "gui"
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling

local input = Instance.new("TextBox")
input.Name = "input"
input.ClearTextOnFocus = false
input.CursorPosition = -1
input.FontFace = Font.new(
  "rbxassetid://11702779517",
  Enum.FontWeight.Bold,
  Enum.FontStyle.Normal
)
input.PlaceholderColor3 = Color3.fromRGB(172, 172, 172)
input.PlaceholderText = "input image url here..."
input.Text = ""
input.TextColor3 = Color3.fromRGB(255, 255, 255)
input.TextSize = 12
input.TextWrapped = true
input.TextXAlignment = Enum.TextXAlignment.Left
input.AnchorPoint = Vector2.new(0.5, 0.5)
input.BackgroundColor3 = Color3.fromRGB(40, 50, 56)
input.BorderColor3 = Color3.fromRGB(0, 0, 0)
input.BorderSizePixel = 0
input.Position = UDim2.fromScale(0.455, 0.8)
input.Size = UDim2.new(0.21, 0, 0, 24)

local uIPadding = Instance.new("UIPadding")
uIPadding.Name = "UIPadding"
uIPadding.PaddingBottom = UDim.new(0, 4)
uIPadding.PaddingLeft = UDim.new(0, 8)
uIPadding.PaddingRight = UDim.new(0, 8)
uIPadding.PaddingTop = UDim.new(0, 4)
uIPadding.Parent = input

local uICorner = Instance.new("UICorner")
uICorner.Name = "UICorner"
uICorner.CornerRadius = UDim.new(1, 0)
uICorner.Parent = input

local depth = Instance.new("TextBox")
depth.Name = "depth"
depth.ClearTextOnFocus = false
depth.CursorPosition = -1
depth.FontFace = Font.new(
  "rbxassetid://11702779517",
  Enum.FontWeight.Bold,
  Enum.FontStyle.Normal
)
depth.PlaceholderColor3 = Color3.fromRGB(172, 172, 172)
depth.PlaceholderText = "bit"
depth.Text = "16"
depth.TextColor3 = Color3.fromRGB(255, 255, 255)
depth.TextSize = 11
depth.TextWrapped = true
depth.AnchorPoint = Vector2.new(0.5, 0.5)
depth.BackgroundColor3 = Color3.fromRGB(40, 50, 56)
depth.BorderColor3 = Color3.fromRGB(0, 0, 0)
depth.BorderSizePixel = 0
depth.Position = UDim2.fromScale(0.429, -1.25)
depth.Size = UDim2.new(0.166, 0, -0.385, 24)

local uIPadding1 = Instance.new("UIPadding")
uIPadding1.Name = "UIPadding"
uIPadding1.PaddingBottom = UDim.new(0, 4)
uIPadding1.PaddingLeft = UDim.new(0, 8)
uIPadding1.PaddingRight = UDim.new(0, 8)
uIPadding1.PaddingTop = UDim.new(0, 4)
uIPadding1.Parent = depth

local uICorner1 = Instance.new("UICorner")
uICorner1.Name = "UICorner"
uICorner1.CornerRadius = UDim.new(1, 0)
uICorner1.Parent = depth

depth.Parent = input

local size = Instance.new("TextBox")
size.Name = "size"
size.ClearTextOnFocus = false
size.CursorPosition = -1
size.FontFace = Font.new(
  "rbxassetid://11702779517",
  Enum.FontWeight.Bold,
  Enum.FontStyle.Normal
)
size.PlaceholderColor3 = Color3.fromRGB(172, 172, 172)
size.PlaceholderText = "size"
size.Text = "0.15"
size.TextColor3 = Color3.fromRGB(255, 255, 255)
size.TextSize = 11
size.TextWrapped = true
size.AnchorPoint = Vector2.new(0.5, 0.5)
size.BackgroundColor3 = Color3.fromRGB(40, 50, 56)
size.BorderColor3 = Color3.fromRGB(0, 0, 0)
size.BorderSizePixel = 0
size.Position = UDim2.fromScale(0.615, -1.25)
size.Size = UDim2.new(0.166, 0, -0.385, 24)

local uIPadding2 = Instance.new("UIPadding")
uIPadding2.Name = "UIPadding"
uIPadding2.PaddingBottom = UDim.new(0, 4)
uIPadding2.PaddingLeft = UDim.new(0, 8)
uIPadding2.PaddingRight = UDim.new(0, 8)
uIPadding2.PaddingTop = UDim.new(0, 4)
uIPadding2.Parent = size

local uICorner2 = Instance.new("UICorner")
uICorner2.Name = "UICorner"
uICorner2.CornerRadius = UDim.new(1, 0)
uICorner2.Parent = size

size.Parent = input

local width = Instance.new("TextBox")
width.Name = "width"
width.ClearTextOnFocus = false
width.FontFace = Font.new(
  "rbxassetid://11702779517",
  Enum.FontWeight.Bold,
  Enum.FontStyle.Normal
)
width.PlaceholderColor3 = Color3.fromRGB(172, 172, 172)
width.PlaceholderText = "width"
width.Text = ""
width.TextColor3 = Color3.fromRGB(255, 255, 255)
width.TextSize = 11
width.TextWrapped = true
width.AnchorPoint = Vector2.new(0.5, 0.5)
width.BackgroundColor3 = Color3.fromRGB(40, 50, 56)
width.BorderColor3 = Color3.fromRGB(0, 0, 0)
width.BorderSizePixel = 0
width.Position = UDim2.fromScale(0.0592, -1.25)
width.Size = UDim2.new(0.166, 0, -0.385, 24)

local uIPadding3 = Instance.new("UIPadding")
uIPadding3.Name = "UIPadding"
uIPadding3.PaddingBottom = UDim.new(0, 4)
uIPadding3.PaddingLeft = UDim.new(0, 8)
uIPadding3.PaddingRight = UDim.new(0, 8)
uIPadding3.PaddingTop = UDim.new(0, 4)
uIPadding3.Parent = width

local uICorner3 = Instance.new("UICorner")
uICorner3.Name = "UICorner"
uICorner3.CornerRadius = UDim.new(1, 0)
uICorner3.Parent = width

width.Parent = input

local height = Instance.new("TextBox")
height.Name = "height"
height.ClearTextOnFocus = false
height.CursorPosition = -1
height.FontFace = Font.new(
  "rbxassetid://11702779517",
  Enum.FontWeight.Bold,
  Enum.FontStyle.Normal
)
height.PlaceholderColor3 = Color3.fromRGB(172, 172, 172)
height.PlaceholderText = "height"
height.Text = "240"
height.TextColor3 = Color3.fromRGB(255, 255, 255)
height.TextSize = 11
height.TextWrapped = true
height.AnchorPoint = Vector2.new(0.5, 0.5)
height.BackgroundColor3 = Color3.fromRGB(40, 50, 56)
height.BorderColor3 = Color3.fromRGB(0, 0, 0)
height.BorderSizePixel = 0
height.Position = UDim2.fromScale(0.243, -1.25)
height.Size = UDim2.new(0.166, 0, -0.385, 24)

local uIPadding4 = Instance.new("UIPadding")
uIPadding4.Name = "UIPadding"
uIPadding4.PaddingBottom = UDim.new(0, 4)
uIPadding4.PaddingLeft = UDim.new(0, 8)
uIPadding4.PaddingRight = UDim.new(0, 8)
uIPadding4.PaddingTop = UDim.new(0, 4)
uIPadding4.Parent = height

local uICorner4 = Instance.new("UICorner")
uICorner4.Name = "UICorner"
uICorner4.CornerRadius = UDim.new(1, 0)
uICorner4.Parent = height

height.Parent = input

input.Parent = gui

local draw = Instance.new("TextButton")
draw.Name = "draw"
draw.FontFace = Font.new(
  "rbxassetid://11702779517",
  Enum.FontWeight.Bold,
  Enum.FontStyle.Normal
)
draw.Text = "draw"
draw.TextColor3 = Color3.fromRGB(255, 255, 255)
draw.TextSize = 12
draw.TextWrapped = true
draw.AnchorPoint = Vector2.new(0.5, 0.5)
draw.BackgroundColor3 = Color3.fromRGB(40, 50, 56)
draw.BorderColor3 = Color3.fromRGB(0, 0, 0)
draw.BorderSizePixel = 0
draw.Position = UDim2.fromScale(0.587, 0.8)
draw.Size = UDim2.new(0.04, 0, 0, 24)

local uIPadding5 = Instance.new("UIPadding")
uIPadding5.Name = "UIPadding"
uIPadding5.PaddingBottom = UDim.new(0, 4)
uIPadding5.PaddingLeft = UDim.new(0, 8)
uIPadding5.PaddingRight = UDim.new(0, 8)
uIPadding5.PaddingTop = UDim.new(0, 4)
uIPadding5.Parent = draw

local uICorner5 = Instance.new("UICorner")
uICorner5.Name = "UICorner"
uICorner5.CornerRadius = UDim.new(1, 0)
uICorner5.Parent = draw

draw.Parent = gui

local clear = Instance.new("TextButton")
clear.Name = "clear"
clear.FontFace = Font.new(
  "rbxassetid://11702779517",
  Enum.FontWeight.Bold,
  Enum.FontStyle.Normal
)
clear.Text = "clear"
clear.TextColor3 = Color3.fromRGB(255, 255, 255)
clear.TextSize = 12
clear.TextWrapped = true
clear.AnchorPoint = Vector2.new(0.5, 0.5)
clear.BackgroundColor3 = Color3.fromRGB(40, 50, 56)
clear.BorderColor3 = Color3.fromRGB(0, 0, 0)
clear.BorderSizePixel = 0
clear.Position = UDim2.fromScale(0.633, 0.8)
clear.Size = UDim2.new(0.04, 0, 0, 24)

local uIPadding6 = Instance.new("UIPadding")
uIPadding6.Name = "UIPadding"
uIPadding6.PaddingBottom = UDim.new(0, 4)
uIPadding6.PaddingLeft = UDim.new(0, 8)
uIPadding6.PaddingRight = UDim.new(0, 8)
uIPadding6.PaddingTop = UDim.new(0, 4)
uIPadding6.Parent = clear

local uICorner6 = Instance.new("UICorner")
uICorner6.Name = "UICorner"
uICorner6.CornerRadius = UDim.new(1, 0)
uICorner6.Parent = clear

clear.Parent = gui

gui.Parent = script

local remote = workspace:FindFirstChild("imageDrawRemoteaaaaaaa", true)

clear.MouseButton1Down:Connect(function()
	remote:FireServer("clear")
end)
draw.MouseButton1Down:Connect(function()
	remote:FireServer(input.Text, tonumber(width.Text), tonumber(height.Text), tonumber(depth.Text), tonumber(size.Text))
end)]], owner.PlayerGui)

local loaded = {}
remote.OnServerEvent:Connect(function(sender, url, width, height, depth, size)
	if sender ~= owner then return warn("bad owner") end
	if url == "clear" then
		local model = table.remove(loaded, #loaded)
		model:Destroy()
		return
	end
	if not url then return end
	local response = process({
		{
			url = url,
			height = height,
			width = width,
			colorDepth = depth,
		}
	})
	
	if response.Success then
		local body = HttpService:JSONDecode(response.Body)
		local selected = body[1]
		if selected.status == 200 then
			table.insert(loaded, draw(script, size or 0.15, owner.Character.Head.CFrame, selected.data))
		else
			warn(selected.status .. " " .. selected.data)
		end
	else
		error(response.StatusCode .. " " .. response.StatusMessage)
	end
end)
INFO