Exemple #1
0
def fake_photo(count=30, period=None):
    # photos
    upload_path = current_app.config['VSHAURME_UPLOAD_PATH']
    for photo_number in range(count):
        random_color = tuple([random.randint(0, 255) for i in range(0,3)])
        img = Image.new("RGB", (100, 100), random_color)
        filename = 'random_%d.jpg' % photo_number
        img.save('{0}/{1}'.format(upload_path, filename))
        if period:
            timestamp = fake.date_between(start_date=f"-{period}d", end_date="today")
        else:
            timestamp = fake.date_time_this_year()
        photo = Photo(
            description=fake.text(),
            filename=filename,
            filename_m=filename,
            filename_s=filename,
            author=User.query.get(random.randint(1, User.query.count())),
            timestamp=timestamp
        )
        # tags
        for j in range(random.randint(1, 5)):
            tag = Tag.query.get(random.randint(1, Tag.query.count()))
            if tag not in photo.tags:
                photo.tags.append(tag)

        db.session.add(photo)

    db.session.commit()
Exemple #2
0
def fake_photo(count=30):
    # photos
    upload_path = current_app.config['VSHAURME_UPLOAD_PATH']
    for photo_number in range(count):
        filename = 'random_%d.jpg' % photo_number
        random_size = random.randint(1, 2000)
        random_colour1 = random.randint(0, 255)
        random_colour2 = random.randint(0, 255)
        random_colour3 = random.randint(0, 255)
        image = Image.new("RGB", (random_size, random_size),
                          (random_colour1, random_colour2, random_colour3))
        image.save('uploads/{0}'.format(filename))

        photo = Photo(description=fake.text(),
                      filename=filename,
                      filename_m=filename,
                      filename_s=filename,
                      author=User.query.get(
                          random.randint(1, User.query.count())),
                      timestamp=fake.date_time_this_year())

        # tags
        for j in range(random.randint(1, 5)):
            tag = Tag.query.get(random.randint(1, Tag.query.count()))
            if tag not in photo.tags:
                photo.tags.append(tag)

        db.session.add(photo)
    db.session.commit()
Exemple #3
0
def fake_photo(count=30):
    # photos
    upload_path = current_app.config['VSHAURME_UPLOAD_PATH']
    for photo_number in range(count):
        filename = 'random_%d.jpg' % photo_number
        # TODO: generate image
        n, l = 10, 256
        im = np.zeros((l, l))
        points = l * np.random.random((2, n**2))
        im[(points[0]).astype(np.int), (points[1]).astype(np.int)] = 1
        im = ndimage.gaussian_filter(im, sigma=l / n)
        mask = (im > im.mean()).astype(np.float)
        mask += 0.1 * im
        img = mask + 0.2 * np.random.randn(*mask.shape)
        imageio.imsave(os.path.join(upload_path, filename), img)
        photo = Photo(description=fake.text(),
                      filename=filename,
                      filename_m=filename,
                      filename_s=filename,
                      author=User.query.get(
                          random.randint(1, User.query.count())),
                      timestamp=fake.date_time_this_year())

        # tags
        for j in range(random.randint(1, 5)):
            tag = Tag.query.get(random.randint(1, Tag.query.count()))
            if tag not in photo.tags:
                photo.tags.append(tag)

        db.session.add(photo)
    db.session.commit()
Exemple #4
0
def fake_photo(count=30):
    # photos
    upload_path = current_app.config['VSHAURME_UPLOAD_PATH']
    for photo_number in range(count):
        filename = 'random_%d.jpg' % photo_number
        # TODO: generate image

        color = (random.randint(0, 255), random.randint(0, 255),
                 random.randint(0, 255))
        img = Image.new('RGB', (320, 240), color)
        imgDrawer = ImageDraw.Draw(img)

        img.save(os.path.join(upload_path, filename))
        photo = Photo(description=fake.text(),
                      filename=filename,
                      filename_m=filename,
                      filename_s=filename,
                      author=User.query.get(
                          random.randint(1, User.query.count())),
                      timestamp=fake.date_time_this_year())

        # tags
        for j in range(random.randint(1, 5)):
            tag = Tag.query.get(random.randint(1, Tag.query.count()))
            if tag not in photo.tags:
                photo.tags.append(tag)

        db.session.add(photo)
    db.session.commit()
Exemple #5
0
def upload():
    if request.method == 'POST' and 'file' in request.files:
        f = request.files.get('file')
        filename = rename_image(f.filename)
        f.save(os.path.join(current_app.config['VSHAURME_UPLOAD_PATH'], filename))
        filename_s = resize_image(f, filename, current_app.config['VSHAURME_PHOTO_SIZE']['small'])
        filename_m = resize_image(f, filename, current_app.config['VSHAURME_PHOTO_SIZE']['medium'])
        photo = Photo(
            filename=filename,
            filename_s=filename_s,
            filename_m=filename_m,
            author=current_user._get_current_object()
        )
        db.session.add(photo)
        db.session.commit()
    return render_template('main/upload.html')
Exemple #6
0
def fake_photo(count=30):
    # photos
    upload_path = current_app.config['VSHAURME_UPLOAD_PATH']
    for photo_number in range(count):
        filename = 'random_%d.jpg' % photo_number
        # TODO: generate image

        photo = Photo(description=fake.text(),
                      filename=filename,
                      filename_m=filename,
                      filename_s=filename,
                      author=User.query.get(
                          random.randint(1, User.query.count())),
                      timestamp=fake.date_time_this_year())

        # tags
        for j in range(random.randint(1, 5)):
            tag = Tag.query.get(random.randint(1, Tag.query.count()))
            if tag not in photo.tags:
                photo.tags.append(tag)

        db.session.add(photo)
    db.session.commit()