|
| 1 | +local vips = require "vips" |
| 2 | +local ffi = require "ffi" |
| 3 | + |
| 4 | +local JPEG_FILE = "./spec/images/Gugg_coloured.jpg" |
| 5 | +local TMP_FILE = ffi.os == "Windows" and os.getenv("TMP") .. "\\x.png" or "/tmp/x.png" |
| 6 | + |
| 7 | +describe("test connection", function() |
| 8 | + setup(function() |
| 9 | + -- vips.log.enable(true) |
| 10 | + end) |
| 11 | + |
| 12 | + describe("to file target", function() |
| 13 | + local target |
| 14 | + |
| 15 | + setup(function() |
| 16 | + target = vips.Target.new_to_file(TMP_FILE) |
| 17 | + end) |
| 18 | + |
| 19 | + it("can create image from file source", function() |
| 20 | + local source = vips.Source.new_from_file(JPEG_FILE) |
| 21 | + local image = vips.Image.new_from_source(source, '', { access = 'sequential' }) |
| 22 | + image:write_to_target(target, '.png') |
| 23 | + |
| 24 | + local image1 = vips.Image.new_from_file(JPEG_FILE, { access = 'sequential' }) |
| 25 | + local image2 = vips.Image.new_from_file(TMP_FILE, { access = 'sequential' }) |
| 26 | + assert.is_true((image1 - image2):abs():max() < 10) |
| 27 | + end) |
| 28 | + |
| 29 | + it("can create image from memory source", function() |
| 30 | + local file = assert(io.open(JPEG_FILE, "rb")) |
| 31 | + local content = file:read("*a") |
| 32 | + file:close() |
| 33 | + local mem = ffi.new("unsigned char[?]", #content) |
| 34 | + ffi.copy(mem, content, #content) |
| 35 | + local source = vips.Source.new_from_memory(mem) |
| 36 | + local image = vips.Image.new_from_source(source, '', { access = 'sequential' }) |
| 37 | + image:write_to_target(target, '.png') |
| 38 | + |
| 39 | + local image1 = vips.Image.new_from_file(JPEG_FILE, { access = 'sequential' }) |
| 40 | + local image2 = vips.Image.new_from_file(TMP_FILE, { access = 'sequential' }) |
| 41 | + assert.is_true((image1 - image2):abs():max() < 10) |
| 42 | + end) |
| 43 | + end) |
| 44 | +end) |
0 commit comments