Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image resizing exception: System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform. #21

Open
sunsiz opened this issue Apr 20, 2024 · 3 comments

Comments

@sunsiz
Copy link

sunsiz commented Apr 20, 2024

Describe the bug
When running on Linux the Scale method throw: "Image resizing exception: System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform." exception.
As in docs explained I have installed libc6-dev and libgdiplus libraries.

There is also another issue if path is contains backslash like this:
Path.Combine(webRootPath, @"images\artist");
it will throw directory not found exception on Linux, as a workaround I have changed the backslash to forward slash it worked.

To Reproduce
Steps to reproduce the behavior:

  1. Run the application on Linux
  2. Scale an image while uploading
  3. If not debugging or on server you can see the errors in logs.

Expected behavior
***** Image resizing exception: System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
at System.Drawing.Image.FromStream(Stream stream)

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Debian 5.10.209-2 (2024-01-31) x86_64 GNU/Linux
  • Browser Chrome
  • Version LazZiya.ImageResize 4.1.4

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Example code block looks like this:

var uploads = Path.Combine(webRootPath, @"images/artist");
var fileName = file.FileName;
var namePart = fileName.Remove(fileName.LastIndexOf('.'));
var extension = fileName.Substring(fileName.LastIndexOf('.'));
using var fileStream = new FileStream(Path.Combine(uploads, fileName), FileMode.Create);
file.CopyTo(fileStream);
using var img = Image.FromStream(fileStream);
img.Scale(384, 384).SaveAs(Path.Combine(uploads, namePart + "-384" + extension));
@LazZiya
Copy link
Owner

LazZiya commented Apr 21, 2024

Which .net version you are using?

LazZiya.ImageResize depends on System.Drawing.Common starting .net6 it is only supported on windows, due to numerous issues reported to libgdiplus that never got fixed!

@sunsiz
Copy link
Author

sunsiz commented Apr 22, 2024

Oh, I used .net 8.0. Is there any other known workaround for it?

@LazZiya
Copy link
Owner

LazZiya commented Apr 25, 2024

Not sure if this will work; create a class library project targeting lower .net framework and install ImageResize nuget. Then add a reference to your project!?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants