Skip to content

refactor(api): replace ImageSharp with SkiaSharp - #198

Merged
thomas-lg merged 1 commit into
mainfrom
refactor/replace-imagesharp-with-skiasharp
Oct 10, 2026
Merged

thomas-lg merged 1 commit into
mainfrom
refactor/replace-imagesharp-with-skiasharp

Conversation

@thomas-lg

Copy link
Copy Markdown
Owner

Summary

ImageSharp stopped being an option on two fronts at once:

SkiaSharp 4.153.1 (MIT) takes over the two jobs ImageSharp had:

  • Photo uploads (FileSystemPhotoStorage): same checks, same order. The header is read for dimensions before any full decode, the decode itself is the last check, and the stored file is re-encoded from pixels (JPEG/WebP quality 75, ImageSharp's default, so stored photos weigh what they did).
  • OCR pre-processing (UprightImage): untagged photos still go to the engine byte for byte. Rotated ones are turned upright and sent as PNG.

One behaviour change, deliberate: Skia's decoder reports the EXIF orientation without applying it, and its encoders write no EXIF. So OrientedImage applies the orientation to the pixels when a photo is stored. ImageSharp used to copy the photo's metadata into the stored file, GPS included, despite the class comment saying only pixels were kept. That is now actually true.

Linux native binaries come from SkiaSharp.NativeAssets.Linux.NoDependencies, because the default Linux build links fontconfig, which the runtime image doesn't have. dotnet publish ships both linux-x64 and linux-arm64. The Dependabot ignore rule for ImageSharp majors goes away with the package.

Checklist

  • PR title follows Conventional Commits
  • Tests: UprightImageTests (pass-through, orientations 6 and 8 checked by pixel colour, garbage passed through), a storage test that a tagged photo is stored upright, existing fixtures moved to Skia. Since Skia can't write EXIF, TestImages.WithExifOrientation splices an APP1 segment by hand, which TesseractOrientationTests now uses too
  • Local checks pass: dotnet build -c Release (no warnings), dotnet test (331 passed, 4 OCR benchmarks skipped without engines locally), --locked-mode restore of Api and Tests
  • Lockfiles regenerated
  • Not verified locally: running the published API inside the runtime image. CI's backend job loads the native library on Ubuntu x64

Related issues

Supersedes the ImageSharp part of #195.

ImageSharp 3.2.0 now refuses to build without a Six Labors license key,
and every version up to 4.1.1 carries the advisories published on
2026-10-07 (GHSA-j3p4-wp97-rph4 and four others), so neither staying on
3.1.12 nor taking the 3.2.0 bump was an option for a public repository
anyone should be able to build.

SkiaSharp (MIT) takes over the two jobs ImageSharp had: validating and
re-encoding uploaded photos, and turning EXIF-rotated photos upright
before OCR. Its decoder reports the orientation tag without applying it
and its encoders write no EXIF, so the orientation is now applied to the
pixels when a photo is stored, where ImageSharp used to carry the tag
over. The Linux native binaries come from the NoDependencies package,
since the runtime image has no fontconfig.
@github-actions github-actions Bot added the chore label Oct 10, 2026
@thomas-lg
thomas-lg merged commit c3943f9 into main Oct 10, 2026
10 checks passed
@thomas-lg
thomas-lg deleted the refactor/replace-imagesharp-with-skiasharp branch October 10, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant