Search code examples
iosiphoneswiftgpuimage

Adding GPUImage Vignette Filter with Opacity


I am attempting to create an effect on an image using GPUImage. I am adding a vignette to an image to produce an Instagram-inspired filter. Currently I am using a GPUImageVignetteFilter to achieve this. The filter works, but I am looking for a way to either decrease the opacity of this filter, or blend it similar to a photoshop effect. Current code:

  let sourceImage = GPUImagePicture(image: "Nothing.png")
  let vignetteFilter = GPUImageVignetteFilter()
  vignetteFilter.vignetteColor = GPUVector3(one: 77.0 / 255.0, two: 3.0 / 255.0, three: 188.0 / 255.0)
  vignetteFilter.vignetteStart = 0
  vignetteFilter.vignetteEnd = 1.2
  sourceImage?.addTarget(vignetteFilter)
  vignetteFilter.useNextFrameForImageCapture()
  sourceImage?.processImage()

  let newImage =  vignetteFilter.imageFromCurrentFramebuffer()

Current Effect:

enter image description here

Desired Effect:

enter image description here

Original Photo:

enter image description here

Any help would be appreciated!


Solution

  • For anyone looking into adding vignettes with alpha, it is not currently supported through the current GPUImage. There is a fork by Drew Wilson (https://github.com/drewwilson/GPUImage) which adds a vignetteAlpha property to the filter. This worked like a charm. Hopefully it will be added to the main branch in the future!