repo_description: Self-hosted collection of powerful web-based tools for everyday tasks. No ads, no tracking, just fast, accessible utilities right from your browser!
repo_topics: alternative converter data-manipulation developer-tools devtools frontend good-first-issue image-manipulation image-processing javascript pdf-manipulation productivity react self-hosted swissarmyknife tools typescript video-manipulation webapp website
code: export function areColorsSimilar(
    color1: [number, number, number],
    color2: [number, number, number],
    similarity: number
  ): boolean {
    const colorDistance = (
      c1: [number, number, number],
      c2: [number, number, number]
    ) => {
      return Math.sqrt(
        Math.pow(c1[0] - c2[0], 2) +
          Math.pow(c1[1] - c2[1], 2) +
          Math.pow(c1[2] - c2[2], 2)
      );
    };
    const maxColorDistance = Math.sqrt(
      Math.pow(255, 2) + Math.pow(255, 2) + Math.pow(255, 2)
    );
    const similarityThreshold = (similarity / 100) * maxColorDistance;
  
    return colorDistance(color1, color2) <= similarityThreshold;
  }
  
  export function convertHexToRGBA(color: string): number {
    // Remove the leading '#' if present
    if (color.startsWith('#')) {
      color = color.slice(1);
    }
  
    // Convert the color to a number and add the alpha channel
    const colorValue = parseInt(color, 16);
    const alphaChannel = 0xff;
    return (colorValue << 8) | alphaChannel;
  }
  