DEV Community

petercour
petercour

Posted on

Image converter in python

It's easy to create an image converter gui in Python. You can use the PyQt module to create desktop software. Then simply design your user interface it in designer and then load it with the code.

In the case of this app, just link the button clicks to the command line program "convert".

    # connect clicks to callback functions
    self.pushButtonDir.clicked.connect(self.onClick)
    self.pushButtonConvert.clicked.connect(self.onConvert)

def onClick(self):
    self.thedir = str(QFileDialog.getExistingDirectory(self, "Select Directory"))
    print('select dir ' + self.thedir)

def onConvert(self):
    images = glob.glob(self.thedir + "/*")
    print(images)
    for image in images:
        # no dot in filename allowed
        newImage = image[:image.index(".")] + self.comboBox.currentText()
        cmd = "convert " + image + " " + newImage
        os.system(cmd)

More on PyQt:

Top comments (0)