DEBUG and RELEASE modeWhen painting text if the text exceeds the boundary of the image horizontally due to font size with no wrapping
The DrawText method throws an argumentexception
ArgumentOutOfRangeException: Specified argument was out of the range of valid values.``
Parameter name: start
System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument)
SixLabors.ImageSharp.Processing.SolidBrush+SolidBrushApplicator.Apply(Span<float> scanline, int x, int y)
SixLabors.ImageSharp.Processing.Processors.Text.DrawTextProcessor.<OnFrameApply>g__Draw|22_0(List<DrawingOperation> operations, IBrush<TPixel> brush, ref <>c__DisplayClass22_0 )
SixLabors.ImageSharp.Processing.Processors.Text.DrawTextProcessor.OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
SixLabors.ImageSharp.Processing.Processors.ImageProcessor.Apply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
sing (Image<Rgba32> image = Image.Load("Assets/share-bg.png"))
{
FontCollection fontCollection = new FontCollection();
Font regularFont = fontCollection.Install("Assets/TitilliumWeb-SemiBold.ttf").CreateFont(24, FontStyle.Regular);
Font italicFont = fontCollection.Install("Assets/TitilliumWeb-BoldItalic.ttf").CreateFont(24, FontStyle.Italic);
image.Mutate(x => x.DrawText(text, regularFont, Rgba32.White, new PointF(100,100)));
MemoryStream stream = new MemoryStream();
image.Save(stream, new PngEncoder());
stream.Position = 0;
return stream;
}
Choose your font (doesn't matter), increase font size until the text you are painting overflows the dimension of the image
Windows 10, .net core
Only occurs when text overflows horizontally, not vertically
I'm guessing we should be measuring and clamping somewhere?
I am still able to reproduce the issue. When text being drawn exceeds image boundary then Specified argument was out of the range of valid values is thrown but only when overflow happens horizontally not vertically as @agrath said.
can you confirm you are still experiencing this issue in the nightlies on our myget feed? https://www.myget.org/gallery/sixlabors
Yes this is version I am using
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-dev002311" />
SixLabors.ImageSharp.ImageProcessingException: An error occurred when processing the image using DrawTextProcessor`1. See the inner exception for more detail. ---> SixLabors.ImageSharp.ImageProcessingException: An error occurred when processing the image using DrawTextProcessor`1. See the inner exception for more detail. ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
at SixLabors.ImageSharp.Processing.SolidBrush`1.SolidBrushApplicator.Apply(Span`1 scanline, Int32 x, Int32 y)
at SixLabors.ImageSharp.Processing.Processors.Text.DrawTextProcessor`1.<OnFrameApply>g__Draw|22_0(List`1 operations, IBrush`1 brush, <>c__DisplayClass22_0& )
at SixLabors.ImageSharp.Processing.Processors.Text.DrawTextProcessor`1.OnFrameApply(ImageFrame`1 source, Rectangle sourceRectangle, Configuration configuration)
at SixLabors.ImageSharp.Processing.Processors.ImageProcessor`1.Apply(ImageFrame`1 source, Rectangle sourceRectangle, Configuration configuration)
--- End of inner exception stack trace ---
at SixLabors.ImageSharp.Processing.Processors.ImageProcessor`1.Apply(ImageFrame`1 source, Rectangle sourceRectangle, Configuration configuration)
at SixLabors.ImageSharp.Processing.Processors.ImageProcessor`1.Apply(Image`1 source, Rectangle sourceRectangle)
--- End of inner exception stack trace ---
at SixLabors.ImageSharp.Processing.Processors.ImageProcessor`1.Apply(Image`1 source, Rectangle sourceRectangle)
at SixLabors.ImageSharp.Processing.DefaultInternalImageProcessorContext`1.ApplyProcessor(IImageProcessor`1 processor, Rectangle rectangle)
at SixLabors.ImageSharp.Processing.DrawTextExtensions.DrawText[TPixel](IImageProcessingContext`1 source, TextGraphicsOptions options, String text, Font font, TPixel color, PointF location)
at FillYourDocuments.DocumentController.<>c__DisplayClass2_0.<Render>b__0(IImageProcessingContext`1 ctx) in /Users/kolpav/Projects/fillyourdocuments/apps/auth/FillYourDocuments/Controllers/DocumentController.cs:line 40
at SixLabors.ImageSharp.Processing.ProcessingExtensions.Mutate[TPixel](Image`1 source, Action`1 operation)
Reproduction is easy just try to draw long string over image. I haven't tried increasing font size but I guess that will work too.
@kolpav Can you please provide a reduced code sample to replicate the issue we can use in tests. That would be really useful to us.
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-dev002311" />
C#
using (Image<Rgba32> img = new Image<Rgba32>(1500, 500))
{
var font = SystemFonts.CreateFont("Arial", 39, FontStyle.Regular);
string text = new String('a', 10000); // exception
// string text = "Hello"; // no exception
img.Mutate(ctx => ctx
.Fill(Rgba32.White)
.DrawText(text, font, Rgba32.Black, new PointF(100, 100)));
}
@JimBobSquarePants Is something like this enough? I would write proper test in PR but I have trouble running them on mac.
@kolpav That should be enough, Thanks!
Still happens in the latest nuget package available as of the date of posting.
Still happens in the latest nuget package available as of the date of posting.
That's why the issue is still open.
That's why the issue is still open.
Obviously... why else would I be posting? It's a more-than-year-old bug, it's reasonable for me to assume it may have been forgotten. I that is the case then making some kind of post is a great way to bring it back into the spotlight.
@WChrisK I expect a PR by Monday then.
Imagine getting this triggered over someone making a simple post about a bug. Oh well...
Imagine getting this triggered over someone making a simple post about a bug. Oh well...
@WChrisK Nobody here is "triggered". I originally meant my PR comment as tongue in cheek but there's a valid concern here now.
ImageSharp is provided AS-IS. There is no obligation from anybody here to provide fixes for any bugs and it comes across as entitled for you to expect us to do so now that you have "reminded" us. As I said before, the issue is open, we are fully aware of open issues and will fix them if and when we are able to do so. Additional non-constructive comments do not add benefit, only noise.
Everyone involved in this project is working on the library in their spare time. That means volunteering their unpaid time on evenings and weekends in addition to the normal workload of day-to-day life. We all have families and obligations which limit us to maybe grabbing an hour on an evening after we've put our kids to sleep, or some other activity of greater priority than writing code.
Open Source is supposed to be collaborative and there is nothing stopping yourself from downloading the source, creating a failing test and having a dig around.
There is no obligation from anybody here to provide fixes for any bugs and it comes across as entitled for you to expect us to do so now that you have "reminded" us.
You're putting words in my mouth: I never once said - nor implied - that I expect that. I was simply putting a friendly reminder. Yes yes, I know, you don't view it that way (or else you certainly wouldn't have said what you did above) but I did genuinely mean it as a friendly reminder. It's hard for us to get anywhere when I'm being viewed as the way you described when I am not.
I'm sure you've run into some other people who believe that they owe you time to fix things because you're the maintainer, but that type of person is not me, and I'd be the first one to stand by your side against such people.
As I said before, the issue is open, we are fully aware of open issues and will fix them if and when we are able to do so.
I'm unfortunately not psychic (yet), I have to go on experience from countless other projects that range from hobby to professional where things just slip through the cracks. Mistakes happen. There is nothing negative nor demanding IMO about checking in after many months to see if something accidentally fell by the wayside. You may keep a tight leash on all of your issues (which is good) but even the best intentioned teams I've worked with don't have a 100% flawless track record. You may be perfect, but I'm certainly not and out of all the software jobs I've worked I haven't run into someone who is perfect. But hey, maybe you're the first... as they say, first time for everything!
Since you run this repository, I'll do my best to abide by the rules that I am pretty sure you would want followed after this convo and not make any notifications ever again if an existing issue is set to Open.
Fixed in #1008
@WChrisK Let's both take a step back here and start again on the right foot. It's far too easy to misconstrue intent when communication through text alone and I think there's been a bit of that on both sides here.
On a positive note, the fantastic @Turnerj 馃 has stepped up and submitted a fix which has been merged into the code base so you can now pull this from the nightlies on MyGet to work against.
Please let us know if you encounter any issues. 馃憤
Most helpful comment
@WChrisK Nobody here is "triggered". I originally meant my PR comment as tongue in cheek but there's a valid concern here now.
ImageSharp is provided AS-IS. There is no obligation from anybody here to provide fixes for any bugs and it comes across as entitled for you to expect us to do so now that you have "reminded" us. As I said before, the issue is open, we are fully aware of open issues and will fix them if and when we are able to do so. Additional non-constructive comments do not add benefit, only noise.
Everyone involved in this project is working on the library in their spare time. That means volunteering their unpaid time on evenings and weekends in addition to the normal workload of day-to-day life. We all have families and obligations which limit us to maybe grabbing an hour on an evening after we've put our kids to sleep, or some other activity of greater priority than writing code.
Open Source is supposed to be collaborative and there is nothing stopping yourself from downloading the source, creating a failing test and having a dig around.