You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: extend.go
    path of file: ./repos/imgproxy/processing
    
    the code of the file until where you have to start completion: package processing

import (
	"github.com/imgproxy/imgproxy/v3/imagedata"
	"github.com/imgproxy/imgproxy/v3/imath"
	"github.com/imgproxy/imgproxy/v3/options"
	"github.com/imgproxy/imgproxy/v3/vips"
)

func extendImage(img *vips.Image, resultWidth, resultHeight int, opts *options.ExtendOptions, offsetScale float64, extendAr bool) error {
	if !opts.Enabled || (resultWidth <= img.Width() && resultHeight <= img.Height()) || resultWidth == 0 || resultHeight == 0 {
		return nil
	}

	if extendAr && resultWidth > img.Width() && resultHeight > img.Height() {
		diffW := float64(resultWidth) / float64(img.Width())
		diffH := float64(resultHeight) / float64(img.Height())

		switch {
		case diffH > diffW:
			resultHeight = imath.Scale(img.Width(), float64(resultHeight)/float64(resultWidth))
			resultWidth = img.Width()

		case diffW > d
    
func extendImage(img *vips.Image, resultWidth, resultHeight int, opts *options.ExtendOptions, offsetScale float64, extendAr bool) error {
	if !opts.Enabled || (resultWidth <= img.Width() && resultHeight <= img.Height()) || resultWidth == 0 || resultHeight == 0 {
		return nil
	}

	if extendAr && resultWidth > img.Width() && resultHeight > img.Height() {
		diffW := float64(resultWidth) / float64(img.Width())
		diffH := float64(resultHeight) / float64(img.Height())

		switch {
		case diffH > diffW:
			resultHeight = imath.Scale(img.Width(), float64(resultHeight)/float64(resultWidth))
			resultWidth = img.Width()

		case diffW > diffH:
			resultWidth = imath.Scale(img.Height(), float64(resultWidth)/float64(resultHeight))
			resultHeight = img.Height()

		default:
			// The image has the requested arpect ratio
			return nil
		}
	}

	offX, offY := calcPosition(resultWidth, resultHeight, img.Width(), img.Height(), &opts.Gravity, offsetScale, false)
	return img.Embed(resultWidth, resultHeight, offX, offY)
}