diff --git a/imagedata/factory.go b/imagedata/factory.go index 8d1be5d3..ccda5fac 100644 --- a/imagedata/factory.go +++ b/imagedata/factory.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/imgproxy/imgproxy/v3/imagemeta" + "github.com/imgproxy/imgproxy/v3/imagetype" ) // NewFromBytes creates a new ImageData instance from the provided byte slice. @@ -17,6 +18,11 @@ func NewFromBytes(b []byte, headers http.Header) (*ImageData, error) { return nil, err } + return NewFromBytesWithFormat(meta.Format(), b, headers) +} + +// NewFromBytesWithFormat creates a new ImageData instance from the provided format and byte slice. +func NewFromBytesWithFormat(format imagetype.Type, b []byte, headers http.Header) (*ImageData, error) { // Temporary workaround for the old ImageData interface h := make(map[string]string, len(headers)) for k, v := range headers { @@ -25,7 +31,7 @@ func NewFromBytes(b []byte, headers http.Header) (*ImageData, error) { return &ImageData{ data: b, - meta: meta, + format: format, Headers: h, }, nil } diff --git a/imagedata/image_data.go b/imagedata/image_data.go index e8106b72..ec3d224a 100644 --- a/imagedata/image_data.go +++ b/imagedata/image_data.go @@ -12,7 +12,6 @@ import ( "github.com/imgproxy/imgproxy/v3/config" "github.com/imgproxy/imgproxy/v3/ierrors" - "github.com/imgproxy/imgproxy/v3/imagemeta" "github.com/imgproxy/imgproxy/v3/imagetype" "github.com/imgproxy/imgproxy/v3/security" ) @@ -23,7 +22,7 @@ var ( ) type ImageData struct { - meta imagemeta.Meta + format imagetype.Type data []byte Headers map[string]string @@ -41,14 +40,9 @@ func (d *ImageData) Close() error { return nil } -// Meta returns the image metadata -func (d *ImageData) Meta() imagemeta.Meta { - return d.meta -} - // Format returns the image format based on the metadata func (d *ImageData) Format() imagetype.Type { - return d.meta.Format() + return d.format } // Reader returns an io.ReadSeeker for the image data diff --git a/imagedata/read.go b/imagedata/read.go index 20be72d0..7fbe4a93 100644 --- a/imagedata/read.go +++ b/imagedata/read.go @@ -51,7 +51,7 @@ func readAndCheckImage(r io.Reader, contentLength int, secopts security.Options) return &ImageData{ data: buf.Bytes(), - meta: meta, + format: meta.Format(), cancel: cancel, }, nil } diff --git a/svg/svg.go b/svg/svg.go index 82415306..87d4f154 100644 --- a/svg/svg.go +++ b/svg/svg.go @@ -9,6 +9,7 @@ import ( "github.com/tdewolff/parse/v2/xml" "github.com/imgproxy/imgproxy/v3/imagedata" + "github.com/imgproxy/imgproxy/v3/imagetype" ) func cloneHeaders(src map[string]string) http.Header { @@ -54,7 +55,11 @@ func Sanitize(data *imagedata.ImageData) (*imagedata.ImageData, error) { return nil, l.Err() } - newData, err := imagedata.NewFromBytes(buf.Bytes(), cloneHeaders(data.Headers)) + newData, err := imagedata.NewFromBytesWithFormat( + imagetype.SVG, + buf.Bytes(), + cloneHeaders(data.Headers), + ) if err != nil { return nil, err } diff --git a/vips/vips.go b/vips/vips.go index e7b18968..6319738f 100644 --- a/vips/vips.go +++ b/vips/vips.go @@ -470,7 +470,7 @@ func (img *Image) Save(imgtype imagetype.Type, quality int) (*imagedata.ImageDat b := ptrToBytes(ptr, int(imgsize)) - imgdata, ierr := imagedata.NewFromBytes(b, make(http.Header)) + imgdata, ierr := imagedata.NewFromBytesWithFormat(imgtype, b, make(http.Header)) if ierr != nil { cancel() return nil, ierr