@@ -2,23 +2,42 @@ local vips = require "vips"
22local ffi = require " ffi"
33
44local 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"
76
7+ describe (" test connection" , function ()
88 setup (function ()
99 -- vips.log.enable(true)
1010 end )
1111
1212 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 ()
1420 local source = vips .Source .new_from_file (JPEG_FILE )
1521 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 )
1822 image :write_to_target (target , ' .png' )
1923
2024 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' })
2241 assert .is_true ((image1 - image2 ):abs ():max () < 10 )
2342 end )
2443 end )
0 commit comments