by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 03 14:22
    antonfirsov commented #946
  • Jun 02 22:24
    greg-dickie commented #946
  • Jun 02 22:17
    greg-dickie commented #946
  • May 28 02:04
    YuanfanHu commented #1209
  • May 27 17:36
    codecov[bot] commented #1196
  • May 27 17:36
    codecov[bot] commented #1196
  • May 27 17:35
    JimBobSquarePants commented #1196
  • May 27 17:32
    JimBobSquarePants synchronize #1196
  • May 27 17:32

    JimBobSquarePants on fake-async-codecs

    DetectFormat for tga now additi… Merge pull request #1210 from S… Merge branch 'master' into sw/f… (compare)

  • May 27 17:31

    JimBobSquarePants on master

    DetectFormat for tga now additi… Merge pull request #1210 from S… (compare)

  • May 27 17:31

    JimBobSquarePants on detectTga

    (compare)

  • May 27 17:31
    JimBobSquarePants closed #1210
  • May 27 17:31
    JimBobSquarePants closed #1208
  • May 27 12:27
    brianpopow labeled #1210
  • May 27 12:27
    brianpopow opened #1210
  • May 27 12:27
    tocsoft commented #1208
  • May 27 12:23

    brianpopow on detectTga

    DetectFormat for tga now additi… (compare)

  • May 27 12:12
    brianpopow assigned #1208
  • May 27 12:03
    JimBobSquarePants commented #1204
  • May 27 12:02
    JimBobSquarePants commented #1207
Dennis Cassøe
@dcasso
image.png
image.png
same parameters sent to the text
using a simple drawtext function that convert a string of rgb to the rgba you see above
textcanvas.Mutate(x => x.DrawText(StringToColor(values["c"]).ToString(), font, StringToColor(values["c"]), point));
Peter Amrehn
@jongleur1983
@dcasso can you share the entire code somehow?
Dennis Cassøe
@dcasso
it is a huge file. Just wanted to see if anyone had any pointers, so I could create a new function to see if I could replicate it
where I only have the core issue in
just wanted to hear if I was the first experiencing this or if not, there might be an idea to go for. If not, I'll create a new project with just this issue to share
Peter Amrehn
@jongleur1983
I don't know anybody experiencing the same. First attempt I have would be to check the color storage of the resulting file - is it somehow due to the color sometimes being skipped from an indexed palette or something (should not be, but who knows)
Dennis Cassøe
@dcasso
thx, I'll try to isolate the code and recreate it
Dennis Cassøe
@dcasso
sry not sure why the code doesn't all get marked up
the above code when refreshed on azure functions generate the green and the correct black from time to time
Dennis Cassøe
@dcasso
`
[FunctionName("IM1")]
public static async Task<IActionResult> Run1([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
Image<Rgba32> ProcessedImage;
using (Image<Rgba32> canvas = new Image<Rgba32>(800, 500))
{
canvas.Mutate(x => x.BackgroundColor(new Rgba32(255, 255, 255)));
ProcessedImage = canvas.Clone();
}
        using (Image<Rgba32> textcanvas = new Image<Rgba32>(800, 500))
        {

            var font = SystemFonts.CreateFont("Arial", 30);
            Random rn = new Random();
            float r = rn.Next(1,10);
            float g = rn.Next(1,10);
            float b = rn.Next(1,10);
            var color = new Rgba32(r, g, b);
            textcanvas.Mutate(x => x.DrawText(r + "-" + g + "-" + b + "---" + color.ToString(), font, color, new Point(0, 0)));

            GraphicsOptions go = new GraphicsOptions();
            ProcessedImage.Mutate(x => x.DrawImage(textcanvas, new Point(0, 0), go));
        }
        using (var returnImageStream = new MemoryStream())
        {
            ProcessedImage.Save(returnImageStream, new PngEncoder() { });
            return new FileContentResult(returnImageStream.ToArray(), "image/png"); ;
        }   
    }
made an updated version, where I insert a random number between 1 and 10 (seems mainly to happen with low numbers)
output contains the text and rgba color
https://wudimagemanipulator.azurewebsites.net/api/IM1
image.png
Scott Williams
@tocsoft
@dcasso can you try using a different encoder? bmp, or jpeg, to rule out the issue living in the encoder.. also try drawing the text directly onto ProcessedImage instead of using DrawImage() too. Try to isolate down to the single operation that's introducing the discoloration. at the moment it could be DrawImage(), DrawText() or the png encode that's at fault
Dennis Cassøe
@dcasso
First version were mainly to recreate the process I was doing in a much larger codebase, but i'll try to make a few variations.
Scott Williams
@tocsoft
nice one... yeah I guessed it was probably a simplified model of a larger pipeline.
Dennis Cassøe
@dcasso
It is a layered app where you add images, text and shapes from a set of layers onto a bigger canvas. Which is the reason for the double image setup
Scott Williams
@tocsoft
yeah that makes sense.. would probably have done the same depending on what's being drawing on each layer.... there's probably some little tricks to prevent having to allocate an image for every layer (but I would only think about that on an an optermisation pass personally).
Dennis Cassøe
@dcasso
I am pretty sure there is quite a few way to optimize my codebase , no doubt :) and any input is always appreciated, just don't want to ask too many questions in here. But this one have had me stumped for days
Dennis Cassøe
@dcasso
if you have any idea for how to avoid creating an image each time, it would be nice. But I nede to be able to load images, text, rotate, add background and so forth
Dennis Cassøe
@dcasso
Decided to check the settings i azure functions. The app was set to run in a 32bit environment, I changed it to 64, could that be the reason
Adam Buchanan
@RejectKid
@JimBobSquarePants thanks!
Adam Buchanan
@RejectKid
@JimBobSquarePants ive noticed the Rational class cant be negative. guessing by design? unless ive used it wrong, which is usually the case lol
Peter Tribe
@UkooLabs
@dcasso you can save time loading images you constantly use by storing them in memory cache against a key (you create if doesnt exist other wise just load). You will also get speed increase if you just store the pixel data in cache rather than the image format as this will save decode time. ImageSharp provides ways of reading pixel data directly so you will have everything you need.
Dennis Cassøe
@dcasso
thanks @UkooLabs will have to look into that, that I will need to do the same task for different images 50.000 times :)
James Jackson-South
@JimBobSquarePants
@RejectKid You want SignedRational or LongRational.
Adam Buchanan
@RejectKid
ooo thanks you!
James Jackson-South
@JimBobSquarePants
@RejectKid no worries...
@saucecontrol Just got RLE ported. Worked first time which was nice! Compression at level 1 isn't as good as Deflate.Fast but I've yet to test it across different medium.
Clinton Ingram
@saucecontrol
Nice! Bummer it's not compressing well. Are there different levels/strategies to RLE? I know it works exceedingly well for solid color PNG, but I'm not sure how it compares with the normal deflate strategies on only partially sparse data
James Jackson-South
@JimBobSquarePants
Yeah, no... No levels for RLE. It matches to a maximum of 258.
Clinton Ingram
@saucecontrol
Ah, I didn't realize it had the same match length limit. Saw these examples before where RLE had a good showing on anything with big patches of similar color http://optipng.sourceforge.net/pngtech/z_rle.html
but I've never done any tests myself
James Jackson-South
@JimBobSquarePants
It was that page that lead me to wanting to implement the method actually. I'll have to experiment with the Kodak images when I have time.
Peter Tribe
@UkooLabs
@JimBobSquarePants have just idea you ever thought of adding own format to image sharp maybe some custom format which has the best of worlds like jpeg with a transparency mask , or maybe some type of utility thats able to analyze image and recomend a format / options etc
was also thinking of AI based compression
Peter Tribe
@UkooLabs
Looks like someone thought of things in line i was thinking https://pixeldrive.co/
James Jackson-South
@JimBobSquarePants
@UkooLabs Get me some venture capitalists to back it all and maybe in the future. 😁
Peter Tribe
@UkooLabs
hehe :)
Matthias Koch
@matkoch
Hi everyone! Is there any way to set a line height when using DrawText ?
Adam Buchanan
@RejectKid
@JimBobSquarePants if i wanted to mock a situation where an Image has a specific ExifTag, how can that work? ImageMetadata cant be newed or mock as an outsider. (sorry for so many questions, youve been great!)
James Jackson-South
@JimBobSquarePants
Why not use an image and set the metadata?
Adam Buchanan
@RejectKid
like just new up an image?
something like
var image = new Image<Rgba32>(5,5);
i guess im used to always mocking the interface rather than newing things up like that
James Jackson-South
@JimBobSquarePants
Mocking should be an absolute last resort. I’ve seen so many instances where devs are trying to test too much at the same time and end up mocking things as a stop gap.
Adam Buchanan
@RejectKid
gotcha. thanks so much man!
James Jackson-South
@JimBobSquarePants
No worries