Advertisement
Guest User

Untitled

a guest
Jan 14th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. from core.lib.png import Reader, Writer, write_chunks
  2. import pickle
  3. import sys
  4. from core.appfw.transforms import *
  5.  
  6. filename = r"C:\path\to\image.png"
  7. r = Reader(filename=filename)
  8.  
  9.  
  10. #newChunk = ('tEXt',pickle.dumps([[Attributes.TYPE_SEARCH_PREV, {'value':Attributes.SPACIAL_ABOVE, 'proximity':50}]\
  11. #                                    ]))
  12.  
  13. #newChunk = ('tEXt',pickle.dumps([[Attributes.SIMILARITY, {'value':1.0}]]))
  14.  
  15.  
  16. transforms = {
  17.                 Transforms.CONTEXT_PREVIOUS: [ \
  18.                     RegionNearby(10),
  19.                                               ], \
  20.                 Transforms.CONTEXT_CURRENT: [ \
  21.                    PatternSimilarity(0.75),
  22. #                    PatternTargetOffset(0,-10)
  23.                                              ], \
  24.                 Transforms.CONTEXT_NEXT: [ \
  25. #                    RegionBelow(200),
  26. #                    RegionLeft()
  27. #                    RegionNearby(10)
  28.                                           ] \
  29.               }
  30.  
  31. newChunk = ('tEXt',pickle.dumps(transforms))
  32.  
  33.  
  34. found = False
  35. chunks = []
  36. for chunk in r.chunks():
  37.        
  38.     print chunk
  39.     if chunk[0] == 'tEXt':
  40.         #print 'here', chunk
  41.         chunk = newChunk
  42.         found = True
  43.     elif chunk[0] == 'IEND':
  44.         if not found:
  45.             chunks.append(newChunk)
  46.            
  47.     chunks.append(chunk)
  48.  
  49.  
  50. f=open(filename, 'wb')
  51. write_chunks(f, chunks)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement