@@ -2,23 +2,42 @@ local vips = require "vips"
2
2
local ffi = require " ffi"
3
3
4
4
local JPEG_FILE = " ./spec/images/Gugg_coloured.jpg"
5
- -- test gvalue
6
- describe (" test connection" , function ()
5
+ local TMP_FILE = ffi .os == " Windows" and os.getenv (" TMP" ) .. " \\ x.png" or " /tmp/x.png"
7
6
7
+ describe (" test connection" , function ()
8
8
setup (function ()
9
9
-- vips.log.enable(true)
10
10
end )
11
11
12
12
describe (" to file target" , function ()
13
- it (" can create image from file source and write 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 ()
14
20
local source = vips .Source .new_from_file (JPEG_FILE )
15
21
local image = vips .Image .new_from_source (source , ' ' , { access = ' sequential' })
16
- local filename = ffi .os == " Windows" and os.getenv (" TMP" ) .. " \\ x.png" or " /tmp/x.png"
17
- local target = vips .Target .new_to_file (filename )
18
22
image :write_to_target (target , ' .png' )
19
23
20
24
local image1 = vips .Image .new_from_file (JPEG_FILE , { access = ' sequential' })
21
- local image2 = vips .Image .new_from_file (filename , { 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' })
22
41
assert .is_true ((image1 - image2 ):abs ():max () < 10 )
23
42
end )
24
43
end )
0 commit comments