コード例 #1
0
ファイル: test_core.py プロジェクト: jimr/deba-bocho
    def test_basic_stack(self):
        output = assemble(self.fname)
        img = Image.open(output)

        self.assertEqual(img.size,
                         (DEFAULTS.get('width'), DEFAULTS.get('height')))

        self.cleanup(output)
コード例 #2
0
ファイル: test_core.py プロジェクト: Maplecroft/deba-bocho
    def test_basic_stack(self):
        output = assemble(self.fname)
        img = Image.open(output)

        self.assertEqual(
            img.size, (DEFAULTS.get('width'), DEFAULTS.get('height'))
        )

        self.cleanup(output)
コード例 #3
0
ファイル: cmd.py プロジェクト: jimr/deba-bocho
def main():
    """Command-line entry point for key functionality."""
    parser = argparse.ArgumentParser()
    parser.add_argument('pdf_file')
    parser.add_argument('--pages', type=int, nargs='*')
    parser.add_argument('--width', type=int, nargs='?')
    parser.add_argument('--height', type=int, nargs='?')
    parser.add_argument('--resolution', type=int, nargs='?')
    parser.add_argument(
        '--angle', type=int, nargs='?',
        help='Angle of rotation (between -90 and 90 degrees)',
    )
    parser.add_argument('--offset_x', type=int, nargs='?')
    parser.add_argument('--offset_y', type=int, nargs='?')
    parser.add_argument('--spacing_x', type=int, nargs='?')
    parser.add_argument('--spacing_y', type=int, nargs='?')
    parser.add_argument('--zoom', type=float, nargs='?')
    parser.add_argument('--reverse', action='store_true', default=None)
    parser.add_argument('--border', type=int, nargs='?')
    parser.add_argument('--colour', nargs='?')
    parser.add_argument('--shadow', action='store_true', default=None)
    parser.add_argument('--affine', action='store_true', default=None)
    parser.add_argument('--use_convert', action='store_true', default=None)
    parser.add_argument(
        '--reuse', action='store_true', default=None,
        help='Re-use page PNG files between runs. If True, you need to clear '
             'up after yourself, but multiple runs on the same input will be '
             'much faster.',
    )
    parser.add_argument(
        '--delete', action='store_true', default=None,
        help='Delete the output file before running. If False, and the file '
             'exists, an exception will be raised and nothing will happen.',
    )
    parser.add_argument('--config', help='path to config.ini')
    parser.add_argument('--preset', help='load parameters from a named preset')
    parser.add_argument(
        '--parallel', type=int, nargs='?',
        help='If set to a value > 1, we use that number of processes when '
             'applying borders & shadow to individual pages.',
    )
    parser.add_argument('--verbose', action='store_true', default=None)
    args = parser.parse_args()

    name, ext = os.path.splitext(args.pdf_file)
    if ext != '.pdf':
        raise Exception("Input file doesn't look like a PDF")

    kwargs = dict(args._get_kwargs())
    print(assemble(args.pdf_file, **kwargs))
コード例 #4
0
ファイル: app.py プロジェクト: Maplecroft/chopper
def chop():
    pages = request.args.get('pages')
    if pages:
        pages = pages.split(',')

    f = request.files['file']
    fd, out_path = tempfile.mkstemp(
        suffix=secure_filename(f.filename),
        dir='upload',
    )
    os.close(fd)
    f.save(out_path)

    file_path = assemble(
        out_path, pages=pages, angle=25, zoom=1.35, reverse=True, affine=True,
        offset_x=14, offset_y=-5, spacing_x=40, spacing_y=0, border=4,
        use_convert=True,
    )

    with open(file_path) as f:
        response = make_response(f.read())
        response.headers['Content-Type'] = 'image/png'
        return response