五一节贺卡¶
连接所需的一切,上传底座和文字。
In [ ]:
Pkg.add(["ImageShow"])
In [ ]:
using FileIO, Images, ImageShow
In [ ]:
basis = load("$(@__DIR__)/basis.png")
Out[0]:
In [ ]:
text = load("$(@__DIR__)/text.png")
Out[0]:
尺寸不匹配。:(
In [ ]:
print(string(size(channelview(text))) * " != " * string(size(channelview(basis))))
让图像的尺寸相等,为相互叠加做好准备。
In [ ]:
new_basis = channelview(basis)
c_basis = zeros(3,size(new_basis,1),size(new_basis,2))
for i in 1:3
c_basis[i,:,:] = new_basis
end
text_new = imresize(text, ratio=2)
text_new = imresize(text_new, size(channelview(text),2)-150, size(c_basis,3))
x = (size(c_basis,2)-size(channelview(text_new),2))
arr_zero = RGB.(zeros(x,size(c_basis,3)))
text_new = [text_new; arr_zero]
c_text = channelview(text_new)
c_text = c_text[1:3,:,:]
c_text[c_text.>0.999999999].=0.0;
print(string(size(c_text)) * " = " * string(size(c_basis)))
开始叠加。
In [ ]:
postcard = c_basis*0.75 + c_text*0.25
postcard = RGB.(postcard[1,:,:], postcard[2,:,:], postcard[3,:,:])
Out[0]:
让我们在节日气氛中添加红色!
In [ ]:
с_postcard = channelview(postcard)
postcard = RGB.(с_postcard[1,:,:]*2,с_postcard[2,:,:],с_postcard[3,:,:])
Out[0]:
保存,以免丢失我们的酷卡!
In [ ]:
save("postcard.jpg", postcard)
Out[0]: