Browse Source

Fix Pillow issue with recognizing pngs

pull/333/head
Ionite 1 year ago
parent
commit
28a593d420
No known key found for this signature in database
  1. 16
      StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs

16
StabilityMatrix.Avalonia/ViewModels/Base/InferenceGenerationViewModelBase.cs

@ -205,8 +205,20 @@ public abstract partial class InferenceGenerationViewModelBase
uploadName
);
await using var stream = localFile.Info.OpenRead();
await client.UploadImageAsync(stream, uploadName);
// For pngs, strip metadata since Pillow can't handle some valid files?
if (localFile.Info.Extension.Equals(".png", StringComparison.OrdinalIgnoreCase))
{
var bytes = PngDataHelper.RemoveMetadata(await localFile.ReadAllBytesAsync());
using var stream = new MemoryStream(bytes);
await client.UploadImageAsync(stream, uploadName);
}
else
{
await using var stream = localFile.Info.OpenRead();
await client.UploadImageAsync(stream, uploadName);
}
}
}
}

Loading…
Cancel
Save