dqmq0654 2018-07-03 19:41
浏览 53
已采纳

govips选项结构如何设置白色背景

https://github.com/davidbyttow/govips Option

// Option is a type that is passed to internal libvips functions
type Option struct {
    Name   string
    ref    interface{}
    gvalue C.GValue
    closer func(gv *C.GValue)
    output bool
}

Fail to figure out how I can add a Option to embed in Go to set the white background

x := 100 - imgRef.Width()/2
y := 100 - imgRef.Height()/2
img, err := vips.Embed(imgRef.Image(), x, y, 200, 200, background)

I only know it's possible looking at de cli verion, but how to translate it into a Go Option struct is a mystery for me

$ vips embed
embed an image in a larger image
usage:
   embed in out x y width height
where:
   in           - Input image, input VipsImage
   out          - Output image, output VipsImage
   x            - Left edge of input in output, input gint
                            default: 0
                            min: -1000000000, max: 1000000000
   y            - Top edge of input in output, input gint
                            default: 0
                            min: -1000000000, max: 1000000000
   width        - Image width in pixels, input gint
                            default: 1
                            min: 1, max: 1000000000
   height       - Image height in pixels, input gint
                            default: 1
                            min: 1, max: 1000000000
optional arguments:
   extend       - How to generate the extra pixels, input VipsExtend
                            default: black
                            allowed: black, copy, repeat, mirror, white, background
   background   - Colour for background pixels, input VipsArrayDouble
operation flags: sequential-unbuffered 
  • 写回答

1条回答 默认 最新

  • duanjiaonie6097 2018-07-03 20:47
    关注
    x := 100 - imgRef.Width()/2
    y := 100 - imgRef.Height()/2
    img, err := vips.Embed(imgRef.Image(), x, y, 200, 200, vips.InputString("extend", "white"))
    

    Found it, alleluia!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数