Skip to content

[18.0][FIX] web_company_color: integer division in image color extraction#3551

Open
fsmw wants to merge 1 commit into
OCA:18.0from
fsmw:18.0-fix-web-company-color-integer-division
Open

[18.0][FIX] web_company_color: integer division in image color extraction#3551
fsmw wants to merge 1 commit into
OCA:18.0from
fsmw:18.0-fix-web-company-color-integer-division

Conversation

@fsmw

@fsmw fsmw commented May 16, 2026

Copy link
Copy Markdown

Issue

Closes #3532

In image_to_rgb() pixel loop uses i / width returning float in Python 3, causing getpixel() to raise TypeError in Pillow >= 10.2.0 because coordinates must be integers. This completely blocks color extraction when a logo is set.

Steps to reproduce

  1. Install web_company_color on Odoo >= 18.0
  2. Set a company logo
  3. Click 'Compute Colors from Logo'
  4. Traceback: TypeError - 'float' object cannot be interpreted as an integer

Fix

Replace i / width with i // width so getpixel() receives integer coordinates.

Backward Compatibility

Fully backward compatible; the behavior is identical for valid integer widths and fixes the crash with newer Pillow.

@MarwanBHL MarwanBHL left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it in Runboat and it's not working. And don't change the version, the bot does it automatically.

…eger division

Use i // width instead of i / width so getpixel() receives
integer coordinates (Pillow >= 10.2 compatible).

Catch PIL.UnidentifiedImageError in convert_to_image() and
raise a user-friendly UserError instead of a traceback.

Add test for invalid image data in convert_to_image().
@fsmw fsmw force-pushed the 18.0-fix-web-company-color-integer-division branch from 10e5775 to e4a0cff Compare June 5, 2026 14:25
@fsmw

fsmw commented Jun 5, 2026

Copy link
Copy Markdown
Author

Thanks for the review. I've addressed both points:

  1. Version bump removed — reverted the manifest change, bot will handle it.
  2. The fix now actually addresses web_company_color: Error when computing colors when using webp image as logo #3532: Added a try/except around Image.open() to catch UnidentifiedImageError (Pillow can't read WEBP) and show a user-friendly error instead of a traceback. The // integer division fix is also included for Pillow >= 10.2 compatibility.

Ready for re-review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:web_company_color Module web_company_color series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

web_company_color: Error when computing colors when using webp image as logo

3 participants