Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- # shelves_norja
- // $image = [
- // # image | width | height | x | y | color | blendmode
- // ['img/shelves_norja_64_sd_0_0.png', 47, 23, 18, 11, null, null],
- // ['img/shelves_norja_64_a_0_0.png', 49, 111, 22, 101, null, null],
- // ['img/shelves_norja_64_b_0_0.png', 44, 78, 21, 84, 'E14218', null],
- // ];
- # rare_dragonlamp
- /*$image = [
- # image | width | height | x | y | color | blendmode
- ['img/rare_dragonlamp_64_sd_4_0.png', 62, 20, 29, 3, null, null],
- ['img/rare_dragonlamp_64_a_4_0.png', 60, 29, 28, 13, null, null],
- ['img/rare_dragonlamp_64_b_4_0.png', 42, 36, 18, 35, 'FFBC00', null],
- ['img/rare_dragonlamp_64_c_4_1.png', 24, 36, 8, 69, 'FFBC00', null],
- ['img/rare_dragonlamp_64_d_4_0.png', 40, 33, 17, 34, null, 'ADD'],
- ['img/rare_dragonlamp_64_e_4_1.png', 22, 35, 7, 68, null, 'ADD'],
- ['img/rare_dragonlamp_64_f_4_1.png', 19, 41, 3, 96, null, null],
- ['img/rare_dragonlamp_64_g_4_1.png', 58, 72, 25, 114, null, 'ADD'],
- ];*/
- # urban_lamp
- $image = [
- # image | width | height | x | y | color | blendmode
- ['img/1_urban_lamp_urban_lamp_64_sd_0_0.png', 27, 13, 13, 4, null, null],
- ['img/14_urban_lamp_urban_lamp_64_a_2_0.png', 76, 189, 10, 184, null, null],
- ['img/12_urban_lamp_urban_lamp_64_b_2_1.png', 219, 266, 57, 168, null, 'ADD']
- ];
- # pastel_c19_bed
- // $image = [
- // # image | width | height | x | y | color | blendmode
- // ['img/pastel_c19_bed_64_sd_2_0.png', 160, 81, 64, 16, null, null],
- // ['img/pastel_c19_bed_64_a_2_0.png', 64, 59, 30, 73, null, null],
- // ['img/pastel_c19_bed_64_b_2_0.png', 132, 75, 64, 53, null, null],
- // ['img/pastel_c19_bed_64_c_2_0.png', 128, 53, 31, 15, null, null],
- // ['img/pastel_c19_bed_64_d_2_0.png', 64, 61, -1, -3, null, null],
- // ];
- /**
- * Convert hex color to rgb color.
- *
- * @param string $hex
- * @return array
- */
- function hex2rgb(string $hex): array
- {
- $color = str_split($hex, 2);
- return [
- hexdec($color[0]),
- hexdec($color[1]),
- hexdec($color[2]),
- ];
- }
- $canvas = imagecreatetruecolor(500, 500);
- imagealphablending($canvas, true);
- imagesavealpha($canvas, true);
- imagefill($canvas, 0, 0, imagecolorallocatealpha($canvas, 145, 147, 158, 0));
- imagecolortransparent($canvas, imagecolorat($canvas, 0, 0));
- foreach ($image as $value) {
- $im = imagecreatefrompng($value[0]);
- # handle shadow
- if (stristr($value[0], '_64_sd_')) {
- imagealphablending($im, false);
- imagesavealpha($im, true);
- imagefilter($im, IMG_FILTER_COLORIZE, 0, 0, 0, 127*0.8); # find exact transparency
- }
- # handle color
- if (null !== $value[5]) {
- $color = hex2rgb($value[5]);
- for ($x = 0; $x < $value[1]; $x++) {
- for ($y = 0; $y < $value[2]; $y++) {
- $srcColor = imagecolorsforindex($im, imagecolorat($im, $x, $y));
- # multiply
- $r = ($srcColor['red'] * $color[0]) / 255;
- $g = ($srcColor['green'] * $color[1]) / 255;
- $b = ($srcColor['blue'] * $color[2]) / 255;
- imagesetpixel($im, $x, $y, imagecolorallocatealpha($im, $r, $g, $b, $srcColor['alpha']));
- }
- }
- }
- $posX = (500 / 2) - $value[3];
- $posY = (500 / 2) - $value[4];
- # handle blendmode
- if (null !== $value[6]) {
- for ($x = 0; $x < $value[1]; $x++) {
- for ($y = 0; $y < $value[2]; $y++) {
- $dstColor = imagecolorsforindex($canvas, imagecolorat($canvas, $x + $posX, $y + $posY));
- $srcColor = imagecolorsforindex($im, imagecolorat($im, $x, $y));
- # addition
- $r = $dstColor['red'] + $srcColor['red'] - ($dstColor['red'] * $srcColor['red']) / 255;
- $g = $dstColor['green'] + $srcColor['green'] - ($dstColor['green'] * $srcColor['green']) / 255;
- $b = $dstColor['blue'] + $srcColor['blue'] - ($dstColor['blue'] * $srcColor['blue']) / 255;
- $a = $dstColor['alpha'];
- imagesetpixel($canvas, $x + $posX, $y + $posY, imagecolorallocatealpha($im, $r, $g, $b, $a));
- }
- }
- } else {
- imagecopy($canvas, $im, $posX, $posY, 0, 0, $value[1], $value[2]);
- }
- imagedestroy($im);
- }
- imagepng($canvas, 'result.png');
- imagedestroy($canvas);
- echo '<img src="result.png">';
Advertisement
Add Comment
Please, Sign In to add comment