1
0
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:
DarthSim 2018-11-14 00:50:38 +06:00
parent 00b690e93d
commit da1a802632
5 changed files with 14 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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},

View File

@ -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"