import time import sys import PySide sys.modules['PyQt4'] = PySide # this little hack allows to solve naming problem when using PIL with Pyside (instead of PyQt4) from PIL import Image, ImageQt from PySide import QtCore,QtGui EXAMPLE1 = 1 EXAMPLE2 = 2 EXAMPLE3 = 3 ############################################################### ##### change the following variable to select the example ##### case = EXAMPLE3 ############################################### ############################################################### ############################################################### #keep looking at your process manager to see python dedicated memory increase, and don't forget to ctrl+c :) if __name__ == '__main__': #we just create a small blue picture for our example refImage = QtGui.QImage(100,100,QtGui.QImage.Format_ARGB32) refImage.fill(QtCore.Qt.blue) refImage.save('i.png','PNG') #first example if case == EXAMPLE1: print("case1") #load pic with pil im = Image.open('i.png').convert('RGBA') while True: # loop #use ImageQt to transfer it to QtImage type imQt = QtGui.QImage(ImageQt.ImageQt(im)) imQt.save("o.png") #image is ok time.sleep(0.1) # second example, I got rid of ImageQt to show it's not directly responsible elif case == EXAMPLE2: print("case2") im = Image.open('i.png').convert('RGBA') while True: #loop data = im.tostring('raw','RGBA') imQt = QtGui.QImage(data,im.size[0],im.size[1],QtGui.QImage.Format_ARGB32) imQt.save("o.png") #image is ok time.sleep(0.1) # third case, if the data variable is out of the loop, memory stays constant elif case == EXAMPLE3: print("case3") im = Image.open('i.png').convert('RGBA') data = im.tostring('raw','RGBA') while True: #loop #data = copy.deepcopy(data) #no effect imQt = QtGui.QImage(data,im.size[0],im.size[1],QtGui.QImage.Format_ARGB32) imQt.save("o.png") #image is ok time.sleep(0.1) #note : in examples 2 and 3, blue/red channels are inverted, this is normal, and this is the reason why PIL.Image.ImageQt() exists