Skip to content

Commit

Permalink
Merge pull request #8 from soeren-kirchner/feature/project-file-support
Browse files Browse the repository at this point in the history
Feature/project file support
  • Loading branch information
soeren-kirchner authored Nov 9, 2019
2 parents 2905eb6 + cdb8711 commit d916160
Show file tree
Hide file tree
Showing 111 changed files with 20,065 additions and 361 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ share/python-wheels/
MANIFEST

# Sphinx documentation
docs/_build/
docsrc/_build/

# vscode
.vscode/
Expand All @@ -35,3 +35,5 @@ docs/_build/
examples/**/dest
pyimgbatch.log

# private playground
playground/
139 changes: 125 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,154 @@

PyImgBatch is a batch image processor for python including a command line interface.

## Installation
For installation open a terminal and type the following line into the command line.

## Usage
```
pip install pyimgbatch
```

## Usage on command line

The simplest usage is to change to the folder containing the images with

```
cd /folder/wit/images
```
and type

```
pyimgbatch --width 300
```
This will resize all supported image files in the current folder to a width of 300 pixels respecting the aspect ratio of the source file. The results will be written to a "dest" subfolder.

pyimgbatch -s source_folder -d destination_folder -c configfile
Alternatively, you can set a source folder with the images to be converted and/or a destination folder for the results as follow.

```
pyimgbatch --source source_folder --dest destination_folder --height 400
```
or shorter
```
pyimgbatch -s source_folder -d destination_folder --height 400
```
This will convert the images from the *source_folder* to a height of 400px and stores the results in the destination folder.
*Note: For every source image a subfolder will be created inside the destination_folder. To avoid this behavior use the --nosubfolder argument.*

- *source_folder* -
Folder containing the images to be processed (resized, color mode changed ...)
## Project Files
One of PyImgBatch features is to create multiple different versions from given image files.

- *destination_folder* -
Target for the converted Images.
For this, you can use project files. Project files are JSON files containing the specifications for the image processing.

- *config_file* -
A simple json file containing the settings for the processed files
### The very short one

Here an example of a very short one.

```json
[
{ "width": 1000, "suffix": ".w1000" },
{ "height": 1200, "suffix": ".h1200" }
]
```
For example:
For example (may the project named "myprj.json"):
```
pyimgbatch -s source -d dest -c config_samples/imagebatch_simple2.json
pyimgbatch -c myprj.json
```
produces the following output:
```
progressing: french-bulldog-4530685.jpg
processing: french-bulldog-4530685.jpg
creating: french-bulldog-4530685.w1000.jpg
creating: french-bulldog-4530685.h1200.jpg
progressing: coast-4478424.jpg
processing: coast-4478424.jpg
creating: coast-4478424.w1000.jpg
creating: coast-4478424.h1200.jpg
...
pprogressing: beaded-2137080_1920-cmyk-iso-eci.tif
processing: beaded-2137080_1920-cmyk-iso-eci.tif
creating: beaded-2137080_1920-cmyk-iso-eci.w1000.jpg
creating: beaded-2137080_1920-cmyk-iso-eci.h1200.jpg
...
```
and creates two images per source images, resized to the specified width or height with suffix added to the original name.
and creates two images per source images, resized to the specified width or height with suffix added to the original name.

### The short one

Imagine, you need to create different sizes for all your images for your web project. For instance, you need the images in widths 180px, 300px, 400px and one in a height of 800 and each 2x and 3x the size for higher pixel density display like in smartphones.
An example could look as follow.

```JSON
{
"name": "web set",
"comment": "some sample pictures",
"source": "webset/source",
"dest": "webset/dest",
"prefix": "web.",
"configs": [
{ "width": 180, "suffix": ".w180", "webset": "@3x" },
{ "width": 300, "suffix": ".w300", "webset": "@3x" },
{ "width": 400, "suffix": ".w400", "webset": "@3x" },
{ "height": 800, "prefix": "preview.", "webset": "@3x" }
]
}
```
This will create 12 destination images for each imput image. For a image "lama-4540160.jpg" you get:

```
...
creating: lama-4540160/[email protected]
creating: lama-4540160/[email protected]
creating: lama-4540160/[email protected]
creating: lama-4540160/[email protected]
creating: lama-4540160/[email protected]
creating: lama-4540160/[email protected]
creating: lama-4540160/[email protected]
creating: lama-4540160/[email protected]
creating: lama-4540160/[email protected]
creating: lama-4540160/[email protected]
creating: lama-4540160/[email protected]
creating: lama-4540160/[email protected]
...
```

As you see you can specify defaults, so you don't need to repeat yourself.
The more specific option is used instead of the more general one. So in this example, all images get the prefix "web." except the last, because the more specific prefix is here given as "preview."

*Hint: The file names are a little strange because I've downloaded the from the free image stock [pixabay](https://pixabay.com) and I haven't changed the Name so you can search for the pics or the photographer if you want.*

### Full image project file

looks as follow.

```JSON
{
"comment": "pyImgBatch demo project",
"debug": true,
"no-progess": false,
"projects": [
{
"name": "web set",
"comment": "some sample pictures",
"source": "webset/source",
"dest": "webset/dest",
"prefix": "web.",
"configs": [
{ "width": 180, "suffix": ".w180", "webset": "@3x" },
{ "width": 300, "suffix": ".w300", "webset": "@3x" },
{ "width": 400, "suffix": ".w400", "webset": "@3x" },
{ "height": 800, "prefix": "preview.", "webset": "@3x" }
]
},
{
"name": "images to thumbnails",
"source": "to-thumbnails/originals",
"dest": "to-thumbnails/thumbnails",
"subfolder": false,
"prefix": "thumb.",
"configs": [
{"height": 300},
{"prefix": "smallthumb.", "height": 200}
]
}
]
}
```

This project contains two projects.
4 changes: 4 additions & 0 deletions docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: c04d496af9e683ca3dbd4c94361ef2c7
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file added docs/.doctrees/environment.pickle
Binary file not shown.
Binary file added docs/.doctrees/index.doctree
Binary file not shown.
Empty file added docs/.nojekyll
Empty file.
25 changes: 25 additions & 0 deletions docs/_sources/index.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. PyImgBatch documentation master file, created by
sphinx-quickstart on Sun Oct 13 20:20:09 2019.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to PyImgBatch's documentation!
======================================



.. toctree::
:maxdepth: 2
:caption: Contents:

quickstart
tutorials
parameters
pyimgbatch

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
14 changes: 14 additions & 0 deletions docs/_sources/parameters.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Parameters
==========

List of **pyimgbatch** project file parameters. The content of the square brackets shows the command line equivalent.

:width [-\\-width]: **Width** of the destination image. If the **width** is not given, it calculateted on the height.
If neither the width nor the height are given, the width and the height of the source image will be used.

:height [-\\-height]: **Height** of the destination image. If the **height** is not given, it calculateted on the height.
If neither the width nor the height are given, the width and the height of the source image will be used.

:resample [-\\-resample]: defines the resample mode on resizing the image. Possible values are
"none", "bilinear", "bicubic", "hamming", "box" or "antialias".
If there is no resample mode is given or the given resample mode is unknown, it defaults to "antialias"
5 changes: 5 additions & 0 deletions docs/_sources/pyimgbatch.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PyImgBatch
==========

.. automodule:: pyimgbatch
:members:
Loading

0 comments on commit d916160

Please sign in to comment.