Skip to content

Remove use of deprecated Pillow function#178

Merged
whtsky merged 1 commit intowhtsky:masterfrom
brianhelba:getdata-deprecated
Mar 1, 2026
Merged

Remove use of deprecated Pillow function#178
whtsky merged 1 commit intowhtsky:masterfrom
brianhelba:getdata-deprecated

Conversation

@brianhelba
Copy link
Contributor

Fixes #170 by removing use of PIL.Image.getdata().

Rather than using the suggested replacement of get_flattened_data which would, require checking the version of Pillow, this uses PIL.Image.tobytes(), which is available on all versions of Pillow.

.tobytes is also significantly faster, as it doesn't require Python list iteration. Since the image is explicitly converted to "RGBA" format, the bytes representation is just a linear list of the pixel values anyway.

Fixes whtsky#170 by removing use of `PIL.Image.getdata()`.

Rather than using the suggested replacement of `get_flattened_data` which would,
require checking the version of Pillow, this uses `PIL.Image.tobytes()`,
which is available on all versions of Pillow.

`.tobytes` is also significantly faster, as it doesn't require Python list
iteration. Since the image is explicitly converted to "RGBA" format, the
bytes representation is just a linear list of the pixel values anyway.
@sonarqubecloud
Copy link

@brianhelba
Copy link
Contributor Author

@whtsky Please take a look.

@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.95%. Comparing base (1d912f9) to head (9fb0792).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #178   +/-   ##
=======================================
  Coverage   97.95%   97.95%           
=======================================
  Files           5        5           
  Lines         147      147           
=======================================
  Hits          144      144           
  Misses          3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@whtsky whtsky merged commit e16dc53 into whtsky:master Mar 1, 2026
12 checks passed
@whtsky
Copy link
Owner

whtsky commented Mar 1, 2026

Looks good. Thank you!

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.

PIL.Image.getdata() is deprecated

2 participants