5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/douyin_image/image.rb', line 5
def generate(file_path, output_path, options={})
offset = (options.delete(:offset) || 8).to_i.abs
im = Vips::Image.new_from_file(file_path)
im_r = im * [1, 0, 0] im_gb = im * [0, 1, 1]
im_r = im_r.embed(offset, offset, im.width, im.height)
target_im = im_r.add(im_gb)
target_im = random_part_offset(target_im, options)
target_im = target_im.embed(-offset, -offset, im.width-offset, im.height-offset)
target_im.write_to_file(output_path)
end
|