Apr-19-2020, 02:51 AM
I made a little Python to remove watermarks from pdfs. It works OK.
After splitting the pdf into jpgs, I look for grey pixels and paint them white.
I just changed it to take the lowest grey range as a variable.
The smaller the variable lowestGrey = int(Grey), and of course, the greater the number of pixels, the longer the function takes to complete.
Also, it's a trade-off: the Chinese characters in the pdf contain grey pixels too. If lowestGrey is too small, the characters get very scruffy.
Just out of interest, I'd like to time the function.
How can I set a timer? The timer should start when the function is called and print its result when the function is done.
After splitting the pdf into jpgs, I look for grey pixels and paint them white.
I just changed it to take the lowest grey range as a variable.
The smaller the variable lowestGrey = int(Grey), and of course, the greater the number of pixels, the longer the function takes to complete.
Also, it's a trade-off: the Chinese characters in the pdf contain grey pixels too. If lowestGrey is too small, the characters get very scruffy.
Just out of interest, I'd like to time the function.
How can I set a timer? The timer should start when the function is called and print its result when the function is done.
def removeWM(path, aJPG, grey): picture = Image.open(path + aJPG) saveas = aJPG.split('.') savename = saveas[0] + 'WMgone.jpg' width, height = picture.size for x in range(0, width): for y in range(0, height): r,g,b = picture.getpixel( (x,y) ) if r and g and b in range(grey, 253): picture.putpixel( (x,y), (255, 255, 255)) # white is 3 x 255 picture.save(pathToWMgone + savename) print(aJPG + ' watermark gone and saved')