0

I'm trying to write a code in python that is able to open an image in paint and save it with a different name of the original one.

My code is the follow:

import os
import subprocess

new_path='img.png'
path_img='./img.jpeg'
paintPath = os.path.splitdrive(os.path.expanduser("~"))[0]+r"\WINDOWS\system32\mspaint.exe"
subprocess.call([paintPath, path_img])

At this point, my image appears on Paint, but I would like automatically to save it and close the program, if it is possible. I didn't find any solution online.

Azzurra
  • 51
  • 6
  • 1
    You could use the [`pyautogui`](https://pyautogui.readthedocs.io/en/latest/) to hotkey the save keys and close the program. – Codeman Feb 23 '22 at 11:13
  • 1
    Why do you need to use MS paint? It looks like all you want to do is to convert an image to a different format. You don't need paint to do that. Python can do it – kyriakosSt Feb 23 '22 at 11:16
  • https://stackoverflow.com/questions/10759117/converting-jpg-images-to-png –  Feb 23 '22 at 11:17
  • The point is that, after this process I get 'img.png' and I need to make by hand some modifications in few images of those by using Paint, so for example I will have 'img_modified.png' Now, I'm going to compare img.png and img_modified.png, If I don't make img.png, but I directly compare img.jpeg (that has not been opened in paint) and img_modified.png I get a wrong result. When I open an image in Paint, it changes. – Azzurra Feb 23 '22 at 11:30
  • Just use **PIL/Pillow** `from PIL import Image; Image.open('image.jpg').save('image.png')` – Mark Setchell Feb 23 '22 at 11:42

0 Answers0