Skip to content

fix: preserve colors in uploaded images (draft, not for merge) - #828

Closed
anttikissa wants to merge 1 commit into
dev-null-sh:productionfrom
anttikissa:fix/upload-color-profiles
Closed

anttikissa wants to merge 1 commit into
dev-null-sh:productionfrom
anttikissa:fix/upload-color-profiles

Conversation

@anttikissa

Copy link
Copy Markdown

Refs #806.

Not for merge as-is: this shows a working color fix, but it needs server changes the diff can't make. Uploads are converted to sRGB with libvips before metadata is removed, so Display P3 screenshots keep their colors instead of looking washed out. Size limit, WebP quality, orientation handling and metadata removal stay the same.

Changes:

  • CreateCommitImageFiles uses libvips (jcupitt/vips) instead of GD: load, autorotate, convert to sRGB, resize, save WebP without metadata.
  • New test with a single-color PNG: tagged Display P3 comes back as sRGB red (fails with the current GD code), untagged keeps its color.

Server requirements (why this is a draft):

  • libvips with ICC and EXIF support
  • ffi.enable=true globally (php-vips can't use preloading)
  • zend.max_allowed_stack_size=-1 on PHP 8.3+
  • libvips preloaded into the PHP process; without it, the web server segfaulted after each upload. Tested locally with DYLD_INSERT_LIBRARIES on macOS.

Known gaps: libvips errors are reported as validation errors, PNG EXIF orientation is now applied (GD ignores it) but untested, and only the image tests were run locally (no coverage driver).

@anttikissa

Copy link
Copy Markdown
Author

The things I had to do to make it work:

# 1. Get the branch
gh pr checkout 828 --repo nunomaduro/dev-null.sh

# 2. Install libvips and the PHP binding
brew install vips
composer install

# 3. PHP settings that php-vips needs (add to your php.ini)
#    ffi.enable=true
#    zend.max_allowed_stack_size=-1
php -r 'echo ini_get("ffi.enable"), " ", ini_get("zend.max_allowed_stack_size"), PHP_EOL;'   #
expect: 1 -1

# 4. Run the color tests
vendor/bin/pest tests/Unit/Actions/CreateCommitImagesTest.php --filter srgb

# 5. Build the frontend once, because Vite won't run
bun install && bun run build

# 6. Start the web server with libvips preloaded (without this it segfaults after an upload)
cd public
DYLD_INSERT_LIBRARIES="$(brew --prefix vips)/lib/libvips.42.dylib" \
 /path/to/real/php -S 127.0.0.1:8000 \
 ../vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php

# 7. In a second terminal: start the queue worker
php artisan queue:listen --tries=1

@anttikissa anttikissa closed this Oct 20, 2026
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.

1 participant