Skip to content

Image.write/3: accept :average or Pixel.t() as :background#206

Open
hlindset wants to merge 1 commit into
elixir-image:mainfrom
hlindset:feat/write-background-color-resolution
Open

Image.write/3: accept :average or Pixel.t() as :background#206
hlindset wants to merge 1 commit into
elixir-image:mainfrom
hlindset:feat/write-background-color-resolution

Conversation

@hlindset

@hlindset hlindset commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This PR makes it possible to set Image.write/3's :background option to :average or Pixel.t().

The original :background handling for Image.write/3 just guarded is_pixel, and then pushed the raw value into vix, causing protocol Enumerable not implemented for ... for anything other than numeric lists.

defp validate_option({:background, background}, options, _image_type) when is_pixel(background) do
{:cont, options}
end

Open questions:

  • Adding :average/to_pixel required threading the image through all validation functions, so all function heads had to be updated. If you'd prefer I could do it in a resolve/validate step after the main validation has completed.
  • I added Image.Options.Write.invalid_option/1 for errors not bound to a specific image type, but the return type of that is %Image.Error{}, not binary() like Image.Options.Write.invalid_option/2. Is that ok, or should I switch both to either %Image.Error{} or binary()?

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