Last active
August 29, 2015 14:23
-
-
Save AurelienLavorel/45f521ab8496f4badfff to your computer and use it in GitHub Desktop.
Generate Switch Images for Magento
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
<?php | |
/** | |
* Generate Switch Images for Magento | |
* cp out/* media/wysiwyg/swatches | |
*/ | |
$x = 21; | |
$y = 21; | |
$colors = array( | |
'Lemon yellow' => '#FFE500', | |
'Sunflower yellow' => '#FFAE00', | |
'Orange' => '#F86A00', | |
'Red' => '#D9161A', | |
'Medium red' => '#AD0019', | |
'Burgundy' => '#7B1E22', | |
'Magnolia' => '#A52E5F', | |
'Dahlia pink' => '#FEA096', | |
'Antique violet' => '#B09086', | |
'Bishop purple' => '#5B4866', | |
'Light blue' => '#62AABD', | |
'Sky blue' => '#0090B9', | |
'medium blue' => '#186CA7', | |
'Royal blue' => '#333572', | |
'Blue grey' => '#44515C', | |
'Pastel turquoise' => '#668779', | |
'Lagoon blue' => '#A7C6AD', | |
'Green yellow' => '#DAE043', | |
'Spring Green' => '#23A01B', | |
'Pesto' => '#647946', | |
'Oasis' => '#A9A042', | |
'Dark Green' => '#005332', | |
'Bahamas bue' => '#005E62', | |
'Turquoise blue' => '#00918F', | |
'Water Lily' => '#B2D574', | |
'Beige' => '#F2CE8F', | |
'Mocha' => '#BA9668', | |
'Silk grey' => '#AE9A75', | |
'Sepia brown' => '#5A4533', | |
'Chocolate brown' => '#5F412A', | |
'Pearl grey' => '#CDC2A5', | |
'Medium grey' => '#9F9680', | |
'Graphite' => '#605E52', | |
'Black' => '#000000', | |
'Blanc antique' => '#F6E1B8', | |
'Blanc' => '#ffffff', | |
'Silver' => '#A49C89', | |
'Gold' => '#A3894B' | |
); | |
/** | |
* Make color from hexa | |
* | |
* @param $im image | |
* @param $hex hexa | |
* | |
* @return int | |
*/ | |
function hexColorAllocate($im, $hex) { | |
$hex = ltrim($hex, '#'); | |
$a = hexdec(substr($hex, 0, 2)); | |
$b = hexdec(substr($hex, 2, 2)); | |
$c = hexdec(substr($hex, 4, 2)); | |
return imagecolorallocate($im, $a, $b, $c); | |
} | |
/** | |
* Make Name Magento Switch friendly | |
* | |
* @param $color | |
* | |
* @return string | |
*/ | |
function makeName($color) { | |
$carac = array( | |
'À' => 'a', 'Á' => 'a', 'Â' => 'a', 'Ä' => 'a', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ä' => 'a', '@' => 'a', | |
'È' => 'e', 'É' => 'e', 'Ê' => 'e', 'Ë' => 'e', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', '€' => 'e', | |
'Ì' => 'i', 'Í' => 'i', 'Î' => 'i', 'Ï' => 'i', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', | |
'Ò' => 'o', 'Ó' => 'o', 'Ô' => 'o', 'Ö' => 'o', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'ö' => 'o', | |
'Ù' => 'u', 'Ú' => 'u', 'Û' => 'u', 'Ü' => 'u', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'µ' => 'u', | |
'Œ' => 'oe', 'œ' => 'oe', | |
'$' => 's'); | |
$str = strtr($color, $carac); | |
$str = preg_replace('#[^A-Za-z0-9]+#', '-', $str); | |
return strtolower($str); | |
} | |
// Work | |
foreach ($colors as $color => $hexa) { | |
$img = imagecreatetruecolor($x, $y); | |
imagefill($img, 0, 0, $color); | |
imagepng($img, 'out/' . makeName($color) . '.png'); | |
imagedestroy($img); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment