lua-vips
lua-vips copied to clipboard
Using VIPs library and Lua to process pictures
To get an original picture from the file, what I want to do is to select a position, cut a rectangle, and make a concave or convex semicircle on the edge of the rectangle, and make this area transparent. Is there an appropriate API or solution?
Hi @hzm199822, could you post a sample image showing what you want?
For example, this:
#!/usr/bin/luajit
local vips = require "vips"
local im = vips.Image.new_from_file(arg[1], {access = "sequential"})
-- make a transparent square ... just RGBA all 0 (black)
local square = vips.Image.black(64, 64, {bands = 4})
-- insert into the main image
im = im:insert(square, 100, 100)
im:write_to_file(arg[2])
makes a square in an image transparent, eg.:
$ ./try320.lua ~/pics/lion.png x.png

Where do you need the semicircle? Do you need a line, or a segment?
What I want is not all white, but translucency. Or that piece becomes a watermark
What I want is that this square is just a benchmark. I want to add a semicircle or subtract a semicircle on any two sides of the four sides of the square. Of course, the diameter of the semicircle must be smaller than the side length
What I want is that this square is just a benchmark. I want to add a semicircle or subtract a semicircle on any three sides of the four sides of the square. Of course, the diameter of the semicircle must be smaller than the side length. The translucency on the right side of the image can also be a fuzzy watermark. Then the block on the left side, I hope, is the same as the missing block in the original image, which is equivalent to providing a picture. I need to make two images, one is with watermark, the other is a small piece taken out separately I don't know if luavips can do this for images (add or subtract semicircles on the edges of rectangles)
The square in the lion only looks white because the page background is white. Try opening the image in a new tab.
You can overlay complex shapes with composite. You give it an RGBA image, one of the PDF blending modes (eg. over) and a position.
Could you upload some test images? It would save me making them. Just drag the images into the text box.
huangzhiming [email protected]
签名由 网易邮箱大师 定制
On 11/4/2020 15:58,John Cupitt[email protected] wrote:
The square in the lion only looks white because the page background is white. Try opening the image in a new tab. You can overlay complex shapes with composite. You give it an RGBA image and one of the PDF blending modes (eg. over) and a position. Could you upload some test images? It would save me making them. Just drag the images into the text box. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
Composite example:
#!/usr/bin/luajit
vips = require 'vips'
local image = vips.Image.new_from_file(arg[1], {access = "sequential"})
local overlay = vips.Image.new_from_file(arg[2], {access = "sequential"})
-- composite the overlay at 50, 20 using 'over' blend mode
image = image:composite(overlay, "over", {x = 50, y = 20})
image:write_to_file(arg[3])
Generates:

I mainly want to extract a figure from the original image, then save it, and change the extracted part of the original image into translucent or other
It's important to extract this step, but it seems to me that the API can only extract simple rectangles
You can apply masks if you want more complex shapes.
Post a set of sample images and I'll have a go.
like this?
huangzhiming [email protected]
签名由 网易邮箱大师 定制
On 11/4/2020 17:07,John Cupitt[email protected] wrote:
You can apply masks if you want more complex shapes. Post a set of sample images and I'll have a go. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.
Use the github website and drag images into the text box.
You need to wait for the upload to finish before pressing Comment.

OK, now it's OK. My goal is very simple, that is to get such a shape from the original image rather than just a simple rectangle. After saving this shape, I will do some operations on the original image, such as translucency, or other things. I can now extract rectangles and darken them myself, but I don't know if there is such an API to support my goal.
Ah, like a jigsaw, I wondered.
Yes, it should be easy. Do you have that shape as a PNG?

What I want to do is JPG, the encoding format of JPG is simpler than PNG, and the operation time should be shorter
I mean, do you have a PNG for the jigsaw piece? It would save me drawing it.


like this?
I found this sample:

Example code:
#!/usr/bin/luajit
vips = require 'vips'
local image = vips.Image.new_from_file(arg[1], {access = "sequential"})
local mask = vips.Image.new_from_file(arg[2], {access = "sequential"})
-- the position we place the piece
left = 200
top = 100
-- get just the alpha from the mask
alpha = mask:extract_band(3)
-- image pixels
rgb = image:crop(left, top, mask:width(), mask:height())
-- brighten 50%
rgb = rgb * 1.5
-- attach the mask as the alpha channel
overlay = rgb .. alpha
-- composite back
image = image:composite(overlay, "over", {x = left, y = top})
image:write_to_file(arg[3])
I can run like this:
$ ./try320.lua ~/pics/Gugg_coloured.jpg ~/pics/jigsaw.png x.jpg
To make this:

no...
What I want to do is to get a jigsaw block from the original image, not a rectangle, because I need this puzzle block to do some operations. This jigsaw block comes from the original picture, and the position obtained from the original image is different each time
Sorry, I still don't understand what you want to do.
Are you trying to hide or remove the watermark?
