Jump to content

User:Albedo: Difference between revisions

→‎Binary Digits: PNG to wikitable conversion code for Julia
(→‎Binary Digits: PNG to wikitable conversion code for Julia)
Line 305:
↑ . .
l4 ....
 
 
==Create Wikitable from PNG files==
 
This is the Julia code I use to generate wikitables from Piet program png files (codel size 1).
 
I just copy/paste the console output of the program.
 
Usage: convert("filename.png", blocksize)
 
using Images, ImageView
function convert(name::String,blocksize::Int)
img=Images.imread("$name")
view(img)
println("{| style=\"border-collapse: collapse; border-spacing: 0; font-family: courier-new,courier,monospace; font-size: $(blocksize)px; line-height: 1.2em; padding: 0px\"")
for y=1:height(img)
for x=1:width(img)
r=hex(int(img[x,y].r*255))
g=hex(int(img[x,y].g*255))
b=hex(int(img[x,y].b*255))
r=="0" ? r="00" : nothing
g=="0" ? g="00" : nothing
b=="0" ? b="00" : nothing
print("| style=\"background-color:#$r$g$b; color:#$r$g$b;\" | ww\n")
x==width(img) ? print("|-\n\n"):nothing
end
end
print("|}")
end
136

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.