Skip to content

Instantly share code, notes, and snippets.

@adrhill
Created September 9, 2022 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrhill/dcc4d85c93de937842d560835a496468 to your computer and use it in GitHub Desktop.
Save adrhill/dcc4d85c93de937842d560835a496468 to your computer and use it in GitHub Desktop.
Convert image to PPM
using Images, TestImages
img = testimage("cameraman")
img = convert.(RGB{N0f8}, img)
open("cameraman.ppm", "w+") do io
println(io, "P6")
println(io, size(img, 2), " ", size(img, 1))
println(io, 255)
for row in eachrow(img)
for px in row
write(io, px.r.i)
write(io, px.g.i)
write(io, px.b.i)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment