1
- #! /usr/bin/luajit
1
+ #! /usr/bin/luajit
2
2
3
3
-- add a simple text watermark to an image
4
4
-- ./watermark.lua ~/pics/IMG_0073.JPG x.jpg "Hello <i>world!</i>"
@@ -11,22 +11,21 @@ local vips = require "vips"
11
11
local im = vips .Image .new_from_file (arg [1 ], {access = " sequential" })
12
12
13
13
-- make the text mask
14
- local text =
15
- vips .Image .text (arg [3 ], {width = 200 , dpi = 200 ,
16
- align = " centre" , font = " sans bold" })
14
+ local text = vips .Image .text (arg [3 ],
15
+ {width = 200 , dpi = 200 , align = " centre" , font = " sans bold" })
17
16
text = text :rotate (- 45 )
18
17
-- make the text transparent
19
18
text = (text * 0.3 ):cast (" uchar" )
20
19
text = text :gravity (" centre" , 200 , 200 )
21
20
-- this block of pixels will be reused many times ... make a copy
22
- -- text = text:copy_memory()
23
- text = text :replicate (1 + im :width () / text :width (),
21
+ text = text :copy_memory ()
22
+ text = text :replicate (1 + im :width () / text :width (),
24
23
1 + im :height () / text :height ())
25
24
text = text :crop (0 , 0 , im :width (), im :height ())
26
25
27
26
-- we make a constant colour image and attach the text mask as the alpha
28
- local overlay =
29
- text :new_from_image ({255 , 128 , 128 }):copy ( {interpretation = " srgb" })
27
+ local overlay =
28
+ text :new_from_image ({255 , 128 , 128 }):copy {interpretation = " srgb" }
30
29
overlay = overlay :bandjoin (text )
31
30
32
31
-- overlay the text
0 commit comments