{"id":15335681,"url":"https://github.com/kinow/a4-to-a3","last_synced_at":"2026-02-05T14:04:49.519Z","repository":{"id":50633381,"uuid":"518077528","full_name":"kinow/a4-to-a3","owner":"kinow","description":"A Python script that uses Python libraries, ImageJ, and ImageMagick to automatically convert a scanned PDF with two A4 pages, into a single A3.","archived":false,"fork":false,"pushed_at":"2022-07-31T09:39:25.000Z","size":43483,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T13:32:50.153Z","etag":null,"topics":["drawing","figure-drawing","image-stitching","imagej","imaging","life-drawing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kinow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-26T13:41:31.000Z","updated_at":"2022-07-31T09:39:31.000Z","dependencies_parsed_at":"2022-08-22T12:40:13.053Z","dependency_job_id":null,"html_url":"https://github.com/kinow/a4-to-a3","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/kinow/a4-to-a3","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinow%2Fa4-to-a3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinow%2Fa4-to-a3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinow%2Fa4-to-a3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinow%2Fa4-to-a3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kinow","download_url":"https://codeload.github.com/kinow/a4-to-a3/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinow%2Fa4-to-a3/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264446717,"owners_count":23609632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drawing","figure-drawing","image-stitching","imagej","imaging","life-drawing"],"created_at":"2024-10-01T10:13:49.248Z","updated_at":"2026-02-05T14:04:48.328Z","avatar_url":"https://github.com/kinow.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A4-to-A3\n\nA Python script that uses Python libraries, ImageJ, and ImageMagick to\nautomatically convert a scanned PDF with two A4 pages, into a single A3.\n\n## Motivation\n\nThe use case is scanned A3 pages used for life-drawing sessions at the\n[Auckland CBD Life Drawing](https://www.facebook.com/groups/aklcbdlifedrawing)\ngroup.\n\nThese A3 pages are scanned in a Brother MFCL2720DW Monochrome wireless\nlaser all-in-one printer. Due to the scanner glass size, it is not possible\nto scan the document in one go.\n\n![](./printer.jpg)\n\nThe A3 page is scanned twice. The first half is scanned facing up, and the\nsecond half needs to be scanned rotated 180 degrees. Previously GIMP was\nused to stitch the images, manually, changing opacity of layers.\n\nOpenCV contains a stitching function, but it is not able to identify\nenough key points between images, since normally there are two drawings\nper page, with the mid-area of the drawing quasi-empty.\n\nImageJ comes with a plug-in for stitching that, when combined with a\nselection to reduce the search-area, works as well as the manual\nwork flow with GIMP.\n\nInstead of spending between 15 minutes, now the whole process takes\nless than 10 seconds to copy the files and execute the command line.\nThe program takes between 1 and 2 minutes to process 6 files, creating\nthe final image with color, brightness, and contrast levels adjusted,\nand an image with the canvas size with equal width and height (useful\nfor social medias like Instagram, for instance).\n\n## Dependencies\n\nThe Python libraries used are:\n\n- [pypdfium2](https://pypi.org/project/pypdfium2/)\n- [Pillow](https://pypi.org/project/Pillow/)\n- [joblib](https://pypi.org/project/joblib/)\n\nThe version of ImageJ used is ImageJ 1.53q, for Linux without a JRE.\nDue to libraries from the Sun namespace, and how ImageJ tries to\nload JVM libraries, it is necessary to use an Oracle JVM version 8:\n\n```bash\nkinow@ranma:~/Downloads/Fiji.app$ export PATH=/usr/lib/jvm/java-8-oracle/bin:$PATH\nkinow@ranma:~/Downloads/Fiji.app$ ./ImageJ-linux64 \nJava HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0\nJava HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release\n```\n\nAnd the following version of ImageMagick was used, installed via `apt`\nin Ubuntu 20.04.4 LTS:\n\n```bash\nkinow@ranma:~/Downloads/Fiji.app$ convert -version\nVersion: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org\nCopyright: © 1999-2019 ImageMagick Studio LLC\nLicense: https://imagemagick.org/script/license.php\nFeatures: Cipher DPC Modules OpenMP \nDelegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib\n```\n\n## Installation\n\nVerify that the JVM, ImageJ, and ImageMagick versions are installed first.\nClone this repository and install the Python dependencies with `pip`:\n\n```bash\npip install -U pip\npip install -U -r requirements.txt\n```\n\n\u003e A virtual environment is recommended.\n \n## Usage\n\n```bash\n(venv) kinow@ranma:~/Development/python/workspace/a4-to-a3$ python main.py -h\nusage: main.py [-h] [--keep-files] [--debug] IN [IN ...]\n\nConverts a 2-page A4 document into a single page A3, stitching images that overlap.\n\npositional arguments:\n  IN            Input PDF\n\noptional arguments:\n  -h, --help    show this help message and exit\n  --keep-files  Flag to keep intermediary files (left and right pages)\n  --debug       Log debug information\n```\n\nYou can pass a single or multiple PDF's. The process flow of the script is\nthe following:\n\n```mermaid\ngraph TD\n    A[extract images from PDF] --\u003e B[rotate second page];\n    B --\u003e C[ImageJ macro stitch pages];\n    C --\u003e D[adjust brightness/color/contrast levels];\n    D --\u003e E[resize images];\n```\n\n## Example\n\nThis repository contains an example from a figure drawing session.\n\nThe original input is the file [`example.pdf`](./example.pdf). \nThe first page extracted from the PDF.\n\n![](./example-1.png)\n\nThe second page extracted from the PDF, rotated 180 degrees.\n\n![](./example-2.png)\n\nThe images have been inverted, stitched, inverted again, and saved as a single page.\n\n![](./example.png)\n\nAnd another version with same width and height sizes.\n\n![](./example-square.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkinow%2Fa4-to-a3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkinow%2Fa4-to-a3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkinow%2Fa4-to-a3/lists"}