mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.29k stars 531 forks source link

[BUG] "dotnet: symbol lookup error: /var/task/libSkiaSharp.so: undefined symbol: FcConfigGetSysRoot" when publishing SkiaSharp in AWS Lambda Function #1635

Open MohanaselvamJ opened 3 years ago

MohanaselvamJ commented 3 years ago

Description

Facing error while using SkiaSharp library in AWS Lambda funtion

Code

SKBitmap bitmap = new SKBitmap(100, 100, SKImageInfo.PlatformColorType, SKAlphaType.Premul);
        var surface = SKSurface.Create(bitmap.Info);
        SKCanvas canvas = surface.Canvas;
        canvas.Clear(SKColors.White);
        var paint = new SKPaint();
        paint.IsAntialias = true;
        paint.Color = SKColors.Red;
        paint.StrokeWidth = 3;
        canvas.DrawCircle(50, 50, 25, paint);
        var image = SKImage.FromBitmap(bitmap);
        var data = surface.Snapshot().Encode(SKEncodedImageFormat.Jpeg, 80);
        MemoryStream outputStream = new MemoryStream();
        data.SaveTo(outputStream);
        outputStream.Position = 0;
        return "SkiaSharpImageCreation";

Expected Behavior

Should working fine

Actual Behavior

Got error. Please refer the below screenshot which taken from CloudWatchLogs of particular function in AWS Lambda image

Basic Information

Refer screenshots of sample settings and dependencies. Dependecies used: ![image](https://user-images.githubusercontent.com/41197331/108333639-2ebe0d00-71f7-11eb-9154-479eed99b57c.png) Code snippet: ![image](https://user-images.githubusercontent.com/41197331/108333723-45646400-71f7-11eb-869c-0a071a8815c8.png) Sample properties: ![image](https://user-images.githubusercontent.com/41197331/108333842-5ca35180-71f7-11eb-829b-c2923274c204.png)

Reproduction Link

Create simple AWS Lambda function sample and use above code snippet. Then, invoke the function using simple ASP.NET Core application.

`

        AmazonLambdaClient client = new AmazonLambdaClient("accesskey", "secretkey", RegionEndpoint.USEast2);

        //Create new InvokeRequest with published function name.
        InvokeRequest invoke = new InvokeRequest
        {
            FunctionName = "MyNewFunction",
            InvocationType = InvocationType.RequestResponse,
            Payload = "\"Test\""
        };

        //Get the InvokeResponse from client InvokeRequest.
        InvokeResponse response = client.Invoke(invoke);

        //Read the response stream
        var stream = new StreamReader(response.Payload);
        JsonReader reader = new JsonTextReader(stream);
        var serilizer = new JsonSerializer();
        var responseText = serilizer.Deserialize(reader);`

Seems like regression in latest

MohanaselvamJ commented 3 years ago

Any update would be really helpful?

mattleibow commented 3 years ago

Are you installing fontconfig one the AWS side?

Maybe you meant to use the NoDependencies version of the package? https://www.nuget.org/packages/SkiaSharp.NativeAssets.Linux.NoDependencies/2.80.3-preview.40

MohanaselvamJ commented 3 years ago

I have removed SkiaSharp.NativeAssets.Linux from my project

Then installed Sharp.NativeAssets.Linux.NoDependencies v2.80.2

Now working fine.

Thanks.

RamarajMarimuthu commented 3 years ago

Hi @mattleibow,

After installing a SkiaSharp.NativeAssets.Linux.NoDependencies v2.80.2 package in .NET Core 2.1 targeted AWS lambda function, SkiaSharp library performs text measuring properly by using default SkTypeface "DejaVu Sans". When we try to perform a same measuring in .NET Core 3.1 targeted AWS lambda function, it always returns a width of input text as 0.

Please find the below code snippet that we used to measure a text using SkiaSharp,

// Returns width as "40" in .NET Core 2.1 and returns width as "0" in .NET Core 3.1.
SKPaint paint = new SKPaint();
return paint.MeasureText("Simple");

From further investigation, we found default SkTypeface seems empty in a .NET Core 3.1 targeted AWS lambda function. Could you please let us know, how we can able to measure a text in .NET Core 3.1 targeted AWS lambda function using SkiaSharp ?

Please refer the below code snippet,

// Returns FamilyName as "DejaVu Sans" in .NET Core 2.1 and returns FamilyName as "" in .NET Core 3.1.
SKTypeface typeface = SKTypeface.Default;
return typeface.FamilyName;

Additional Information:

While trying to retrieve a available font families of .NET Core 2.1 targeted AWS lambda function using SKFontManager, it returns below font family names. But .NET Core 3.1 targeted AWS lambda function returns 0 font familes.

**.NET Core 2.1 font families:**

  1. DejaVu Sans,
  2. DejaVu Serif,
  3. URW Bookman L,
  4. URW Palladio L,
  5. Nimbus Sans L,
  6. Century Schoolbook L,
  7. Nimbus Roman No9 L,
  8. URW Gothic L,
  9. Nimbus Mono L,
  10. URW Chancery L,
  11. Dingbats,
  12. Standard Symbols L

Please find the below code snippet that we used to retrieve a available font families,

            SKFontManager fontManager = SKFontManager.Default;
            string[] fonts = fontManager.GetFontFamilies();

Also, we like to know, when we should prefer SkiaSharp.NativeAssets.Linux.NoDependencies and SkiaSharp.NativeAssets.Linux packages. Is there any documentation available to refer ?

Thanks in advance.

RamarajMarimuthu commented 3 years ago

@mattleibow - Could you please help us to resolve this ?