Giter VIP home page Giter VIP logo

twilsonco / pyphotocollage Goto Github PK

View Code? Open in Web Editor NEW
20.0 4.0 6.0 52.58 MB

CLI, Pythonista (iOS App), and Siri Shortcut to combine 3 or more images into a collage, maintaining image aspect ratios and distributing images evenly over collage rows.

Home Page: https://routinehub.co/shortcut/17870/

License: MIT License

Python 100.00%
python python-3 pythonista-ios pythonista pythonista3 pythonista-scripts collage collage-maker pillow pil

pyphotocollage's Introduction

title image

PyPhotoCollage

Combines 3 or more images into a collage, maintaining image aspect ratios and distributing images evenly.

Dissatisfied with the Siri Shortcuts image gridding capability, I wanted a photo collage tool that can distribute images evenly. It grew into the current utility.

After looking around, the idea for this tool came from Johannes Treitz's blog post (which no longer exists...). The problem is reduced to the partition problem, for which I used this SO implementation. Main function was modified (significantly) from delimitry's collage_maker.

aspect ratio and image ordering collage type and nesting collage spacing and corner rounding image rotation

Notes for Pythonista and Siri Shortcut versions

  • Photo collage can crash if too much memory is used
  • If this happens, use the included "Preprocess images" utility to downscale images to a smaller size, then rerun Photo collage
  • It will also run faster if preprocessing is done first
  • Can run by sharing images from the Share Sheet (works better with Siri Shortcut; Pythonista version makes you reselect images)

share sheet

Pythonista version for iPhone/iPad/Apple Silicon Mac

  • Takes no arguments.
  • Options are specified by the user when run.
  • Simply place in the app, locally or though iCloud.
  • If you want to run it from e.g. iOS Shortcuts, you'll need to store it locally.
  • If you want to run it from the Share Sheet, you'll need to add it to the Pythonista extension (see image below)
    • Due to limitations in Pythonista, starting Photo collage from the share sheet will not pass through the selected images; you'll need to reselect them
    • It crashes when more than a handful of images are passed via the share sheet, so I had to revert that functionality

Pythonista interface

Pythonista Share Sheet setup

  • PyPhotoCollage is also implemented as a vanilla Siri Shortcut that runs on Mac/iPhone/iPad
  • Has all the same options and capabilities
  • It's slow compared to the Python version; very slow

Siri Shortcut interface

Mac/PC CLI version

Requirements

  • Python3
  • PIL (Pillow)

Usage

usage: PhotoCollage.py [-h] [-f FOLDER] [-R] [-F FILE] [-o OUTPUT] [-t COLLAGE_TYPE] [-O ORDER] [-S MAX_SIZE] [-r TARGET_ASPECT_RATIO] [-g IMAGEGAP] [-m ROUND_IMAGE_CORNERS_PERC]
                       [-M ROUND_COLLAGE_CORNERS_PERC] [-b BACKGROUND] [-c COUNT] [-a] [-i INIT_SIZE] [-N MAX_RECURSION_DEPTH] [-s]
                       [files ...]

Photo collage maker

positional arguments:
  files

options:
  -h, --help            show this help message and exit
  -f FOLDER, --folder FOLDER
                        folder with 3 or more images (*.jpg, *.jpeg, *.png)
  -R, --recurse-input-folder
                        recurse into subfolders of input folder
  -F FILE, --file FILE  file with newline separated list of 3 or more files
  -o OUTPUT, --output OUTPUT
                        output collage image filename
  -t COLLAGE_TYPE, --collage-type COLLAGE_TYPE
                        collage type (default: nested; possible: nested, row, column)
  -O ORDER, --order ORDER
                        order of images (default: input_order; possible: filename, random, oldest_first, newest_first, input)
  -S MAX_SIZE, --max_collage_size MAX_SIZE
                        cap the longest edge (width or height) of resulting collage
  -r TARGET_ASPECT_RATIO, --target-aspect-ratio TARGET_ASPECT_RATIO
                        target aspect ratio for collage
  -g IMAGEGAP, --gap-between-images IMAGEGAP
                        number of pixels of transparent space (if saving as png file; otherwise black or specified background color) to add between neighboring images
  -m ROUND_IMAGE_CORNERS_PERC, --round-image-corners-perc ROUND_IMAGE_CORNERS_PERC
                        percentage of shortest image edge to use as radius for rounding image corners (0.0 to 100.0)
  -M ROUND_COLLAGE_CORNERS_PERC, --round-collage-corners-perc ROUND_COLLAGE_CORNERS_PERC
                        percentage of shortest collage edge to use as radius for rounding collage corners (0.0 to 100.0)
  -b BACKGROUND, --background-color BACKGROUND
                        color (r,g,b) to use for background if spacing is added between images
  -c COUNT, --count COUNT
                        count of images to use, if fewer are desired than those specified or contained in the specified folder
  -a, --no-no_antialias-when-resizing
                        for performance, disable antialiasing on intermediate resizing of images (runs faster but output image looks worse; final resize is always antialiased)
  -i INIT_SIZE, --init-image-size INIT_SIZE
                        to derease necessary memory, resize images on input to set longest edge length
  -N MAX_RECURSION_DEPTH, --max-nested-collage-depth MAX_RECURSION_DEPTH
                        maximum number of levels of nesting. The more levels there are, the larger the size difference will be between the smallest and largest images in the
                        resulting collage (default: 2)
  -s, --show-recursion-depth
                        show recursion depth by adding border to images

pyphotocollage's People

Contributors

kpg-anon avatar t1ml3arn avatar twilsonco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pyphotocollage's Issues

Multi-row images

Just thinking out loud.

One method could be:

  1. given a photo p that will be on m rows
  2. pass multiple pointers to p's width (p.width * m) to the linear_partition function
  3. if the pointers end up on separate rows then as long as they're far-left or far-right in the row, the rest of the row will fit in perfectly

This is nice, but restricts p to the left or right columns.

If you instead

decided where p goes ahead of time, you could populate the remaining portion of the affected rows using more calls to linear_partition.
But this means that you need to know something about the resulting width of the collage, which currently is undetermined (it's the minimum width of any of the rows output by linear_partition).

The collage aspect ratio is somewhat predictable (it's very close to the average aspect ratio of the images).
If I took the total width then I could used the average aspect ratio to approximate the resulting width of the collage, which then allows me to know the width of p when on multiple rows as well as the widths of the new subrows to the left and right of p.

That second one might work

Now I just need to do it.

Unable to get better resolution of images for PhotoCollage.py

First of, I really appreciate the work yo have done. It works great.
The only issue I have is with the resolution.
I have tried setting the image sizes in the arguments to very large values, but nothing seems to increase the resolution of the images in the collage. Delimitry's collage_maker produced a higher quality image.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.