Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Myagmartseren committed Mar 22, 2024
1 parent 53fc655 commit 80cf5ea
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions gopdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"compress/zlib" // for constants
"fmt"
"image"
"image/jpeg"
"image/png"
"io"
"log"
Expand Down Expand Up @@ -731,7 +732,7 @@ func (gp *GoPdf) Image(picPath string, x float64, y float64, rect *Rect) error {
return gp.imageByHolder(imgh, imageOptions)
}

func (gp *GoPdf) ImageFrom(img image.Image, x float64, y float64, rect *Rect) error {
func (gp *GoPdf) ImageFrom(img image.Image, x float64, y float64, rect *Rect, format string) error {
if img == nil {
return errors.New("Invalid image")
}
Expand All @@ -741,7 +742,15 @@ func (gp *GoPdf) ImageFrom(img image.Image, x float64, y float64, rect *Rect) er
r, w := io.Pipe()
go func() {
bw := bufio.NewWriter(w)
err := png.Encode(bw, img)
var err error
switch format {
case "jpeg":
err = jpeg.Encode(bw, img, nil)
case "png":
err = png.Encode(bw, img)
default:
err = errors.New("Unsupported image format")
}
bw.Flush()
if err != nil {
w.CloseWithError(err)
Expand Down

0 comments on commit 80cf5ea

Please sign in to comment.