Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local imlib2 = require "imlib2"
- math.randomseed(os.time())
- local white, black =
- imlib2.image.load("first.png"),
- imlib2.image.load("second.jpg")
- local width, height =
- math.min(white:get_width(), black:get_width()),
- math.min(white:get_height(), black:get_height())
- for _, image in ipairs{white, black} do
- local cwidth, cheight =
- image:get_width(),
- image:get_height()
- image:crop(
- (cwidth - width ) / 2,
- (cheight - height) / 2,
- width,
- height
- )
- end
- local _color = imlib2.color.new(0, 0, 0)
- local function color(val, alpha)
- _color.red = val
- _color.green = val
- _color.blue = val
- _color.alpha = alpha
- return _color
- end
- local target = imlib2.image.new(width, height)
- target:set_has_alpha(true)
- for y=1,height do
- for x=1,width do
- local px_white, px_black =
- white:get_pixel(x, y),
- black:get_pixel(x, y)
- local l_w = (px_white.red + px_white.green + px_white.blue) / 3 + 1
- local l_b = (px_black.red + px_black.green + px_black.blue) / 3 + 1
- -- Normalize
- l_w = (l_w) / 2 + 128
- l_b = (l_b)
- local a_l = (l_w + l_b) / 2
- local d_l = l_w - l_b
- target:draw_pixel(x, y, color(a_l - 1, (255 - d_l) / 2 - 1))
- end
- end
- target:save('result.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement