disintegration / imaging

Imaging is a simple image processing package for Go
MIT License
5.3k stars 443 forks source link

Is there a way to pass the image as io.Reader ? #121

Closed MohitKS5 closed 4 years ago

MohitKS5 commented 4 years ago

After resizing I want to upload it to s3 which takes io.Reader as input. One obvious choice is saving it to a file and then read it. Is there any other way ?

disintegration commented 4 years ago
  1. The simplest option is to use the Encode function (imaging.Encode or jpeg.Encode or png.Encode etc) to write the image to a bytes.Buffer, then pass the buffer to s3 (it implements the io.Reader interface).

  2. A better but a little bit trickier option is to use the io.Pipe function that returns both an io.Writer and an io.Reader. Then you need to start a goroutine, encoding the image to the writer and pass the reader to s3. Documentation: https://golang.org/pkg/io/#Pipe Example: https://github.com/disintegration/bebop/blob/97a8b9d7e78c883d79924976850e1011892c3fe7/avatar/service.go#L235

MohitKS5 commented 4 years ago

Thanks !