'Record the size of an Image upon Upload
Don\'t wish to resize here as we\'d like to use full resolution for printed output'

@staticmethod
def gis_marker_onvalidation(form):

    form_vars = form.vars
    image = form_vars.image
    if (image is None):
        encoded_file = form_vars.get('imagecrop-data', None)
        if (not encoded_file):
            return
        import base64
        import uuid
        (metadata, encoded_file) = encoded_file.split(',')
        (filename, datatype, enctype) = metadata.split(';')
        f = Storage()
        f.filename = (uuid.uuid4().hex + filename)
        import cStringIO
        f.file = cStringIO.StringIO(base64.decodestring(encoded_file))
        form_vars.image = image = f
    elif isinstance(image, str):
        return
    extension = image.filename.rfind('.')
    extension = image.filename[(extension + 1):].lower()
    if (extension == 'jpg'):
        extension = 'jpeg'
    if (extension not in ('bmp', 'gif', 'jpeg', 'png')):
        form.errors.image = current.T("Uploaded    file(s)    are    not    Image(s).    Supported    image    formats    are    '.png',    '.jpg',    '.bmp',    '.gif'.")
        return
    native = False
    try:
        from PIL import Image
    except ImportError:
        try:
            import Image
        except:
            native = True
            import struct
    if native:
        width = height = (-1)
        stream = image.file
        if (extension == 'bmp'):
            if (stream.read(2) == 'BM'):
                stream.read(16)
                (width, height) = struct.unpack('<LL', stream.read(8))
        elif (extension == 'gif'):
            if (stream.read(6) in ('GIF87a', 'GIF89a')):
                stream = stream.read(5)
                if (len(stream) == 5):
                    (width, height) = tuple(struct.unpack('<HHB', stream)[:(-1)])
        elif (extension == 'jpeg'):
            if (stream.read(2) == '\xff\xd8'):
                while True:
                    (marker, code, length) = struct.unpack('!BBH', stream.read(4))
                    if (marker != 255):
                        break
                    elif ((code >= 192) and (code <= 195)):
                        (width, height) = tuple(reversed(struct.unpack('!xHH', stream.read(5))))
                    else:
                        stream.read((length - 2))
        elif (extension == 'png'):
            if (stream.read(8) == '\x89PNG\r\n\x1a\n'):
                stream.read(4)
                if (stream.read(4) == 'IHDR'):
                    (width, height) = struct.unpack('!LL', stream.read(8))
    else:
        try:
            im = Image.open(image.file)
        except:
            width = height = (-1)
        else:
            (width, height) = im.size
    if ((width < 1) or (height < 1)):
        form.errors.image = current.T('Invalid    image!')
        return
    if ((width > 50) or (height > 50)):
        if native:
            form.errors.image = current.T('Maximum    size    50x50!')
            return
        im.thumbnail((50, 50), Image.ANTIALIAS)
        (width, height) = im.size
        current.session.warning = current.T('File    has    been    resized')
    image.file.seek(0)
    form_vars.width = width
    form_vars.height = height
