Skip to content

Fix JPEG rotation fallback when jpegtran is unavailable and add CI support#29

Merged
duartebarbosadev merged 4 commits intomainfrom
copilot/fix-1f0e0c9f-95ff-4d88-95d4-983238f1bfe2
Sep 2, 2025
Merged

Fix JPEG rotation fallback when jpegtran is unavailable and add CI support#29
duartebarbosadev merged 4 commits intomainfrom
copilot/fix-1f0e0c9f-95ff-4d88-95d4-983238f1bfe2

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 2, 2025

The CI was failing with rotation integration tests due to JPEG files being unable to rotate when jpegtran is not available in the system. The error was:

FAILED tests/test_rotation_integration.py::TestRotationIntegration::test_full_rotation_cycle_returns_to_original - AssertionError: Rotation 1 failed
FAILED tests/test_rotation_integration.py::TestRotationIntegration::test_mixed_rotations_sequence[rotation_sequence0] - AssertionError: clockwise rotation failed

With the underlying error: "Failed to rotate tmpw5cp8117.jpg clockwise using unsupported format for pixel rotation method"

Root Cause

In ImageRotator.rotate_image(), when jpegtran is not available, JPEG files would fall through to "unsupported format" because:

  • JPEG files are in _LOSSLESS_JPEG_FORMATS but the condition file_ext in self._LOSSLESS_JPEG_FORMATS and self.jpegtran_available evaluates to False when jpegtran is unavailable
  • JPEG files are not in _STANDARD_PIXEL_ROTATION_FORMATS or _LOSSLESS_HEIF_FORMATS
  • So they hit the else block and get "unsupported format for pixel rotation"

Solution

Added libjpeg-turbo-progs to CI dependencies in .github/workflows/ci.yml to ensure jpegtran is available during testing, enabling optimal lossless JPEG rotation in the CI environment.

With jpegtran now available in CI, JPEG files use the lossless rotation path exclusively. If jpegtran becomes unavailable in any environment, JPEG files will be treated as unsupported format rather than attempting lossy fallback rotation.

Testing

  • ✅ All 4 previously failing rotation integration tests now pass
  • ✅ All 24 rotation-related unit tests pass without regressions
  • ✅ CI environment now supports lossless JPEG rotation testing

The fix ensures JPEG rotation works optimally in CI while maintaining clean failure behavior when jpegtran is unavailable elsewhere.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: duartebarbosadev <13065435+duartebarbosadev@users.noreply.github.com>
Copilot AI changed the title [WIP] The ci is currentely failing with ---------------------------------------------------------------------------- TOTAL 8987 6584 27% Coverage XML written to file coverage.xml Required test coverage... Fix JPEG rotation fallback when jpegtran is unavailable Sep 2, 2025
@duartebarbosadev duartebarbosadev marked this pull request as ready for review September 2, 2025 20:13
@duartebarbosadev
Copy link
Copy Markdown
Owner

@copilot Why isn't jpegtran not available?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 2, 2025

@copilot Why isn't jpegtran not available?

jpegtran is not available by default in Ubuntu base images used by GitHub Actions. It needs to be explicitly installed via system packages like libjpeg-progs or libjpeg-turbo-progs.

The CI workflow currently only installs PyQt6 system dependencies (libgl1 libglib2.0-0 libegl1) but doesn't install JPEG manipulation tools.

If you want lossless JPEG rotation in CI, you could add this to the "Install system deps" step:

sudo apt-get install -y libjpeg-turbo-progs

However, the fallback approach is still valuable since many end users might not have jpegtran installed either. The fix ensures JPEG rotation works everywhere, with lossless rotation when jpegtran is available and standard rotation as fallback.

@duartebarbosadev
Copy link
Copy Markdown
Owner

@copilot Why isn't jpegtran not available?

jpegtran is not available by default in Ubuntu base images used by GitHub Actions. It needs to be explicitly installed via system packages like libjpeg-progs or libjpeg-turbo-progs.

The CI workflow currently only installs PyQt6 system dependencies (libgl1 libglib2.0-0 libegl1) but doesn't install JPEG manipulation tools.

If you want lossless JPEG rotation in CI, you could add this to the "Install system deps" step:

sudo apt-get install -y libjpeg-turbo-progs

However, the fallback approach is still valuable since many end users might not have jpegtran installed either. The fix ensures JPEG rotation works everywhere, with lossless rotation when jpegtran is available and standard rotation as fallback.
Help improve Copilot by leaving feedback using the 👍 or 👎 buttons

If you want lossless JPEG rotation in CI, you could add this to the "Install system deps" step:
sudo apt-get install -y libjpeg-turbo-progs

Lets do it!

Co-authored-by: duartebarbosadev <13065435+duartebarbosadev@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 2, 2025

@copilot Why isn't jpegtran not available?

jpegtran is not available by default in Ubuntu base images used by GitHub Actions. It needs to be explicitly installed via system packages like ...

Added libjpeg-turbo-progs to CI system dependencies in commit 7614600. Now jpegtran will be available during CI runs for optimal lossless JPEG rotation testing, while maintaining the fallback approach for environments where it's not installed.

Copilot AI changed the title Fix JPEG rotation fallback when jpegtran is unavailable Fix JPEG rotation fallback when jpegtran is unavailable and add CI support Sep 2, 2025
@duartebarbosadev
Copy link
Copy Markdown
Owner

@copilot Why isn't jpegtran not available?

jpegtran is not available by default in Ubuntu base images used by GitHub Actions. It needs to be explicitly installed via system packages like ...

Added libjpeg-turbo-progs to CI system dependencies in commit 7614600. Now jpegtran will be available during CI runs for optimal lossless JPEG rotation testing, while maintaining the fallback approach for environments where it's not installed.
Help improve Copilot by leaving feedback using the 👍 or 👎 buttons

now remove your change that you did on elif file_ext in self._STANDARD_PIXEL_ROTATION_FORMATS or file_ext in self._LOSSLESS_JPEG_FORMATS: the jpeg should work now without it right?

Now that jpegtran is available in CI, JPEG files will only use the lossless rotation path and fall through to "unsupported format" if jpegtran is not available, removing the lossy fallback.

Co-authored-by: duartebarbosadev <13065435+duartebarbosadev@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Sep 2, 2025

@copilot Why isn't jpegtran not available?

...

Removed the JPEG fallback from standard pixel rotation path in commit b7dc862. Now that jpegtran is available in CI, JPEG files will only use the lossless rotation path and be treated as unsupported format if jpegtran becomes unavailable, instead of falling back to lossy pixel rotation.

All rotation tests continue to pass with this change.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@duartebarbosadev duartebarbosadev merged commit 6b31f4e into main Sep 2, 2025
3 of 6 checks passed
@duartebarbosadev duartebarbosadev deleted the copilot/fix-1f0e0c9f-95ff-4d88-95d4-983238f1bfe2 branch September 2, 2025 21:00
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

Successfully merging this pull request may close these issues.

2 participants