Last active
December 16, 2024 19:48
-
-
Save phecdaDia/06501e9e5ddcf1697b9d1e278be59cf4 to your computer and use it in GitHub Desktop.
Changing image on click in discord.
This file contains hidden or 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
import matplotlib.pyplot as plt | |
# don't fucking ask me how this works | |
magic_header = """ | |
00 00 00 04 67 41 4D 41 00 00 27 10 4C 57 C2 4C | |
00 00 00 20 63 48 52 4D 00 00 87 0B 00 00 8C 0F | |
00 00 FD 51 00 00 81 40 00 00 7D 76 00 00 E9 90 | |
00 00 3C E5 00 00 19 CD 21 AE 5C 4A | |
00 00 00 DB 69 43 43 50 49 43 43 20 50 72 6F 66 | |
69 6C 65 00 00 28 CF 63 60 60 7C C0 00 04 4C 40 | |
9C 9B 57 52 14 E4 EE A4 10 11 19 A5 C0 7E 81 81 | |
11 08 C1 20 31 B9 B8 C0 37 D8 2D 84 01 27 F8 76 | |
0D A2 F6 B2 2E 03 E9 80 B3 BC A4 A0 04 48 7F 00 | |
62 91 A2 90 20 67 A0 9B 58 80 6C BE 74 08 5B 04 | |
C4 4E 82 B0 55 40 EC 22 A0 03 81 6C 13 90 FA 74 | |
08 DB 03 C4 4E 82 B0 63 40 EC E4 82 22 A0 99 8C | |
05 20 F3 53 52 8B 93 81 EC 06 20 3B 01 E4 37 88 | |
B5 9F 03 C1 6E 66 14 3B 93 5C 5A 54 06 75 0B 23 | |
17 90 20 C4 47 98 91 3F 9F 81 C1 E2 0B 03 03 F3 | |
04 84 58 D2 54 06 86 ED 6D 0C 0C 12 B7 11 62 2A | |
0B 19 18 F8 5B 19 18 B6 5D 2D 49 AD 28 41 F6 3C | |
C4 6D 60 C0 96 5F 00 0C 7D 06 6A 02 06 06 00 AF | |
CB 36 E4 87 53 EC 66 | |
""" | |
# clean up the header | |
magic_header = bytes(int(x, 16) for x in magic_header.strip().replace('\n', ' ').split(' ') if x) | |
header_injection_offset = 0x00000021 # PNG header and IHDR are fixed lengths | |
output_file = 'output.png' | |
busy_image = plt.imread('Wheres-waldo-wally-google-maps-380.png') | |
inj = plt.imread('kitty.png') | |
if inj.shape[0] > 600 or inj.shape[1] > 800: | |
print('Warning, shape too large, might not work on click!') | |
print(inj.shape) | |
# crop the busy image and turn down the brightness | |
busy_image = busy_image[:inj.shape[0], :inj.shape[1], :] | |
busy_image = busy_image * (0.5647059/busy_image.max()) | |
# inject the image | |
x = 4 | |
busy_image[::2, ::2, :3] = (1./x * inj[::2,::2,:3]) + (1-1./x) | |
plt.imsave(output_file,busy_image) | |
# inject the black magic voodoo header | |
image_data = open(output_file, 'rb').read() | |
image_data = image_data[:header_injection_offset] + magic_header + image_data[header_injection_offset:] | |
open(output_file, 'wb').write(image_data) |
Is there a way to do this with bigger images?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
forked it and added args cause why not lol