Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportParams missing during LoadImageFromBuffer #203

Closed
dark-wind opened this issue Jun 18, 2021 · 7 comments
Closed

ImportParams missing during LoadImageFromBuffer #203

dark-wind opened this issue Jun 18, 2021 · 7 comments

Comments

@dark-wind
Copy link

I got error:

 value "0.000000" of type 'gdouble' is invalid or out of range for property 'dpi' of type 'gdouble'

when I load a pdf file with dpi params

my code

// init some params
pdfImportParams := vips.NewImportParams()
pdfImportParams.Density.Set(300)
pdfImportParams.Page.Set(0)
// get a file
buf, err := ioutil.ReadFile("foo.pdf")
checkError(err)
image1, err := vips.LoadImageFromBuffer(buf, pdfImportParams)
// write to jpg
ep := vips.NewJpegExportParams()
imageBytes, _, err := image1.ExportJpeg(ep)
err = ioutil.WriteFile("bar.jpg", imageBytes, 0644)
checkError(err)

the "Density(dpi)" didn't work

My goal

pdf to jpg with dpi params
such as

vips pdfload foo.pdf bar.jpg --dpi=300 --page=1

bug point

if err := C.load_from_buffer(&importParams, unsafe.Pointer(&src[0]), C.size_t(len(src))); err != 0 {
     return nil, ImageTypeUnknown, handleImageError(importParams.outputImage)
}

this code located in "vips/foreign.go" line 253

I am new to both Libvips and Golang, I don't know how to lock and fix this problem

@dark-wind
Copy link
Author

I used the VIPS library from C to solve it:

double dpi = (gdouble)300;
    vips_pdfload("41FC0026.pdf",&out,"dpi",dpi,NULL);

I hope this code helps fix the bug

@tonimelisma
Copy link
Collaborator

Thanks so much for the bug report @dark-wind! This is valuable work.

Would it be too much to ask if you could provide a PR? Any contributions are greatly appreciated! If not, I will try and take a look at this at some stage although I'm now on summer vacation so it might take a bit of time.

@zhifengzhuang
Copy link
Contributor

Dpi is a double type.However, govips use MAYBE_SET_INT to set it.See here https://github.com/davidbyttow/govips/blob/master/vips/foreign.c#L122.
Same as svg, https://github.com/davidbyttow/govips/blob/master/vips/foreign.c#L128

@ugljesas
Copy link

Thanks for the fix!

Do you maybe have an estimate of when this will end up in a stable release? I'm currently using the version tied to the commit of the fix, and everything seems to be alright but would prefer to switch to a stable version before this goes to production.

@davidbyttow
Copy link
Owner

sure, we can do a release, i think

@davidbyttow
Copy link
Owner

Done @ugljesas https://github.com/davidbyttow/govips/releases/tag/v2.11.0

@ugljesas
Copy link

Amazing, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants