davidbyttow / govips

A lightning fast image processing and resizing library for Go
MIT License
1.25k stars 196 forks source link

undefined: vips.WithPDFOptions #363

Closed felixgao closed 1 year ago

felixgao commented 1 year ago

I am writing some code to convert a PDF to PNG and in my function I have the following code but the compiler is telling me that undefined: vips.WithPDFOptions. I looked at the source code it seems the WithPDFOptions defined in image.go is rolled back a few years ago. Is there any new ways of doing this in govips?

I have the following go.mod

module github.com/felixgao/pdf_to_png

go 1.18

require github.com/davidbyttow/govips/v2 v2.13.0

require (
    golang.org/x/image v0.8.0 // indirect
    golang.org/x/net v0.11.0 // indirect
    golang.org/x/text v0.10.0 // indirect
)

In my pdf2png.go

package main

import (
    "archive/zip"
    "fmt"
    "strings"
    "sync"

    "github.com/davidbyttow/govips/v2/vips"
)

type ConvertOptions struct {
    PDFFile     []byte
    PageIndices []int
    Resolution  int
}

type ImageResult struct {
    Image *vips.ImageRef
    Index int
}

func convertPDFToPNG(options ConvertOptions) ([]byte, error) {
    vips.LoggingSettings(nil, vips.LogLevelError)
    vips.Startup(nil)
    defer vips.Shutdown()

    // Load the PDF file using vips
    // Get total pages of document
    tmp, err := vips.NewImageFromBuffer(options.PDFFile, vips.WithPDFOptions(0, 1, 75))
    if err != nil {
        // unable to load PDF file
        return nil, fmt.Errorf("failed to load PDF file: %s", err.Error())
    }
    defer tmp.Close()
    pageCount := tmp.GetPages()
     // ... more code omitted.
}

Thanks,

Felix

zxln007 commented 1 year ago

same question how do you fix it? thanks

services/thumb/image.go:23:7: undefined: vips.Startup
services/thumb/image.go:24:13: undefined: vips.Shutdown
services/thumb/image.go:25:22: undefined: vips.NewImageFromFile
services/thumb/image.go:30:40: undefined: vips.InterestingCentre
services/thumb/image.go:32:19: undefined: vips.DirectionVertical
tonimelisma commented 1 year ago

Hey @zxln007

this looks like it's not an issue with govips. It looks like an issue with your code or the environment.