{"id":22200411,"url":"https://github.com/iaseth/splitter","last_synced_at":"2026-04-16T18:39:29.206Z","repository":{"id":263638301,"uuid":"891029088","full_name":"iaseth/splitter","owner":"iaseth","description":"Image Splitter in Python.","archived":false,"fork":false,"pushed_at":"2024-11-20T11:17:43.000Z","size":1457,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T23:49:12.055Z","etag":null,"topics":["chatgpt","image","image-processing","midjourney","python","stable-diffusion"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iaseth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-19T15:49:53.000Z","updated_at":"2024-11-20T11:17:47.000Z","dependencies_parsed_at":"2024-11-20T00:04:10.359Z","dependency_job_id":null,"html_url":"https://github.com/iaseth/splitter","commit_stats":null,"previous_names":["iaseth/splitter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/iaseth/splitter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iaseth%2Fsplitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iaseth%2Fsplitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iaseth%2Fsplitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iaseth%2Fsplitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iaseth","download_url":"https://codeload.github.com/iaseth/splitter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iaseth%2Fsplitter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278532354,"owners_count":26002346,"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","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["chatgpt","image","image-processing","midjourney","python","stable-diffusion"],"created_at":"2024-12-02T15:26:50.786Z","updated_at":"2025-10-05T22:56:11.352Z","avatar_url":"https://github.com/iaseth.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# splitter\n`Splitter` is a python program that splits any grid-like image into separate files.\nConsider the below image:\n\n![Input Image](animated-female-faces.jpg)\n\nYou can use `splitter` to split this image into 9 separate files:\n```\npython3 splitter.py animated-female-faces.jpg rows=3 cols=3\n```\n\nThis will produce the following output:\n```\nRow 1 of 3 rows:\n\tColumn 1 of 3 columns:\n\t\tSaved: animated-female-faces_1_1.jpg [341x341]\n\tColumn 2 of 3 columns:\n\t\tSaved: animated-female-faces_1_2.jpg [341x341]\n\tColumn 3 of 3 columns:\n\t\tSaved: animated-female-faces_1_3.jpg [341x341]\nRow 2 of 3 rows:\n\tColumn 1 of 3 columns:\n\t\tSaved: animated-female-faces_2_1.jpg [341x341]\n\tColumn 2 of 3 columns:\n\t\tSaved: animated-female-faces_2_2.jpg [341x341]\n\tColumn 3 of 3 columns:\n\t\tSaved: animated-female-faces_2_3.jpg [341x341]\nRow 3 of 3 rows:\n\tColumn 1 of 3 columns:\n\t\tSaved: animated-female-faces_3_1.jpg [341x341]\n\tColumn 2 of 3 columns:\n\t\tSaved: animated-female-faces_3_2.jpg [341x341]\n\tColumn 3 of 3 columns:\n\t\tSaved: animated-female-faces_3_3.jpg [341x341]\n\n```\n\nThe command generated the 9 images shown below:\n\n![Output Image 1](output/animated-female-faces_1_1.jpg)\n![Output Image 2](output/animated-female-faces_1_2.jpg)\n![Output Image 3](output/animated-female-faces_1_3.jpg)\n![Output Image 4](output/animated-female-faces_2_1.jpg)\n![Output Image 5](output/animated-female-faces_2_2.jpg)\n![Output Image 6](output/animated-female-faces_2_3.jpg)\n![Output Image 7](output/animated-female-faces_3_1.jpg)\n![Output Image 8](output/animated-female-faces_3_2.jpg)\n![Output Image 9](output/animated-female-faces_3_3.jpg)\n\n\nI am using [`readmix`](https://github.com/iaseth/readmix) for generating this README.\nYou can view the source file [here](https://github.com/iaseth/splitter/blob/master/README.md.rx).\n\n\n## Args\nIn addition to the input file path, `splitter` accepts the following optional arguments:\n\n| `Arg`    | `Shortcut` | `Description` |\n| -------- | ---- | ------------------- |\n| `rows`   | `r`  | Number of rows.                         |\n| `cols`   | `c`  | Number of columns.                      |\n| `output` | `o`  | Output directory path.                  |\n| `prefix` |      | Prefix to be added to each output file. |\n| `format` | `f`  | Output format and file extension.       |\n\n\n## Code\n```py\nimport os\nimport sys\n\nfrom PIL import Image\n\n\n\ndef split_image_into_files(\n\tinput_image_path, output_directory, prefix,\n\trows=3, cols=3, output_format='jpg'\n):\n\t\"\"\"\n\tSplits an image containing a nxn grid into n separate images.\n\n\t:param input_image_path: Path to the input image\n\t:param output_directory: Path to the folder where output images will be saved\n\t:param prefix: Prefix to be added to each output image filename\n\t:param rows: Number of rows\n\t:param cols: Number of columns\n\t:param output_format: Format and file extension of the output file\n\t\"\"\"\n\ttry:\n\t\t# Open the input image\n\t\timg = Image.open(input_image_path)\n\t\timg_width, img_height = img.size\n\t\t\n\t\t# Calculate the size of each grid cell\n\t\tcell_width = img_width // cols\n\t\tcell_height = img_height // rows\n\t\t\n\t\t# Split the image into (rows * cols) separate images\n\t\tfor row in range(rows):\n\t\t\tprint(f\"Row {row+1} of {rows} rows:\")\n\t\t\tfor col in range(cols):\n\t\t\t\tprint(f\"\\tColumn {col+1} of {cols} columns:\")\n\t\t\t\t# Define the bounding box for each grid cell\n\t\t\t\tleft = col * cell_width\n\t\t\t\tupper = row * cell_height\n\t\t\t\tright = left + cell_width\n\t\t\t\tlower = upper + cell_height\n\t\t\t\tbox = (left, upper, right, lower)\n\t\t\t\t\n\t\t\t\t# Crop the grid cell and save it\n\t\t\t\tcropped_img = img.crop(box)\n\t\t\t\toutput_filename = f\"{prefix}_{row+1}_{col+1}.{output_format}\"\n\t\t\t\toutput_filepath = os.path.join(output_directory, output_filename)\n\t\t\t\tcropped_img.save(output_filepath)\n\t\t\t\tprint(f\"\\t\\tSaved: {output_filepath} [{cropped_img.size[0]}x{cropped_img.size[1]}]\")\n\texcept Exception as e:\n\t\tprint(f\"Error: {e}\")\n\n\ndef main():\n\targs = sys.argv[1:]\n\tif len(args) == 0:\n\t\tprint(f\"Usage:\\n\\tpython image-splitter.py\")\n\t\treturn\n\n\tinput_image_path = args[0]\n\tif not os.path.isfile(input_image_path):\n\t\tprint(f\"Not found: {input_image_path}\")\n\t\treturn\n\n\tinput_image_dirpath = os.path.dirname(input_image_path)\n\toutput_directory = input_image_dirpath\n\n\tinput_image_filename = os.path.basename(input_image_path)\n\tprefix = os.path.splitext(input_image_filename)[0]\n\toutput_format = os.path.splitext(input_image_filename)[1].strip('.')\n\n\trows = 2\n\tcols = 2\n\n\trest = args[1:]\n\tfor arg in rest:\n\t\tparts = arg.split(\"=\")\n\t\tif len(parts) == 2:\n\t\t\tkey = parts[0].strip()\n\t\t\tvalue = parts[1].strip()\n\t\t\tmatch key:\n\t\t\t\tcase 'rows' | 'r':\n\t\t\t\t\trows = int(value)\n\t\t\t\tcase 'cols' | 'c':\n\t\t\t\t\tcols = int(value)\n\t\t\t\tcase 'output' | 'o':\n\t\t\t\t\toutput_directory = value\n\t\t\t\tcase 'prefix':\n\t\t\t\t\tprefix = value\n\t\t\t\tcase 'format' | 'f':\n\t\t\t\t\toutput_format = value\n\t\t\t\tcase _:\n\t\t\t\t\tprint(f\"Invalid arg: '{arg}'\")\n\t\telse:\n\t\t\tprint(f\"Invalid arg: '{arg}'\")\n\t\t\treturn\n\n\t# output_directory = \"images/output\"\n\tsplit_image_into_files(input_image_path, output_directory, prefix=prefix, rows=rows, cols=cols, output_format=output_format)\n\n\nif __name__ == '__main__':\n\tmain()\n\n```\n\n\n## License\nMIT License\n\nCopyright (c) Ankur Seth.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n\n## Credit\n\nThis file was generated using [`readmix`](https://github.com/iaseth/readmix).\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiaseth%2Fsplitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiaseth%2Fsplitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiaseth%2Fsplitter/lists"}