Skip to content

Commit f9ab719

Browse files
Copy subsampling values
1 parent 8152536 commit f9ab719

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/ImageSharp.Web/Processors/JpegQualityWebProcessor.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Globalization;
66
using Microsoft.Extensions.Logging;
7+
using SixLabors.ImageSharp.Advanced;
78
using SixLabors.ImageSharp.Formats.Jpeg;
89
using SixLabors.ImageSharp.Web.Commands;
910

@@ -38,9 +39,19 @@ public FormattedImage Process(
3839
{
3940
if (commands.ContainsKey(Quality) && image.Format is JpegFormat)
4041
{
42+
var reference =
43+
(JpegEncoder)image.Image
44+
.GetConfiguration()
45+
.ImageFormatsManager
46+
.FindEncoder(image.Format);
47+
4148
// The encoder clamps any values so no validation is required.
4249
int quality = parser.ParseValue<int>(commands.GetValueOrDefault(Quality), culture);
43-
image.Encoder = new JpegEncoder() { Quality = quality };
50+
51+
if (quality != reference.Quality)
52+
{
53+
image.Encoder = new JpegEncoder() { Quality = quality, Subsample = reference.Subsample };
54+
}
4455
}
4556

4657
return image;

0 commit comments

Comments
 (0)