Skip to content

Instantly share code, notes, and snippets.

@dietercastel
Last active May 15, 2021 10:29
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 dietercastel/30e36d542e1332a13ab9090070377bd7 to your computer and use it in GitHub Desktop.
Save dietercastel/30e36d542e1332a13ab9090070377bd7 to your computer and use it in GitHub Desktop.
Concat and replace PNG transparent images.
# Concatenate images vertically and replace transparancy with white.
using Images
a = readdir(".")
pngs = filter(x->endswith(x,".png"),a)
imgsperpage = 4
pages = length(pngs) ÷ imgsperpage
function replaceTransp(x)
if x == RGBA(0,0,0,0)
return RGBA(1,1,1,1)
else
return x
end
end
for i in 0:pages
filenames = String[]
for j in 1:imgsperpage
idx = i*imgsperpage+j
if idx <= length(pngs)
println(idx)
push!(filenames,pngs[idx])
end
end
if length(filenames) != 0
page = vcat(tuple(map(x->load(x),filenames)...)...)
p = i + 1
#save(joinpath("output","$p.png"), page)
save(joinpath("output","$p.png"), map(replaceTransp,page))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment