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

ws.Drawings.AddPicture don't support jpeg/exif #645

Closed
superboy1984 opened this issue May 17, 2022 · 5 comments
Closed

ws.Drawings.AddPicture don't support jpeg/exif #645

superboy1984 opened this issue May 17, 2022 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@superboy1984
Copy link

superboy1984 commented May 17, 2022

i use epplus 6.0.4 export excel with image

var imageInfo = new FileInfo(localImageFileName);
picture = ws.Drawings.AddPicture($"image_{DateTime.Now.Ticks}", imageInfo);

then thrown exception:
System.InvalidOperationException: No image handler for image type Jpg

then i change my code

FileStream fileStream = new FileStream(localImageFileName, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[4];
fileStream.Read(buffer, 0, 4);
string magicNumberMapping = string.Join("", buffer.Select(element => element.ToString("X2")));
fileStream.Seek(0, SeekOrigin.Begin);
picture = ws.Drawings.AddPicture($"image_{DateTime.Now.Ticks}", fileStream, ePictureType.Jpg);

then find those images of thrown exception magicNumberMapping is 'FFD8FFE1', work fine magicNumberMapping is 'FFD8FFE0'
FFD8FFE0(JPEG/JFIF),FFD8FFE1(JPEG/EXIF)

@JanKallman
Copy link
Contributor

I'll have a look. Can you attach a failing image?

@superboy1984
Copy link
Author

superboy1984 commented May 17, 2022

https://img.d.esyer.com/ActivityCheckInImgs/b6378daec4e345afa6467ef9ce247003/368df222-0952-41c3-af20-23c9b433451f.jpg

open with UltraEdit
00000000h: FF D8 FF E1 01 37 45 78 69 66 00 00 4D 4D 00 2A

@JanKallman
Copy link
Contributor

Thanks. The GenericImageReader seems to fail on this image. The TIFF header is correctly read, but it fails in a later stage and causes an exception. I'll investigate and provide a fix shortly.

I assume you use a non-GDI environment as this works in Windows and Linux with libgdiplus with the
If you have libgdiplus installed you can force the image handler to use System.Drawing instead:

package.Settings.ImageSettings.PrimaryImageHandler = new SystemDrawingImageHandler();

@JanKallman JanKallman self-assigned this May 18, 2022
@JanKallman JanKallman added the bug Something isn't working label May 18, 2022
JanKallman added a commit that referenced this issue May 18, 2022
@JanKallman
Copy link
Contributor

I have applied a fix for this issue. The internal jpg reader seems to get out of sync after reading the App0 header. Feel free to try it using our develop nuget feed ... https://github.com/EPPlusSoftware/EPPlus/wiki/Using-our-Develop-Nuget-Feed

@JanKallman
Copy link
Contributor

This is fixed in version 5.8.11 and 6.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants