Ensure format processor is before quality processor.
This commit is contained in:
committed by
Sebastiaan Janssen
parent
f7b42a50cc
commit
69c725b3ec
@@ -46,6 +46,7 @@ public sealed class ImageSharpImageUrlGenerator : IImageUrlGenerator
|
||||
}
|
||||
|
||||
var queryString = new Dictionary<string, string?>();
|
||||
Dictionary<string, StringValues> furtherOptions = QueryHelpers.ParseQuery(options.FurtherOptions);
|
||||
|
||||
if (options.Crop is not null)
|
||||
{
|
||||
@@ -80,12 +81,17 @@ public sealed class ImageSharpImageUrlGenerator : IImageUrlGenerator
|
||||
queryString.Add(ResizeWebProcessor.Height, options.Height?.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
if (furtherOptions.Remove(FormatWebProcessor.Format, out StringValues format))
|
||||
{
|
||||
queryString.Add(FormatWebProcessor.Format, format[0]);
|
||||
}
|
||||
|
||||
if (options.Quality is not null)
|
||||
{
|
||||
queryString.Add(QualityWebProcessor.Quality, options.Quality?.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<string, StringValues> kvp in QueryHelpers.ParseQuery(options.FurtherOptions))
|
||||
foreach (KeyValuePair<string, StringValues> kvp in furtherOptions)
|
||||
{
|
||||
queryString.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,33 @@ public class ImageSharpImageUrlGeneratorTests
|
||||
urlString);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetImageUrlFurtherOptionsModeAndQualityTest()
|
||||
{
|
||||
var urlString = s_generator.GetImageUrl(new ImageUrlGenerationOptions(MediaPath)
|
||||
{
|
||||
Quality = 10,
|
||||
FurtherOptions = "format=webp",
|
||||
});
|
||||
Assert.AreEqual(
|
||||
MediaPath +
|
||||
"?format=webp&quality=10",
|
||||
urlString);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetImageUrlFurtherOptionsWithModeAndQualityTest()
|
||||
{
|
||||
var urlString = s_generator.GetImageUrl(new ImageUrlGenerationOptions(MediaPath)
|
||||
{
|
||||
FurtherOptions = "quality=10&format=webp",
|
||||
});
|
||||
Assert.AreEqual(
|
||||
MediaPath +
|
||||
"?format=webp&quality=10",
|
||||
urlString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test that if options is null, the generated image URL is also null.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user