Beispiel #1
0
 def _create_user(self, netid, email, password, **extra_fields):
     """
     Creates and saves a User with the given username, email and password.
     """
     now = timezone.now()
     if not netid:
         raise ValueError('The given netid must be set')
     email = self.normalize_email(email)
     user = self.model(netid=netid,
                       email=email,
                       last_login=now,
                       **extra_fields)
     if settings.IDENTICON:
         IDENTICON_SIZE = 120
         if not os.path.exists(join(settings.MEDIA_ROOT, "profile")):
             os.makedirs(join(settings.MEDIA_ROOT, "profile"))
         profile_path = join(settings.MEDIA_ROOT, "profile",
                             "{}.png".format(netid))
         alpha_netid = PATTERN.sub('', netid)
         identicon.render_identicon(int(alpha_netid, 36),
                                    IDENTICON_SIZE / 3).save(profile_path)
         user.photo = 'png'
     user.set_password(password)
     user.save(using=self._db)
     return user
Beispiel #2
0
 def get(self, id):
     width = request.args.get('width')
     height = request.args.get('height')
     user = User.query.filter_by(id=id).first()
     if user is None:
         return {'status': 'fail', 'mesg': '该用户还未注册!'}
     img_inf = Img.query.filter_by(user_id=id).first()
     if img_inf is None:
         code = random.randint(50000000, 90000000)
         img = identicon.render_identicon(code, 36)
         img_path = os.path.join(get_path(), str(id) + '.jpg')
         img.save(img_path)
         record = Img(id, img_path)
         db.session.add(record)
         try:
             db.session.commit()
             return send_file(img_path)
         except:
             return {'status': 'fail', 'mesg': '头像初始化失败!'}, 200
     pic = Image.open(img_inf.img_path)
     w, h = pic.size
     if (width is not None) and (height is not None):
         if (w < int(width)) or (h < int(height)):
             return {'status': 'fail', 'mesg': '参数不在合理范围!'}, 200
         pic = pic.resize((int(width), int(height)), Image.ANTIALIAS)
         prefix = os.path.split(os.path.realpath(__file__))[0] + '/buf/'
         postfix = (img_inf.img_path).split('/')[-1]
         path = prefix + postfix
         delete_file_folder(prefix)
         pic.save(path)
     else:
         path = img_inf.img_path
     return send_file(path)
Beispiel #3
0
 def get(self, id):
     width = request.args.get('width')
     height = request.args.get('height')
     user = User.query.filter_by(id=id).first()
     if user is None:
         return {'status': 'fail', 'mesg': '该用户还未注册!'}
     img_inf = Img.query.filter_by(user_id=id).first()
     if img_inf is None:
         code = random.randint(50000000, 90000000)
         img = identicon.render_identicon(code, 36)
         img_path = os.path.join(get_path(), str(id) + '.jpg')
         img.save(img_path)
         record = Img(id, img_path)
         db.session.add(record)
         try:
             db.session.commit()
             return send_file(img_path)
         except:
             return {'status': 'fail', 'mesg': '头像初始化失败!'}, 200
     pic = Image.open(img_inf.img_path)
     w, h = pic.size
     if (width is not None) and (height is not None):
         if (w < int(width)) or (h < int(height)):
             return {'status': 'fail', 'mesg': '参数不在合理范围!'}, 200
         pic = pic.resize((int(width), int(height)), Image.ANTIALIAS)
         prefix = os.path.split(os.path.realpath(__file__))[0] + '/buf/'
         postfix = (img_inf.img_path).split('/')[-1]
         path = prefix + postfix
         delete_file_folder(prefix)
         pic.save(path)
     else:
         path = img_inf.img_path
     return send_file(path)
Beispiel #4
0
def create_identicon(code, size, img_format):
	size = size/3
	img = render_identicon(code, size)
	stream = StringIO()

	img.save(stream, format = img_format)

	return stream
Beispiel #5
0
 def _create_user(self, netid, email, password, **extra_fields):
     """
     Creates and saves a User with the given username, email and password.
     """
     now = timezone.now()
     if not netid:
         raise ValueError('The given netid must be set')
     email = self.normalize_email(email)
     user = self.model(netid=netid, email=email, last_login=now, **extra_fields)
     if settings.IDENTICON:
         IDENTICON_SIZE = 120
         profile_path = join(settings.MEDIA_ROOT, "profile", "{}.png".format(netid))
         identicon.render_identicon(int(netid, 36), IDENTICON_SIZE / 3).save(profile_path)
         user.photo = 'png'
     user.set_password(password)
     user.save(using=self._db)
     return user
Beispiel #6
0
def img_create(filename):
    filename_url = 'static/img/avatar/{0}.png'.format(filename)
    result = ''
    for i in filename:
        result += '{0}'.format(ord(i))
    img_id = int(result)
    img = identicon.render_identicon(img_id, 36)
    img.save(filename_url)
    return True
Beispiel #7
0
 def reset_avatar(self, assets_manager_service):
     avatar = identicon.render_identicon(int_hash(self.data.email or self.data.email_to_confirm),
                                         48)
     icon_file = BytesIO()
     avatar.save(icon_file, 'PNG')
     assets_manager_service.save(
         icon_file.getvalue(),
         self.data.username,
         {'filename': '%s.png' % self.data.username})
     self.data.picture = assets_manager_service.get_image_url(self.data.username, 'thumb')
Beispiel #8
0
 def reset_avatar(self, assets_manager_service):
     avatar = identicon.render_identicon(
         int_hash(self.data.email or self.data.email_to_confirm), 48)
     icon_file = BytesIO()
     avatar.save(icon_file, 'PNG')
     assets_manager_service.save(
         icon_file.getvalue(), self.data.username,
         {'filename': '%s.png' % self.data.username})
     self.data.picture = assets_manager_service.get_image_url(
         self.data.username, 'thumb')
Beispiel #9
0
def genimage(release_path, query, ofile):
    font = ImageFont.truetype("YanoneKaffeesatz-Bold.otf", 80 )
    img = identicon.render_identicon(random.randint(0, 99999999), 300)
    draw = ImageDraw.Draw(img)
    text = ""
    for l in query.split('-'):
        text += re.sub("(.{30})", "\\1\n", l, 0, re.DOTALL)
        text += "\n"
    draw.multiline_text((100, 300),text,(44,44,44),font=font, align='center')
    img.save(ofile)
    return query, ofile
Beispiel #10
0
def genimage(release_path, query, ofile):
    font = ImageFont.truetype("YanoneKaffeesatz-Bold.otf", 80)
    img = identicon.render_identicon(random.randint(0, 99999999), 300)
    draw = ImageDraw.Draw(img)
    text = ""
    for l in query.split('-'):
        text += re.sub("(.{30})", "\\1\n", l, 0, re.DOTALL)
        text += "\n"
    draw.multiline_text((100, 300),
                        text, (44, 44, 44),
                        font=font,
                        align='center')
    img.save(ofile)
    return query, ofile
Beispiel #11
0
    def __init__(self, **kwargs):
        '''
            init class, generate user role and photo
        :param kwargs: kwargs
        '''

        super(User, self).__init__(**kwargs)
        if self.role is None:
            if self.email == current_app.config['FLASKY_ADMIN']:
                self.role = Role.query.filter_by(permission=0xff).first()
                self.confirmed = True
            if self.role is None:
                self.role = Role.query.filter_by(default=True).first()
        if self.photo is None:
            code = random.randint(1, 1000000000000)
            icon = identicon.render_identicon(code, 128)
            icon.save('./app/static/photo/%08x.png' % code, 'PNG')
            self.photo = '%08x' % code
        if self.nickname is None:
            self.nickname = self.username
Beispiel #12
0
def gen_avatar_batch(code, size, dir):
    img = identicon.render_identicon(code, 16)
    img.save(dir + '%s_%s.png' % (code, size))
Beispiel #13
0
def contact_view_picture(request, contact_id, response_format='html'):
    "Contact view Picture"
    response = HttpResponse(content_type="image/png")
    render_identicon(contact_id * 5000).save(response, "PNG")
    return response
Beispiel #14
0
def contact_view_picture(request, contact_id, response_format='html'):
    "Contact view Picture"
    response = HttpResponse(content_type="image/png")
    render_identicon(contact_id * 5000).save(response, "PNG")
    return response
Beispiel #15
0
import identicon

s = "Y21614015"
img = identicon.render_identicon(abs(hash(s)) % (10**20), 20)
img.save('2.png')
def gen_avatar_batch(code,size):
	img= identicon.render_identicon(code, 16)
	#img.show()
	img.save('%s_%s.png'%(code,size))
Beispiel #17
0
def gen():
    img = identicon.render_identicon(num, picsize)
    img.save('identicon.png')
    print 'The identicon was generated.'
Beispiel #18
0
import identicon
img = identicon.render_identicon('123123', 16)
img.show()
def gen():
    img = identicon.render_identicon(num, picsize)
    img.save('identicon.png')
    print 'The identicon was generated.'