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

how to get image byte data #141

Open
wzhsh90 opened this issue Apr 22, 2021 · 2 comments
Open

how to get image byte data #141

wzhsh90 opened this issue Apr 22, 2021 · 2 comments

Comments

@wzhsh90
Copy link

wzhsh90 commented Apr 22, 2021

step1、
dstImage := imaging.Resize(srcImage, 210, 250, imaging.Lanczos)

step2、
I need dstImage byte data ,how to do?

@SyxAxis
Copy link

SyxAxis commented Apr 24, 2021

step1、
dstImage := imaging.Resize(srcImage, 210, 250, imaging.Lanczos)

step2、
I need dstImage byte data ,how to do?

Once you've performed all your operations on the image object, dump the bytes out.

// assumes PNG to JPG, no exception handling, just raw example
// load in a PNG
src, _ := imaging.Open("sampleimage.png")
// resize it
dst := imaging.Resize(src, 250, 0, imaging.Lanczos)
// get a bytes buffer container
buf := new(bytes.Buffer)
// use jpg encode ( assuming JPG ) and push the bytes out to the buffer
jpeg.Encode(buf, dst, nil)
// dump out the bytes to a file
ioutil.WriteFile("sampleimageout.jpg", buf.Bytes(), 0644)

@wzhsh90
Copy link
Author

wzhsh90 commented Apr 24, 2021 via email

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

2 participants