LizeCF

Untitled

Jun 28th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. <?php
  2.  
  3. # shelves_norja
  4. // $image = [
  5. // # image | width | height | x | y | color | blendmode
  6. // ['img/shelves_norja_64_sd_0_0.png', 47, 23, 18, 11, null, null],
  7. // ['img/shelves_norja_64_a_0_0.png', 49, 111, 22, 101, null, null],
  8. // ['img/shelves_norja_64_b_0_0.png', 44, 78, 21, 84, 'E14218', null],
  9. // ];
  10.  
  11. # rare_dragonlamp
  12. /*$image = [
  13. # image | width | height | x | y | color | blendmode
  14. ['img/rare_dragonlamp_64_sd_4_0.png', 62, 20, 29, 3, null, null],
  15. ['img/rare_dragonlamp_64_a_4_0.png', 60, 29, 28, 13, null, null],
  16. ['img/rare_dragonlamp_64_b_4_0.png', 42, 36, 18, 35, 'FFBC00', null],
  17. ['img/rare_dragonlamp_64_c_4_1.png', 24, 36, 8, 69, 'FFBC00', null],
  18. ['img/rare_dragonlamp_64_d_4_0.png', 40, 33, 17, 34, null, 'ADD'],
  19. ['img/rare_dragonlamp_64_e_4_1.png', 22, 35, 7, 68, null, 'ADD'],
  20. ['img/rare_dragonlamp_64_f_4_1.png', 19, 41, 3, 96, null, null],
  21. ['img/rare_dragonlamp_64_g_4_1.png', 58, 72, 25, 114, null, 'ADD'],
  22. ];*/
  23.  
  24. # urban_lamp
  25. $image = [
  26. # image | width | height | x | y | color | blendmode
  27. ['img/1_urban_lamp_urban_lamp_64_sd_0_0.png', 27, 13, 13, 4, null, null],
  28. ['img/14_urban_lamp_urban_lamp_64_a_2_0.png', 76, 189, 10, 184, null, null],
  29. ['img/12_urban_lamp_urban_lamp_64_b_2_1.png', 219, 266, 57, 168, null, 'ADD']
  30. ];
  31.  
  32. # pastel_c19_bed
  33. // $image = [
  34. // # image | width | height | x | y | color | blendmode
  35. // ['img/pastel_c19_bed_64_sd_2_0.png', 160, 81, 64, 16, null, null],
  36. // ['img/pastel_c19_bed_64_a_2_0.png', 64, 59, 30, 73, null, null],
  37. // ['img/pastel_c19_bed_64_b_2_0.png', 132, 75, 64, 53, null, null],
  38. // ['img/pastel_c19_bed_64_c_2_0.png', 128, 53, 31, 15, null, null],
  39. // ['img/pastel_c19_bed_64_d_2_0.png', 64, 61, -1, -3, null, null],
  40. // ];
  41.  
  42. /**
  43. * Convert hex color to rgb color.
  44. *
  45. * @param string $hex
  46. * @return array
  47. */
  48. function hex2rgb(string $hex): array
  49. {
  50. $color = str_split($hex, 2);
  51.  
  52. return [
  53. hexdec($color[0]),
  54. hexdec($color[1]),
  55. hexdec($color[2]),
  56. ];
  57. }
  58.  
  59. $canvas = imagecreatetruecolor(500, 500);
  60.  
  61. imagealphablending($canvas, true);
  62. imagesavealpha($canvas, true);
  63. imagefill($canvas, 0, 0, imagecolorallocatealpha($canvas, 145, 147, 158, 0));
  64. imagecolortransparent($canvas, imagecolorat($canvas, 0, 0));
  65.  
  66. foreach ($image as $value) {
  67. $im = imagecreatefrompng($value[0]);
  68.  
  69. # handle shadow
  70. if (stristr($value[0], '_64_sd_')) {
  71. imagealphablending($im, false);
  72. imagesavealpha($im, true);
  73. imagefilter($im, IMG_FILTER_COLORIZE, 0, 0, 0, 127*0.8); # find exact transparency
  74. }
  75.  
  76. # handle color
  77. if (null !== $value[5]) {
  78. $color = hex2rgb($value[5]);
  79.  
  80. for ($x = 0; $x < $value[1]; $x++) {
  81. for ($y = 0; $y < $value[2]; $y++) {
  82. $srcColor = imagecolorsforindex($im, imagecolorat($im, $x, $y));
  83.  
  84. # multiply
  85. $r = ($srcColor['red'] * $color[0]) / 255;
  86. $g = ($srcColor['green'] * $color[1]) / 255;
  87. $b = ($srcColor['blue'] * $color[2]) / 255;
  88.  
  89. imagesetpixel($im, $x, $y, imagecolorallocatealpha($im, $r, $g, $b, $srcColor['alpha']));
  90. }
  91. }
  92. }
  93.  
  94. $posX = (500 / 2) - $value[3];
  95. $posY = (500 / 2) - $value[4];
  96.  
  97. # handle blendmode
  98. if (null !== $value[6]) {
  99. for ($x = 0; $x < $value[1]; $x++) {
  100. for ($y = 0; $y < $value[2]; $y++) {
  101. $dstColor = imagecolorsforindex($canvas, imagecolorat($canvas, $x + $posX, $y + $posY));
  102. $srcColor = imagecolorsforindex($im, imagecolorat($im, $x, $y));
  103.  
  104. # addition
  105. $r = $dstColor['red'] + $srcColor['red'] - ($dstColor['red'] * $srcColor['red']) / 255;
  106. $g = $dstColor['green'] + $srcColor['green'] - ($dstColor['green'] * $srcColor['green']) / 255;
  107. $b = $dstColor['blue'] + $srcColor['blue'] - ($dstColor['blue'] * $srcColor['blue']) / 255;
  108. $a = $dstColor['alpha'];
  109.  
  110. imagesetpixel($canvas, $x + $posX, $y + $posY, imagecolorallocatealpha($im, $r, $g, $b, $a));
  111. }
  112. }
  113. } else {
  114. imagecopy($canvas, $im, $posX, $posY, 0, 0, $value[1], $value[2]);
  115. }
  116. imagedestroy($im);
  117. }
  118. imagepng($canvas, 'result.png');
  119. imagedestroy($canvas);
  120.  
  121. echo '<img src="result.png">';
Advertisement
Add Comment
Please, Sign In to add comment