Skip to content

Add comprehensive image processing tests and improve error handling - #25

Merged
codeling merged 1 commit into
mainfrom
claude/imagemagick-upload-tests
Oct 3, 2026
Merged

codeling merged 1 commit into
mainfrom
claude/imagemagick-upload-tests

Conversation

@codeling

@codeling codeling commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds comprehensive integration tests for image processing functionality (resizing, EXIF orientation, and format conversion) and improves error handling to prevent leaving corrupted files behind when processing fails.

Key Changes

Tests (tests/Integration/ImageProcessingTest.php)

  • Added 30+ integration tests covering image processing with ImageMagick
  • Tests for image resizing with aspect ratio preservation and maximum size clamping
  • Tests for EXIF orientation detection and application (rotation by 90°, 180°, -90°)
  • Tests for image format conversion (GIF, HEIC/HEIF to JPEG)
  • Tests for combined operations (resize + rotate, convert + resize)
  • Tests for error handling with corrupt images
  • Security tests to ensure ImageMagick delegates (MSL, MVG, etc.) cannot be triggered by uploads
  • Tests skip gracefully when Imagick extension is unavailable or lacks HEIC support

Core Functionality (index.php)

  • Wrapped image processing in try-catch block to handle ImagickException
  • On processing failure: removes the temporary file, logs the error, and displays user-friendly error message
  • Prevents leaving half-processed uploads behind when corruption or other errors occur
  • Preserves existing files when overwrite is attempted with a corrupt replacement
  • Only commits to git and shows usage instructions if processing succeeds

Test Infrastructure

  • Added test fixture images with various EXIF orientations (1, 3, 6, 8)
  • Added sample HEIC image for format conversion testing
  • Updated tests/README.md to document imagick dependency and HEIC test requirements
  • Updated GitHub Actions workflow to include imagick extension in test environment

Implementation Details

  • Image processing errors are caught and logged with context
  • Failed processing prevents git commits and usage instructions from being shown
  • The error message indicates whether the file is valid, helping users diagnose issues
  • Tests use data providers for comprehensive coverage of edge cases (max size clamping, various orientations)
  • Security-focused tests verify that ImageMagick's powerful delegate system cannot be exploited through file uploads

https://claude.ai/code/session_011k94dX3j9otoThuhZM9YSd

…e temporary file

Tests cover resizing, maxsize clamping, EXIF orientation, conversion (HEIC and
GIF), overwrite confirmation for converted names and delegate safety. A corrupt
image now gives an error message instead of a fatal ImagickException and no
longer leaves the -tmp-process file behind. CI installs the imagick extension.

Closes #16

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011k94dX3j9otoThuhZM9YSd
@codeling
codeling merged commit cca7c5d into main Oct 3, 2026
15 checks passed
@codeling
codeling deleted the claude/imagemagick-upload-tests branch October 5, 2026 15:03
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