Im = cv2.imread(orig_file_name, cv2.IMREAD_COLOR) Packer.add_rect(r + args.border * 2, r + args.border * 2, rid=i) # NOTE: you could pick a different packing algo by setting pack_algo=., e.g. Print('found %d files in %s' % (len(files), args.input_dir)) Parser.add_argument('-border', help='Border around images in px', default=2, type=int)įiles = sum(], ) Parser.add_argument('-debug', help='Draw "debug" info', default=False, type=bool) Parser.add_argument('-input_dir', help='Input directory with images', default='./') Parser.add_argument('-output', help='Output image name', default='output.png') Parser.add_argument('-aspect', help='Output image aspect ratio, \Į.g. Parser.add_argument('-width', help='Output image width', default=5200, type=int)
![python imagemagick python imagemagick](https://i.stack.imgur.com/DleuP.png)
Parser = argparse.ArgumentParser(description='Montage creator with rectpack') This is a Python package implementing a few algorithms for rectangle packing, a concrete spatial instance of the classic knapsack problem (NP complete!) from computer science: What if there’s a better way to pack the images?
![python imagemagick python imagemagick](https://i.stack.imgur.com/hdfgs.png)
However we can still see a lot of annoying whitespace on the right. usr/local/bin/mogrify -path $_480h.jpg"Īlready looking much better, but we have little control over the resulting size of the montage, ImageMagick just does its best job at packing everything. First the script that I run: TEMP_DIRECTORY=$(mktemp -d /tmp/montageXXXXXX)
![python imagemagick python imagemagick](https://i.stack.imgur.com/oDkB4.png)
Simply using ImageMagick’s montage it looks something the following. It’s good enough for casual montaging, but it’s definitely suboptimal for packing varying size images.Īll photos from: (thanksgiving%2C-autumn) ImageMagick has a built in Montage creating tool.