mirror of
https://github.com/imgproxy/imgproxy.git
synced 2024-11-24 08:12:38 +02:00
Use source image format as resulting one dy default
This commit is contained in:
parent
00b690e93d
commit
da1a802632
@ -275,7 +275,7 @@ Extension specifies the format of the resulting image. At the moment, imgproxy s
|
||||
|
||||
**Note:** Read about GIF support [here](./image_formats_support.md#gif-support).
|
||||
|
||||
The extension part can be omitted. In this case, if the format is not defined by processing options, imgproxy will use `jpg` by default. You can also [enable WebP support detection](./configuration.md#webp-support-detection) to use it as default resulting format when possible.
|
||||
The extension part can be omitted. In this case, imgproxy will use source image format as resulting one. If source image format is not supported as resulting, imgproxy will use `jpg`. You also can [enable WebP support detection](./configuration.md#webp-support-detection) to use it as default resulting format when possible.
|
||||
|
||||
### Example
|
||||
|
||||
|
@ -91,7 +91,7 @@ Extension specifies the format of the resulting image. At the moment, imgproxy s
|
||||
|
||||
**Note:** Read about GIF support [here](./image_formats_support.md#gif-support).
|
||||
|
||||
The extension part can be omitted. In this case, imgproxy will use `jpg` by default. You also can [enable WebP support detection](./configuration.md#webp-support-detection) to use it as default resulting format when possible.
|
||||
The extension part can be omitted. In this case, imgproxy will use source image format as resulting one. If source image format is not supported as resulting, imgproxy will use `jpg`. You also can [enable WebP support detection](./configuration.md#webp-support-detection) to use it as default resulting format when possible.
|
||||
|
||||
### Example
|
||||
|
||||
|
11
process.go
11
process.go
@ -450,10 +450,9 @@ func processImage(ctx context.Context) ([]byte, error) {
|
||||
defer startPrometheusDuration(prometheusProcessingDuration)()
|
||||
}
|
||||
|
||||
po := getProcessingOptions(ctx)
|
||||
|
||||
defer C.vips_cleanup()
|
||||
|
||||
po := getProcessingOptions(ctx)
|
||||
data := getImageData(ctx).Bytes()
|
||||
imgtype := getImageType(ctx)
|
||||
|
||||
@ -461,6 +460,14 @@ func processImage(ctx context.Context) ([]byte, error) {
|
||||
return nil, errSmartCropNotSupported
|
||||
}
|
||||
|
||||
if po.Format == imageTypeUnknown {
|
||||
if vipsTypeSupportSave[imgtype] {
|
||||
po.Format = imgtype
|
||||
} else {
|
||||
po.Format = imageTypeJPEG
|
||||
}
|
||||
}
|
||||
|
||||
img, err := vipsLoadImage(data, imgtype, 1, po.Format == imageTypeGIF)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -701,7 +701,7 @@ func defaultProcessingOptions(headers *processingHeaders) (*processingOptions, e
|
||||
Gravity: gravityOptions{Type: gravityCenter},
|
||||
Enlarge: false,
|
||||
Quality: conf.Quality,
|
||||
Format: imageTypeJPEG,
|
||||
Format: imageTypeUnknown,
|
||||
Blur: 0,
|
||||
Sharpen: 0,
|
||||
Watermark: watermarkOptions{Opacity: 1, Replicate: false, Gravity: gravityCenter},
|
||||
|
@ -37,7 +37,7 @@ func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithoutExtension() {
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
assert.Equal(s.T(), imageURL, getImageURL(ctx))
|
||||
assert.Equal(s.T(), imageTypeJPEG, getProcessingOptions(ctx).Format)
|
||||
assert.Equal(s.T(), imageTypeUnknown, getProcessingOptions(ctx).Format)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParseBase64URLWithBase() {
|
||||
@ -78,7 +78,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePlainURLWithoutExtension() {
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
assert.Equal(s.T(), imageURL, getImageURL(ctx))
|
||||
assert.Equal(s.T(), imageTypeJPEG, getProcessingOptions(ctx).Format)
|
||||
assert.Equal(s.T(), imageTypeUnknown, getProcessingOptions(ctx).Format)
|
||||
}
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePlainURLEscaped() {
|
||||
imageURL := "http://images.dev/lorem/ipsum.jpg?param=value"
|
||||
|
Loading…
Reference in New Issue
Block a user