Engee 文档
Notebook

五一节贺卡

连接所需的一切,上传底座和文字。

In [ ]:
Pkg.add(["ImageShow"])
In [ ]:
using FileIO, Images, ImageShow
In [ ]:
basis = load("$(@__DIR__)/basis.png")
Out[0]:
No description has been provided for this image
In [ ]:
text = load("$(@__DIR__)/text.png")
Warning: Png warn: iCCP: known incorrect sRGB profile
@ PNGFiles /usr/local/julia-1.9.3/packages/PNGFiles/YCPWZ/src/wraphelpers.jl:2
Warning: Png warn: iCCP: cHRM chunk does not match sRGB
@ PNGFiles /usr/local/julia-1.9.3/packages/PNGFiles/YCPWZ/src/wraphelpers.jl:2
Out[0]:
No description has been provided for this image

尺寸不匹配。:(

In [ ]:
print(string(size(channelview(text))) * " != " * string(size(channelview(basis))))
(4, 278, 2195) != (691, 1024)

让图像的尺寸相等,为相互叠加做好准备。

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)))
(3, 691, 1024) = (3, 691, 1024)

开始叠加。

In [ ]:
postcard = c_basis*0.75 + c_text*0.25
postcard = RGB.(postcard[1,:,:], postcard[2,:,:], postcard[3,:,:])
Out[0]:
No description has been provided for this image

让我们在节日气氛中添加红色!

In [ ]:
с_postcard = channelview(postcard)
postcard = RGB.(с_postcard[1,:,:]*2,с_postcard[2,:,:],с_postcard[3,:,:])
Out[0]:
No description has been provided for this image

保存,以免丢失我们的酷卡!

In [ ]:
save("postcard.jpg", postcard)
Out[0]:
131210