Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacement of imghdr #946

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions core/basemaps/mapservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import queue
import time
import urllib.request
import imghdr
import sys, time, os

#core imports
Expand All @@ -37,6 +36,8 @@
from ..proj.reproj import reprojPt, reprojBbox, reprojImg
from ..proj.ellps import dd2meters, meters2dd
from ..proj.srs import SRS
from PIL import Image
from io import BytesIO

from .. import settings
USER_AGENT = settings.user_agent
Expand Down Expand Up @@ -592,8 +593,10 @@ def downloadTile(self, laykey, col, row, zoom):

#Make sure the stream is correct
if data is not None:
format = imghdr.what(None, data)
if format is None:
try:
image = Image.open(BytesIO(data)) # Attempt to open the binary data as an image
image.verify() # Verifies that the file is a valid image
except (IOError, SyntaxError): # If it's not a valid image, set data to None
data = None

if data is None:
Expand Down
17 changes: 10 additions & 7 deletions core/georaster/img_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@


import struct
import imghdr
from PIL import Image
from io import BytesIO


def isValidStream(data):
if data is None:
return False
format = imghdr.what(None, data)
if format is None:
return False
return True
if data is None:
return False
try:
image = Image.open(BytesIO(data))
image.verify() # Verifies that the file is an image
return True
except (IOError, SyntaxError):
return False


def getImgFormat(filepath):
Expand Down