示例#1
0
def create_group_icon(_redis, _users):
    _identicon_store = get_config_server_identicon_store()
    if _identicon_store == None:
        logging.error("no identicon_store configed")
        return None
    
    if len(_users) == 0:
        return None
    
    _icon_list = []
    for _uuid in _users:
        _user_key = DeviceUser.__tablename__ + ".uuid." + _uuid
        _user_icon = _redis.hget(_user_key, "user_icon")
        if _user_icon == None:
            _icon_list.append(_user_icon)
            continue
        _file_key = FileInfo.__tablename__ + ".uuid." + _user_icon
        _file_path = _redis.hget(_file_key, "file_path")
        _icon_list.append(_file_path)

    _data = ImageConverter.conversation_icon(_icon_list)
    if _data == None:
        logging.error("conversation icon data is None, will not create icon file")
        return None
    _file_name = hashlib.sha1("".join(_users)).hexdigest() + ".png"
    _file_path = _identicon_store + os.path.sep + _file_name
    _file = open(_file_path, "wb")
    _file.write(_data)
    _file.close()
    return _icon_url(_file_name)
示例#2
0
def create_group_icon(_redis, _users):
    if len(_users) == 0:
        return None

    _icon_list = []
    for _uuid in _users:
        _user_key = DeviceUser.__tablename__ + ".uuid." + _uuid
        _user_icon = _redis.hget(_user_key, "user_icon")
        if _user_icon == None:
            _icon_list.append(_user_icon)
            continue
        _file_key = FileInfo.__tablename__ + ".uuid." + _user_icon
        _file_path = _redis.hget(_file_key, "file_path")
        _icon_list.append(_file_path)

    _data = ImageConverter.conversation_icon(_icon_list)
    if _data == None:
        logging.error(
            "conversation icon data is None, will not create icon file")
        return None
    _file_name = hashlib.sha1("".join(_users)).hexdigest() + ".png"
    _identicon_store = BOOTSTRAP_DATA.get("server").get("identicon_store")
    _file_path = _identicon_store + os.path.sep + _file_name
    _file = open(_file_path, "wb")
    _file.write(_data)
    _file.close()
    return _icon_url(_file_name)
示例#3
0
    def _parseImage(self, _body):
        _image = json.loads(_body)

        _fid = _image.get("fid")
        _mime = _image.get("mime")

        if _fid == None or _mime == None:
            logging.error("Error for message body of image message")
            return None
        
        _mime = _mime.lower()
        if _mime not in ["image/jpg", "image/jpeg", "image/png", "image/gif"]:
            logging.error("Error for not supported mime=%s." % (_mime))
            return None

        _file = redis_hash_to_dict(self._redis, FileInfo, _fid)
        if _file == None:
            logging.error("Error for no file in redis: %s" % _fid)
            return None

        _image = None
        try:
            # raise IOError when file not image
            _image = Image.open(_file["file_path"])
        except:
            pass
        finally:
            if _image == None:
                logging.error("PIL can not identify the file_id=%s, not image." % (_fid))
                return None

        _image_width = _image.width
        _image_height = _image.height
        _thum_width = _image.width
        _thum_height = _image.height
        
        if _image.format == "GIF":
            return {"thum":_fid, "orig":_fid, "mime":"image/gif", "orig_width": _image_width, "orig_height": _image_height, "thum_width": _thum_width, "_thum_height": _thum_height}
        
        _thum_format = "JPEG"
        if _image.format == "PNG":
            _thum_format = "PNG"

        _thum_image_info = ImageConverter.thumbnailByKeepImage(_image, _thum_format)
        _thum_data = _thum_image_info["data"]
        _thum_image = _thum_image_info["image"]
        if _thum_data == None:
            logging.error("Error for thumbnail image")
            return None

        _thum_id = create_file_with_data(self._redis, _thum_data, _mime, self._from_uuid)

        _thum_width = _thum_image.width
        _thum_height = _thum_image.height

        # where assume the _thum must be jpeg
        return {"thum":_thum_id, "orig":_fid, "mime":_mime, "orig_width": _image_width, "orig_height": _image_height, "thum_width": _thum_width, "thum_height": _thum_height}
示例#4
0
    def _parseImage(self, _body):
        _image = json.loads(_body)

        _fid = _image.get("fid")
        _mime = _image.get("mime")

        if _fid == None or _mime == None:
            logging.error("Error for message body of image message")
            return None
        
        _mime = _mime.lower()
        if _mime not in ["image/jpg", "image/jpeg", "image/png", "image/gif"]:
            logging.error("Error for not supported mime=%s." % (_mime))
            return None

        _file = redis_hash_to_dict(self._redis, FileInfo, _fid)
        if _file == None:
            logging.error("Error for no file in redis: %s" % _fid)
            return None

        _image = None
        try:
            # raise IOError when file not image
            _image = Image.open(_file["file_path"])
        except:
            pass
        finally:
            if _image == None:
                logging.error("PIL can not identify the file_id=%s, not image." % (_fid))
                return None

        _image_width, _image_height = _image.size
        _thum_width = _image_width
        _thum_height = _image_height
        
        if _image.format == "GIF":
            return {"thum":_fid, "orig":_fid, "mime":"image/gif", "orig_width": _image_width, "orig_height": _image_height, "thum_width": _thum_width, "thum_height": _thum_height}
        
        _thum_format = "JPEG"
        if _image.format == "PNG":
            _thum_format = "PNG"

        _thum_image_info = ImageConverter.thumbnailByKeepImage(_image, _thum_format)
        _thum_data = _thum_image_info["data"]
        _thum_image = _thum_image_info["image"]
        if _thum_data == None:
            logging.error("Error for thumbnail image")
            return None

        _thum_id = create_file_with_data(self._redis, _thum_data, _mime, self._from_uuid)

        _thum_width, _thum_height = _thum_image.size

        # where assume the _thum must be jpeg
        return {"thum":_thum_id, "orig":_fid, "mime":_mime, "orig_width": _image_width, "orig_height": _image_height, "thum_width": _thum_width, "thum_height": _thum_height}
示例#5
0
def create_group_icon(_redis, _users):
    _identicon_store = get_config_server_identicon_store()
    if _identicon_store == None:
        logging.error("no identicon_store configed")
        return None

    if len(_users) == 0:
        return None

    if len(_users) == 1:
        _user_key = DeviceUser.__tablename__ + ".uuid." + list(_users)[0]
        _user_icon = _redis.hget(_user_key, "user_icon")
        if _user_icon == None:
            return _icon_url("default_icon.png")
        return _user_icon

    _icon_list = []
    for _uuid in _users:
        _user_key = DeviceUser.__tablename__ + ".uuid." + _uuid
        _user_icon = _redis.hget(_user_key, "user_icon")
        if _user_icon != None:
            _icon_list.append(_user_icon)
        else:
            _icon_list.append(_icon_url("default_icon.png"))

    _icon_list = map(_url2local, _icon_list)

    _data = ImageConverter.conversation_icon(_icon_list)
    if _data == None:
        logging.error(
            "conversation icon data is None, will not create icon file")
        return None
    _file_name = hashlib.sha1("".join(_users)).hexdigest() + ".png"
    _file_path = _identicon_store + os.path.sep + _file_name
    _file = open(_file_path, "wb")
    _file.write(_data)
    _file.close()
    return _icon_url(_file_name)