Python Forum
Run a timer when a functions starts to see how long the function takes to complete
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run a timer when a functions starts to see how long the function takes to complete
#1
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.

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')
Reply


Messages In This Thread
Run a timer when a functions starts to see how long the function takes to complete - by Pedroski55 - Apr-19-2020, 02:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  using threading.Timer for function korenron 1 1,159 Dec-20-2022, 01:09 PM
Last Post: ndc85430
  Move column to the right if it starts with a letter mfernandes 0 650 Oct-25-2022, 11:22 AM
Last Post: mfernandes
  Setup Portable Python on Windows for script starts with double clicks? pstein 0 1,778 Feb-18-2022, 01:29 PM
Last Post: pstein
  Checking the number of arguments a function takes Chirumer 3 2,113 Jul-06-2021, 04:56 PM
Last Post: Chirumer
  Regex: a string does not starts and ends with the same character Melcu54 5 2,369 Jul-04-2021, 07:51 PM
Last Post: Melcu54
  email timer/rss feed timer ndiniz 1 2,045 Feb-02-2021, 07:18 PM
Last Post: nilamo
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,199 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  Code starts slowing down? MemoryError AshkanDev 1 2,118 May-19-2020, 11:38 PM
Last Post: AshkanDev
  Upload takes too long. Makada 29 7,359 Apr-06-2020, 08:06 PM
Last Post: Makada
  Need help with a function that calls other functions. skurrtboi 4 2,460 Sep-30-2019, 09:28 PM
Last Post: stullis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020