Skip to content

fix: use :background_color key in embed adjust_transparency#209

Open
hlindset wants to merge 1 commit into
elixir-image:mainfrom
hlindset:fix/embed-background-color-key
Open

fix: use :background_color key in embed adjust_transparency#209
hlindset wants to merge 1 commit into
elixir-image:mainfrom
hlindset:fix/embed-background-color-key

Conversation

@hlindset

@hlindset hlindset commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Fixed a KeyError in adjust_transparency/3. It tried to read options.background instead of options.background_color. The bug only triggered on Image.embed/4 with extend_mode: :background on images with an alpha band, and 1-band images.

P.S. It looks like there's a dead branch in there, because Pixel.to_pixel always pads background_color to the image's full band count before adjust_transparency sees it, so length == bands is always true. Not fixed in this PR.

if length(options.background) == bands do
options
else
options
|> Map.put(
:background_color,
List.insert_at(options.background, -1, options.background_transparency)
)
end

(code from current main, so the key isn't fixed in the snippet)

Would it make sense to merge background_color and background_transparency into a single Image.Pixel-backed background option, so the alpha rides on the color and the reconcile logic goes away? It should be possible to keep the color/transparency pair as a deprecated alternative that folds into the single key.

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