Last active
May 15, 2021 10:29
-
-
Save dietercastel/30e36d542e1332a13ab9090070377bd7 to your computer and use it in GitHub Desktop.
Concat and replace PNG transparent images.
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
# 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