Guest User

Untitled

a guest
Feb 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. 19c19
  2. < import Image, ImageChops
  3. ---
  4. > import Image
  5. 32d31
  6. <
  7.  
  8. 57c56
  9. < thumbnailimage = Image.new ( "RGB", (boardObj.width, boardObj.height), (0,255,0) )
  10.  
  11. ---
  12. > # thumbnailimage = Image.new ( "RGB", (boardObj.width, boardObj.height), (0,255,0) )
  13.  
  14. 65,85c64,66
  15. < # Generate a Temporary HTML file
  16.  
  17. < tempFilePath = self.GetTextTempFilename(board.id, boardObj.zindex)
  18.  
  19. < tempHTML = self.TempTextGenerator(boardObj.text, 6);
  20.  
  21. < f = open(tempFilePath, 'w')
  22.  
  23. < f.write(tempHTML)
  24.  
  25. < f.close()
  26.  
  27. <
  28.  
  29. < # Call the ImageMagick
  30.  
  31. < tempCommand = self.MakeImageMagickCommand(tempFilePath, (tempFilePath + '.png'), '-trim -fuzz 12% -transparent white')
  32.  
  33. < result = os.popen(tempCommand)
  34.  
  35. <
  36.  
  37. < # Image Processing
  38.  
  39. < textThumb = Image.open (tempFilePath + '.png')
  40.  
  41. <
  42.  
  43. < # Generate Transparent mask
  44.  
  45. < mask = textThumb.convert("L")
  46.  
  47. < mask = ImageChops.invert(mask)
  48.  
  49. < thumbimage.paste(textThumb,(boardObj.posx, boardObj.posy),mask)
  50.  
  51. <
  52.  
  53. < del mask
  54.  
  55. < del textThumb
  56.  
  57. ---
  58. > textboximage = Image.new ( "RGB", (boardObj.width, boardObj.height), (255,0,0) )
  59.  
  60. > thumbimage.paste(textboximage,(boardObj.posx, boardObj.posy))
  61.  
  62. > del textboximage
  63.  
  64. 97c78
  65. < thumbimage.save (thumbimageFile,"PNG")
  66.  
  67. ---
  68. > thumbimage.save (thumbimageFile,"JPEG")
  69.  
  70. 99c80
  71. < thumbimage.save (iconimageFile,"PNG")
  72.  
  73. ---
  74. > thumbimage.save (iconimageFile,"JPEG")
  75.  
  76. 120,133d100
  77. <
  78.  
  79. < # Kit Addition
  80.  
  81. < def GetTextTempFilename (self, boardid, zindex ):
  82.  
  83. < tempHTMLFile= boardid + str(zindex) + "_texttemp.html"
  84.  
  85. < return os.path.join ( self.absDir, "uploadfile", tempHTMLFile )
  86.  
  87. <
  88.  
  89. < def MakeImageMagickCommand (self, srcFile, dstFile, parameter):
  90.  
  91. < return 'convert html:' + srcFile + ' ' + parameter + ' ' + dstFile
  92.  
  93. <
  94.  
  95. < def TempTextGenerator (self, textFromBoard, size):
  96.  
  97. < header = "<html><head><title>1</title></head><body>"
  98.  
  99. < footer = "</body></html>"
  100.  
  101. < return header + '<font size="' + str(size) + '">' + textFromBoard + '</font>' + footer
  102.  
  103. <
Add Comment
Please, Sign In to add comment