mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/file-setup.git
				synced 2025-10-31 10:42:45 +00:00 
			
		
		
		
	Add merge_images
This commit is contained in:
		
							
								
								
									
										44
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| image: docker:stable | ||||
|  | ||||
| services: | ||||
|   - docker:stable-dind | ||||
|  | ||||
| variables: | ||||
|   DOCKER_DRIVER: overlay2 | ||||
|  | ||||
| stages: | ||||
|   - build | ||||
|   - push | ||||
|  | ||||
| before_script: | ||||
|   - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY | ||||
|  | ||||
| Build: | ||||
|   script: | ||||
|     - docker build --pull -t $CI_REGISTRY_IMAGE:tmp . | ||||
|     - docker push $CI_REGISTRY_IMAGE:tmp | ||||
|   stage: build | ||||
|   tags: | ||||
|   - docker | ||||
|  | ||||
| Push latest: | ||||
|   only: | ||||
|     - master | ||||
|   script: | ||||
|     - docker pull $CI_REGISTRY_IMAGE:tmp | ||||
|     - docker tag $CI_REGISTRY_IMAGE:tmp $CI_REGISTRY_IMAGE:latest | ||||
|     - docker push $CI_REGISTRY_IMAGE:latest | ||||
|   stage: push | ||||
|   tags: | ||||
|   - docker | ||||
|  | ||||
| Push tag: | ||||
|   only: | ||||
|     - tags | ||||
|   script: | ||||
|     - docker pull $CI_REGISTRY_IMAGE:tmp | ||||
|     - docker tag $CI_REGISTRY_IMAGE:tmp $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME | ||||
|     - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME | ||||
|   stage: push | ||||
|   tags: | ||||
|   - docker | ||||
							
								
								
									
										23
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| FROM debian:9-slim | ||||
|  | ||||
|  | ||||
| # Define image metadata | ||||
| LABEL maintainer="inf_sfb1288@lists.uni-bielefeld.de" | ||||
|  | ||||
|  | ||||
| ENV LANG=C.UTF-8 | ||||
|  | ||||
|  | ||||
| # Install prerequisites | ||||
| RUN apt-get update \ | ||||
|  && apt-get install -y --no-install-recommends \ | ||||
|       imagemagick \ | ||||
|       python3.5 \ | ||||
|  && rm -rf /var/lib/apt/lists/* | ||||
|  | ||||
|  | ||||
| # Install merge_images | ||||
| COPY merge_images /usr/local/bin | ||||
|  | ||||
| ENTRYPOINT ["merge_images"] | ||||
| CMD ["--help"] | ||||
							
								
								
									
										39
									
								
								merge_images
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								merge_images
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| #!/usr/bin/env python3.5 | ||||
| # coding=utf-8 | ||||
|  | ||||
|  | ||||
| """ | ||||
| merge_images | ||||
|  | ||||
| Usage:  For usage instructions run with option --help | ||||
| Author: Stephan Porada <sporada@uni-bielefeld.de> | ||||
|  | ||||
| """ | ||||
|  | ||||
| import os | ||||
| import argparse | ||||
|  | ||||
|  | ||||
| def parse_arguments(): | ||||
|     parser = argparse.ArgumentParser(description='Merges given input images ' | ||||
|                                                  'into one multipage tiff.') | ||||
|     parser.add_argument('-i', dest='input_dir', required=True) | ||||
|     parser.add_argument('-o', dest='output_dir', required=True) | ||||
|     return parser.parse_args() | ||||
|  | ||||
|  | ||||
| def merge_images(input_dir, output_dir): | ||||
|     os.system('mkdir {}'.format(output_dir)) | ||||
|     os.system('ls -v {}/*.* >> file_list.txt'.format(input_dir)) | ||||
|     os.system('convert @file_list.txt {}/combined.tiff'.format(output_dir)) | ||||
|     os.system('cat "file_list.txt" | xargs rm') | ||||
|     os.system('rm file_list.txt') | ||||
|  | ||||
|  | ||||
| def main(): | ||||
|     args = parse_arguments() | ||||
|     merge_images(args.input_dir, args.output_dir) | ||||
|  | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|     main() | ||||
		Reference in New Issue
	
	Block a user