Skip to content

Commit 5ed6c03

Browse files
committed
add buffer example
1 parent 733260f commit 5ed6c03

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

example/buffer.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/luajit
2+
3+
-- load and save images to and from memory buffers
4+
5+
local vips = require "vips"
6+
7+
local f = io.open(arg[1], "rb")
8+
local content = f:read("*all")
9+
10+
local im = vips.Image.new_from_buffer(content, "", {access = "sequential"})
11+
12+
-- brighten 20%
13+
im = (im * 1.2):cast("uchar")
14+
15+
-- print as mime jpg
16+
local buffer = im:write_to_buffer(".jpg", {Q = 90})
17+
print("Content-length: " .. #buffer)
18+
print("Content-type: image/jpeg")
19+
print("")
20+
print(buffer)

0 commit comments

Comments
 (0)