Added support for unpng
This commit is contained in:
		
							parent
							
								
									409dcfac31
								
							
						
					
					
						commit
						e4d2cb3ea0
					
				
					 2 changed files with 28 additions and 4 deletions
				
			
		
							
								
								
									
										11
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								README.md
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1 +1,10 @@
 | 
			
		|||
hello how are you doing toda
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
e ~/Desktop/projects/pnger :) shasum README.md 
 | 
			
		||||
96313bbb41092391c6df854d0bf6c9b7e1fe71fd  README.md
 | 
			
		||||
e ~/Desktop/projects/pnger :) python pnger.py -i README.md -o testing.png
 | 
			
		||||
e ~/Desktop/projects/pnger :) python pnger.py -i testing.png -o test.txt -u
 | 
			
		||||
e ~/Desktop/projects/pnger :) shasum test.txt 
 | 
			
		||||
96313bbb41092391c6df854d0bf6c9b7e1fe71fd  test.txt
 | 
			
		||||
e ~/Desktop/projects/pnger :) 
 | 
			
		||||
```
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										21
									
								
								pnger.py
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								pnger.py
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -10,16 +10,31 @@
 | 
			
		|||
import sys
 | 
			
		||||
import argparse
 | 
			
		||||
 | 
			
		||||
def pngit(infile, outfile):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def pngit(infile, outfile, nowrite=0):
 | 
			
		||||
	outcounter = 0
 | 
			
		||||
	with open(outfile, "wb") as theoutf:
 | 
			
		||||
        	theoutf.write("\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
 | 
			
		||||
		
 | 
			
		||||
		if nowrite == 0:
 | 
			
		||||
        		theoutf.write("\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
 | 
			
		||||
		
 | 
			
		||||
		with open(infile, "rb") as f:
 | 
			
		||||
		
 | 
			
		||||
			byte = f.read(1)
 | 
			
		||||
			while byte != "":
 | 
			
		||||
				theoutf.write(byte)	
 | 
			
		||||
		
 | 
			
		||||
				if outcounter >= nowrite:
 | 
			
		||||
					theoutf.write(byte)	
 | 
			
		||||
				else:
 | 
			
		||||
					outcounter+=1
 | 
			
		||||
				
 | 
			
		||||
				byte = f.read(1)
 | 
			
		||||
 | 
			
		||||
def unpngit(infile, outfile):
 | 
			
		||||
	pngit(infile, outfile, 8)
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
	parser = argparse.ArgumentParser(description='Process some integers.')
 | 
			
		||||
	parser.add_argument('-i', '--input', help='the input file you want to perform a png or unpng operation on.')
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue