Skip to content

Instantly share code, notes, and snippets.

@devnix
Forked from mailtruck/colormeter.js
Last active May 16, 2020 00:26
Show Gist options
  • Select an option

  • Save devnix/ed7953386814f023ea496f41209fd3cc to your computer and use it in GitHub Desktop.

Select an option

Save devnix/ed7953386814f023ea496f41209fd3cc to your computer and use it in GitHub Desktop.

Revisions

  1. devnix revised this gist Sep 23, 2016. No changes.
  2. devnix revised this gist Sep 23, 2016. 1 changed file with 0 additions and 13 deletions.
    13 changes: 0 additions & 13 deletions colormeter.php
    Original file line number Diff line number Diff line change
    @@ -27,16 +27,3 @@ function color_meter($cwith, $ccolor) {
    $perc2 = round(($p1 + $p2 + $p3) / 3);
    return abs($perc1 - $perc2);
    }

    $aqua = '#00FFFF';
    $aquamarine = ' #7FFFD4';
    $blue = '#0000FF';
    $brown = '#A52A2A';
    $red = '#FF0000';
    $darkred = '#8B0000';
    $green = '#008000';

    var_dump(['$aqua vs $aquamarine', color_meter($aqua, $aquamarine)]);
    var_dump(['$aqua vs $blue', color_meter($aqua, $blue)]);
    var_dump(['$aqua vs $brown', color_meter($aqua, $brown)]);

  3. Pablo Largo Mohedano revised this gist Sep 23, 2016. No changes.
  4. Pablo Largo Mohedano revised this gist Sep 23, 2016. 1 changed file with 37 additions and 24 deletions.
    61 changes: 37 additions & 24 deletions colormeter.php
    Original file line number Diff line number Diff line change
    @@ -1,29 +1,42 @@
    function color_meter(cwith, ccolor) {

    if (!cwith && !ccolor) return;

    var _cwith = (cwith.charAt(0)=="#") ? cwith.substring(1,7) : cwith;
    var _ccolor = (ccolor.charAt(0)=="#") ? ccolor.substring(1,7) : ccolor;

    var _r = parseInt(_cwith.substring(0,2), 16);
    var _g = parseInt(_cwith.substring(2,4), 16);
    var _b = parseInt(_cwith.substring(4,6), 16);
    <?php

    var __r = parseInt(_ccolor.substring(0,2), 16);
    var __g = parseInt(_ccolor.substring(2,4), 16);
    var __b = parseInt(_ccolor.substring(4,6), 16);
    function color_meter($cwith, $ccolor) {
    if (empty($cwith) || empty($ccolor)) return false;

    var p1 = (_r / 255) * 100;
    var p2 = (_g / 255) * 100;
    var p3 = (_b / 255) * 100;
    $_cwith = ($cwith[0] === '#') ? substr($cwith, 1, 7) : $cwith;
    $_ccolor = ($ccolor[0] === '#') ? substr($ccolor, 1, 7) : $ccolor;

    var perc1 = Math.round((p1 + p2 + p3) / 3);

    var p1 = (__r / 255) * 100;
    var p2 = (__g / 255) * 100;
    var p3 = (__b / 255) * 100;
    $_r = intval(substr($_cwith, 0, 2), 16);
    $_g = intval(substr($_cwith, 2, 2), 16);
    $_b = intval(substr($_cwith, 4, 2), 16);

    $__r = intval(substr($_ccolor, 0, 2), 16);
    $__g = intval(substr($_ccolor, 2, 2), 16);
    $__b = intval(substr($_ccolor, 4, 2), 16);

    $p1 = ($_r / 255) * 100;
    $p2 = ($_g / 255) * 100;
    $p3 = ($_b / 255) * 100;

    $perc1 = round(($p1 + $p2 + $p3) / 3);

    var perc2 = Math.round((p1 + p2 + p3) / 3);
    $p1 = ($__r / 255) * 100;
    $p2 = ($__g / 255) * 100;
    $p3 = ($__b / 255) * 100;

    return Math.abs(perc1 - perc2);
    }
    $perc2 = round(($p1 + $p2 + $p3) / 3);
    return abs($perc1 - $perc2);
    }

    $aqua = '#00FFFF';
    $aquamarine = ' #7FFFD4';
    $blue = '#0000FF';
    $brown = '#A52A2A';
    $red = '#FF0000';
    $darkred = '#8B0000';
    $green = '#008000';

    var_dump(['$aqua vs $aquamarine', color_meter($aqua, $aquamarine)]);
    var_dump(['$aqua vs $blue', color_meter($aqua, $blue)]);
    var_dump(['$aqua vs $brown', color_meter($aqua, $brown)]);

  5. devnix revised this gist Sep 23, 2016. No changes.
  6. Pablo Largo Mohedano renamed this gist Sep 23, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. Tiago Dias created this gist Apr 16, 2012.
    29 changes: 29 additions & 0 deletions colormeter.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    function color_meter(cwith, ccolor) {

    if (!cwith && !ccolor) return;

    var _cwith = (cwith.charAt(0)=="#") ? cwith.substring(1,7) : cwith;
    var _ccolor = (ccolor.charAt(0)=="#") ? ccolor.substring(1,7) : ccolor;

    var _r = parseInt(_cwith.substring(0,2), 16);
    var _g = parseInt(_cwith.substring(2,4), 16);
    var _b = parseInt(_cwith.substring(4,6), 16);

    var __r = parseInt(_ccolor.substring(0,2), 16);
    var __g = parseInt(_ccolor.substring(2,4), 16);
    var __b = parseInt(_ccolor.substring(4,6), 16);

    var p1 = (_r / 255) * 100;
    var p2 = (_g / 255) * 100;
    var p3 = (_b / 255) * 100;

    var perc1 = Math.round((p1 + p2 + p3) / 3);

    var p1 = (__r / 255) * 100;
    var p2 = (__g / 255) * 100;
    var p3 = (__b / 255) * 100;

    var perc2 = Math.round((p1 + p2 + p3) / 3);

    return Math.abs(perc1 - perc2);
    }