{"id":19866138,"url":"https://github.com/tlux/tint","last_synced_at":"2025-07-15T15:43:23.715Z","repository":{"id":57556205,"uuid":"208311519","full_name":"tlux/tint","owner":"tlux","description":"An Elixir library to work with colors, convert between different colorspaces and calculate color distances.","archived":false,"fork":false,"pushed_at":"2025-02-03T10:28:57.000Z","size":185,"stargazers_count":11,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-19T10:28:57.294Z","etag":null,"topics":["ciede2000","cielab","cmyk","color","color-conversion","color-converter","color-distance","colorspaces","complementary-colors","convert-colors","elixir-library","euclidean-distances","hex","hex-codes","hsv","rgb","rgb-colors"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tlux.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-09-13T17:15:34.000Z","updated_at":"2025-02-03T10:29:00.000Z","dependencies_parsed_at":"2024-07-12T11:14:44.175Z","dependency_job_id":"a36e4ab8-c7c4-441a-a1a8-51347675f0eb","html_url":"https://github.com/tlux/tint","commit_stats":{"total_commits":72,"total_committers":1,"mean_commits":72.0,"dds":0.0,"last_synced_commit":"742b3cc8ffd5e90bc78fe0413286af8ec593298c"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/tlux/tint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Ftint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Ftint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Ftint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Ftint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tlux","download_url":"https://codeload.github.com/tlux/tint/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlux%2Ftint/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265443558,"owners_count":23766417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ciede2000","cielab","cmyk","color","color-conversion","color-converter","color-distance","colorspaces","complementary-colors","convert-colors","elixir-library","euclidean-distances","hex","hex-codes","hsv","rgb","rgb-colors"],"created_at":"2024-11-12T15:25:04.950Z","updated_at":"2025-07-15T15:43:23.706Z","avatar_url":"https://github.com/tlux.png","language":"Elixir","readme":"# Tint\n\n[![Build](https://github.com/tlux/tint/actions/workflows/elixir.yml/badge.svg)](https://github.com/tlux/tint/actions/workflows/elixir.yml)\n[![Coverage Status](https://coveralls.io/repos/github/tlux/tint/badge.svg?branch=main)](https://coveralls.io/github/tlux/tint?branch=main)\n[![Module Version](https://img.shields.io/hexpm/v/tint.svg)](https://hex.pm/packages/tint)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/tint/)\n[![License](https://img.shields.io/hexpm/l/tint.svg)](https://github.com/tlux/tint/blob/main/LICENSE.md)\n[![Last Updated](https://img.shields.io/github/last-commit/tlux/tint.svg)](https://github.com/tlux/tint/commits/main)\n\nAn Elixir library allowing calculations with colors and conversions between\ndifferent colorspaces.\n\nCurrently supports the following color models:\n\n- [RGB](https://en.wikipedia.org/wiki/RGB_color_space)\n- [CMYK](https://en.wikipedia.org/wiki/CMYK_color_model)\n- [HSV](https://en.wikipedia.org/wiki/HSL_and_HSV)\n- L\\*a\\*b\\* ([CIELAB](https://en.wikipedia.org/wiki/CIELAB_color_space))\n- XYZ ([CIE 1931](https://en.wikipedia.org/wiki/CIE_1931_color_space))\n- [DIN99](https://de.wikipedia.org/wiki/DIN99-Farbraum)\n\n## Prerequisites\n\n- Elixir 1.14 or greater\n\n## Installation\n\nThe package can be installed by adding `tint` to your list of dependencies in\n`mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:tint, \"~\u003e 1.3\"}\n  ]\nend\n```\n\n## Usage\n\n### Colorspaces\n\n#### RGB\n\n```elixir\niex\u003e Tint.RGB.new(255, 0, 0)\n#Tint.RGB\u003c255,0,0 (#FF0000)\u003e\n```\n\nor\n\n```elixir\niex\u003e import Tint.Sigil\n...\u003e ~K[255, 0, 0]r\n#Tint.RGB\u003c255,0,0 (#FF0000)\u003e\n```\n\nUsing hex codes:\n\n```elixir\niex\u003e Tint.RGB.from_hex(\"#FF0000\")\n{:ok, #Tint.RGB\u003c255,0,0 (#FF0000)\u003e}\n\niex\u003e Tint.RGB.from_hex(\"#F00\")\n{:ok, #Tint.RGB\u003c255,0,0 (#FF0000)\u003e}\n\niex\u003e Tint.RGB.from_hex(\"FF0000\")\n{:ok, #Tint.RGB\u003c255,0,0 (#FF0000)\u003e}\n\niex\u003e Tint.RGB.from_hex!(\"F00\")\n#Tint.RGB\u003c255,0,0 (#FF0000)\u003e\n\niex\u003e Tint.RGB.from_hex(\"invalid\")\n:error\n\niex\u003e Tint.RGB.from_hex!(\"invalid\")\n** (ArgumentError) Invalid hex code: invalid\n```\n\nor\n\n```elixir\niex\u003e import Tint.Sigil\n...\u003e ~K[#FF0000]\n#Tint.RGB\u003c255,0,0 (#FF0000)\u003e\n```\n\nTo convert RGB colors back to hex codes:\n\n```elixir\niex\u003e color = Tint.RGB.new(255, 0, 0)\n...\u003e Tint.RGB.to_hex(color)\n\"#FF0000\"\n```\n\n#### CMYK\n\n```elixir\niex\u003e Tint.CMYK.new(0.55, 0.26, 0.24, 0.65)\n#Tint.CMYK\u003c55%,26%,24%,65%\u003e\n```\n\nor\n\n```elixir\niex\u003e import Tint.Sigil\n...\u003e ~K[0.55, 0.26, 0.24, 0.65]c\n#Tint.CMYK\u003c55%,26%,24%,65%\u003e\n```\n\n#### HSV\n\n```elixir\niex\u003e Tint.HSV.new(25.8, 0.882, 1)\n#Tint.HSV\u003c25.8°,88.2%,100%\u003e\n```\n\nor\n\n```elixir\niex\u003e import Tint.Sigil\n...\u003e ~K[25.8, 0.882, 1]h\n#Tint.HSV\u003c25.8°,88.2%,100%\u003e\n```\n\n#### CIELAB\n\n```elixir\niex\u003e Tint.Lab.new(53.2329, 80.1068, 67.2202)\n#Tint.Lab\u003c53.2329,80.1068,67.2202\u003e\n```\n\nor\n\n```elixir\niex\u003e import Tint.Sigil\n...\u003e ~K[53.2329, 80.1068, 67.2202]c\n#Tint.Lab\u003c53.2329,80.1068,67.2202\u003e\n```\n\n#### DIN99\n\n```elixir\niex\u003e Tint.DIN99.new(53.2329, 80.1068, 67.2202)\n#Tint.DIN99\u003c53.2329,80.1068,67.2202\u003e\n```\n\nor\n\n```elixir\niex\u003e import Tint.Sigil\n...\u003e ~K[53.2329, 80.1068, 67.2202]d\n#Tint.DIN99\u003c53.2329,80.1068,67.2202\u003e\n```\n\n### Conversion\n\n```elixir\niex\u003e rgb = Tint.RGB.new(255, 0, 0)\n...\u003e Tint.to_hsv(rgb)\n#Tint.HSV\u003c0°,100%,100%\u003e\n```\n\nThe complete list:\n\n```elixir\nTint.to_cmyk(color)\nTint.to_din99(color)\nTint.to_hsv(color)\nTint.to_lab(color)\nTint.to_rgb(color)\nTint.to_xyz(color)\n```\n\nAlternatively you can use `convert/2` and `convert!/2`:\n\n```elixir\nTint.convert(color, :rgb)\nTint.convert(color, Tint.RGB)\nTint.convert!(color, :hsv)\n```\n\nCurrently, only RGB can be converted to any other colorspace.\n\n### Color Distance\n\nThere are a couple of functions to calculate the distance between two colors.\n\n#### Euclidean Distance\n\nThe\n[Euclidean distance](https://en.wikipedia.org/wiki/Color_difference#Euclidean)\ncan be calculated on RGB colors. Calculating the Euclidean distance is very fast\nbut may not be very precise. If you want maximum precision use the CIEDE2000\nalgorithm.\n\n```elixir\niex\u003e Tint.RGB.euclidean_distance(~K[#FFFFFF], ~K[#000000])\n441.6729559300637\n```\n\nYou can also define weights for the individual red, green and blue color\nchannels:\n\n```elixir\niex\u003e Tint.RGB.euclidean_distance(~K[#FFFFFF], ~K[#000000], weights: {2, 4, 3})\n765.0\n```\n\nTo find the nearest color from a given palette:\n\n```elixir\niex\u003e Tint.RGB.nearest_color(~K[#CC0000], [~K[#009900], ~K[#FF0000]])\n#Tint.RGB\u003c255,0,0 (#FF0000)\u003e\n```\n\n#### CIEDE2000\n\n[CIEDE2000](https://en.wikipedia.org/wiki/Color_difference#CIEDE2000) is an\nalgorithm that operates on the CIELAB colorspace. It is very slow compared to\nthe Euclidean distance algorithm but it is optimized to human color perception.\n\n```elixir\niex\u003e Tint.Lab.ciede2000_distance(~K[#FF0000], ~K[#000000])\n50.3905024704449\n```\n\nTo find the nearest color from a given palette:\n\n```elixir\niex\u003e Tint.Lab.nearest_color(~K[#FF0000], [~K[#009900], ~K[#CC0000]])\n#Tint.RGB\u003c204,0,0 (#CC0000)\u003e\n```\n\n### Complementary Color\n\n```elixir\niex\u003e Tint.RGB.complementary_color(~K[#FF0000])\n#Tint.RGB\u003c0,255,255 (#00FFFF)\u003e\n```\n\n## Docs\n\nThe API docs can be found at [HexDocs](https://hexdocs.pm/tint).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlux%2Ftint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftlux%2Ftint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlux%2Ftint/lists"}