Simplify way to check if an image is valid

determinetype functions has some defaults
This commit is contained in:
Hugo Posnic 2019-02-20 15:27:45 +01:00
parent f7531a1095
commit 13f43bfa2f

View file

@ -16,7 +16,6 @@ from PyQt5.QtCore import *
from PyQt5.QtGui import * from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from filesize import * from filesize import *
from imghdr import what as determinetype
from queue import Queue from queue import Queue
from ThreadPool import ThreadPool from ThreadPool import ThreadPool
@ -398,23 +397,14 @@ class Image:
self.reset() self.reset()
self.fullpath = fullpath self.fullpath = fullpath
if path.isfile(self.fullpath) and access(self.fullpath, WRITEABLE): if path.isfile(self.fullpath) and access(self.fullpath, WRITEABLE):
self.filetype = determinetype(self.fullpath) self.filetype = path.splitext(self.fullpath)[1]
if self.filetype in ["jpeg", "png"]: if self.filetype in [".jpeg", ".jpg", ".png"]:
oldfile = QFileInfo(self.fullpath) oldfile = QFileInfo(self.fullpath)
self.shortname = oldfile.fileName() self.shortname = oldfile.fileName()
self.oldfilesize = oldfile.size() self.oldfilesize = oldfile.size()
self.icon = QIcon(self.fullpath) self.icon = QIcon(self.fullpath)
self.valid = True self.valid = True
#def _determinetype(self):
# """ Determine the filetype of the file using imghdr. """
# filetype = determinetype(self.fullpath)
# if filetype in ["jpeg", "png"]:
# self.filetype = filetype
# else:
# self.filetype = None
# return self.filetype
def reset(self): def reset(self):
self.failed = False self.failed = False
self.compressed = False self.compressed = False