Replies: 1 comment
-
|
This is an excellent feature request that addresses a real ergonomic issue. Your proposal is well-reasoned and the code example is clear. Let me provide some thoughts on this: Why This Makes SenseYour observation is spot-on. The current API forces users to either:
All of these approaches add unnecessary complexity when you just want to specify an encoder with custom parameters like Implementation ConsiderationsThe overload you've proposed looks solid, but there are a few things the maintainers would likely consider: 1. MIME Type HandlingOne thing I noticed in your code - you're using public static string ToBase64String(this Image source, IImageEncoder encoder, IImageFormat? format = null)
{
Guard.NotNull(encoder, nameof(encoder));
using var stream = new MemoryStream();
source.Save(stream, encoder);
stream.TryGetBuffer(out var buffer);
// If format not provided, try to get it from encoder's configuration
var mimeType = format?.DefaultMimeType ?? "application/octet-stream";
return $"data:{mimeType};base64,{Convert.ToBase64String(buffer.Array ?? [], 0, (int)stream.Length)}";
}2. Encoder DefinitionYou might want to check if the
The second option would be more explicit and consistent with the existing overload. 3. DocumentationWhen submitted, it would be great to include:
Next StepsI'd suggest:
This is definitely a worthwhile addition that would improve the API's usability. The SixLabors team is generally responsive to well-reasoned feature proposals with clear use cases like this one! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently we only have the function called
public static string ToBase64String(this Image source, IImageFormat format), and it usesIImageEncoder encoder = source.Configuration.ImageFormatsManager.GetEncoder(format);.So if we want to use specific image encoder(especially with a different
Qualityfrom the default) we have to set/change the encoder of the image configuration. It's like noise in the code, and there should already be a ready-made extension to deal with it.Beta Was this translation helpful? Give feedback.
All reactions