
from PIL import Image, ImageDraw, ImageFont
import sys


def add_num_to_img(file_path):
    im = Image.open(file_path)
    im_draw = ImageDraw.Draw(im)
    font = ImageFont.truetype("arial.ttf", int(im.size[0]/5))
    im_draw.text((int(im.size[0]-im.size[0]/10), 5), "4", (256, 0, 0), font=font)
    del im_draw
    im.save(file_path)

if __name__ == "__main__":
    if len(sys.argv) <= 1:
        print("Need at least 1 parameter. Try to execute 'python 0000.py $image_path'")
    else:
        for infile in sys.argv[1:]:
            try:
                add_num_to_img(infile)
                print("Success!")
            except IOError:
                print("Can't open image!")
                pass


from PIL import Image, ImageDraw, ImageFont
import sys


def add_num_to_img(file_path):
    im = Image.open(file_path)
    im_draw = ImageDraw.Draw(im)
    font = ImageFont.truetype("arial.ttf", int(im.size[0]/5))
    im_draw.text((int(im.size[0]-im.size[0]/10), 5), "4", (256, 0, 0), font=font)
    del im_draw
    im.save('./result.png')

if __name__ == "__main__":
    if len(sys.argv) <= 1:
        print("Need at least 1 parameter. Try to execute 'python 0000.py $image_path'")
    else:
        for infile in sys.argv[1:]:
            try:
                add_num_to_img(infile)
                print("Success!")
            except IOError:
                print("Can't open image!")
                pass


Rename the result image to avoid overwriting the original image
Rename the result image to avoid overwriting the original image

  
  from PIL import Image, ImageDraw, ImageFont
  import sys
  
  
  def add_num_to_img(file_path):
      im = Image.open(file_path)
      im_draw = ImageDraw.Draw(im)
      font = ImageFont.truetype("arial.ttf", int(im.size[0]/5))
      im_draw.text((int(im.size[0]-im.size[0]/10), 5), "4", (256, 0, 0), font=font)
      del im_draw
-     im.save(file_path)
+     im.save('./result.png')
  
  if __name__ == "__main__":
      if len(sys.argv) <= 1:
          print("Need at least 1 parameter. Try to execute 'python 0000.py $image_path'")
      else:
          for infile in sys.argv[1:]:
              try:
                  add_num_to_img(infile)
                  print("Success!")
              except IOError:
                  print("Can't open image!")
                  pass
  
+ 
Rename the result image to avoid overwriting the original image
## Code Before:

from PIL import Image, ImageDraw, ImageFont
import sys


def add_num_to_img(file_path):
    im = Image.open(file_path)
    im_draw = ImageDraw.Draw(im)
    font = ImageFont.truetype("arial.ttf", int(im.size[0]/5))
    im_draw.text((int(im.size[0]-im.size[0]/10), 5), "4", (256, 0, 0), font=font)
    del im_draw
    im.save(file_path)

if __name__ == "__main__":
    if len(sys.argv) <= 1:
        print("Need at least 1 parameter. Try to execute 'python 0000.py $image_path'")
    else:
        for infile in sys.argv[1:]:
            try:
                add_num_to_img(infile)
                print("Success!")
            except IOError:
                print("Can't open image!")
                pass

## Instruction:
Rename the result image to avoid overwriting the original image
## Code After:

from PIL import Image, ImageDraw, ImageFont
import sys


def add_num_to_img(file_path):
    im = Image.open(file_path)
    im_draw = ImageDraw.Draw(im)
    font = ImageFont.truetype("arial.ttf", int(im.size[0]/5))
    im_draw.text((int(im.size[0]-im.size[0]/10), 5), "4", (256, 0, 0), font=font)
    del im_draw
    im.save('./result.png')

if __name__ == "__main__":
    if len(sys.argv) <= 1:
        print("Need at least 1 parameter. Try to execute 'python 0000.py $image_path'")
    else:
        for infile in sys.argv[1:]:
            try:
                add_num_to_img(infile)
                print("Success!")
            except IOError:
                print("Can't open image!")
                pass

