Last active
March 6, 2016 20:19
-
-
Save mikebronner/57c4440ad76025e7435e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$palette = imagecreatefrompng(public_path() . "/assets/palette.png"); | |
$metalsPalette = imagecreatefrompng(public_path() . "/assets/metalsPalette.png"); | |
$colorsPalette = imagecreatefrompng(public_path() . "/assets/colorsPalette.png"); | |
$basesPalette = imagecreatefrompng(public_path() . "/assets/basesPalette.png"); | |
$original1 = imagecreatefrompng(public_path() . '/uploads/test1.png'); | |
$original2 = imagecreatefrompng(public_path() . '/uploads/test2.png'); | |
$resampled1 = imagecreatetruecolor(5, 5); | |
$resampled2 = imagecreatetruecolor(5, 5); | |
$adjusted1 = imagecreatetruecolor(5, 5); | |
$adjusted2 = imagecreatetruecolor(5, 5); | |
$difference = imagecreatetruecolor(5, 5); | |
$significantDifference = imagecreatetruecolor(5, 5); | |
imagetruecolortopalette($palette, false, 16); | |
imagetruecolortopalette($metalsPalette, false, 3); | |
imagetruecolortopalette($colorsPalette, false, 6); | |
imagetruecolortopalette($basesPalette, false, 6); | |
imagecopyresampled($resampled1, $original1, 0, 0, 0, 0, 5, 5, imagesx($original1), imagesy($original1)); | |
imagecopyresampled($resampled2, $original2, 0, 0, 0, 0, 5, 5, imagesx($original2), imagesy($original2)); | |
$differenceCount = 0; | |
$significantDifferenceCount = 0; | |
for ($row = 0; $row < 5; $row++) { | |
for ($column = 0; $column < 5; $column++) { | |
$rgb1 = imagecolorat($resampled1, $column, $row); | |
$rgb2 = imagecolorat($resampled2, $column, $row); | |
$color1 = imagecolorsforindex($resampled1, $rgb1); | |
$color2 = imagecolorsforindex($resampled2, $rgb2); | |
$closestRgb1 = imagecolorclosest($palette, $color1['red'], $color1['green'], $color1['blue']); | |
$closestRgb2 = imagecolorclosest($palette, $color2['red'], $color2['green'], $color2['blue']); | |
$closestColor1 = imagecolorsforindex($palette, $closestRgb1); | |
$closestColor2 = imagecolorsforindex($palette, $closestRgb2); | |
imagesetpixel($adjusted1, $column, $row, imagecolorallocate($adjusted1, $closestColor1['red'], $closestColor1['green'], $closestColor1['blue'])); | |
imagesetpixel($adjusted2, $column, $row, imagecolorallocate($adjusted2, $closestColor2['red'], $closestColor2['green'], $closestColor2['blue'])); | |
if (imagecolorat($adjusted1, $column, $row) != imagecolorat($adjusted2, $column, $row)) { | |
imagesetpixel($difference, $column, $row, imagecolorallocate($difference, 255, 0, 0)); | |
$differenceCount++; | |
} | |
if ((imagecolorexact($basesPalette, $closestColor1['red'], $closestColor1['green'], $closestColor1['blue']) > -1) && | |
(imagecolorexact($basesPalette, $closestColor2['red'], $closestColor2['green'], $closestColor2['blue']) > -1)) { | |
// no significant difference | |
} elseif ((imagecolorexact($colorsPalette, $closestColor1['red'], $closestColor1['green'], $closestColor1['blue']) > -1) && | |
(imagecolorexact($colorsPalette, $closestColor2['red'], $closestColor2['green'], $closestColor2['blue']) > -1)) { | |
// no significant difference | |
} elseif ((imagecolorexact($metalsPalette, $closestColor1['red'], $closestColor1['green'], $closestColor1['blue']) > -1) && | |
(imagecolorexact($metalsPalette, $closestColor2['red'], $closestColor2['green'], $closestColor2['blue']) > -1)) { | |
// no significant difference | |
} else { | |
imagesetpixel($significantDifference, $column, $row, imagecolorallocate($significantDifference, 255, 0, 0)); | |
$significantDifferenceCount++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment