fitToCanvas

command
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2020 License: MIT Imports: 9 Imported by: 0

README

= fitToCanvas

....
./fitToCanvas [ -infer PAD [-nosquare] [-atleast MINSIZE] | -b BOUND [-by BOUNDY] -c CANVAS [-cy CANVASY]] source destination
....

== Normal mode

`fitToCanvas` performs `images/FitToDimensions` to all images in a folder `source`
where all images will be resized to fit inside a `BOUND` by `BOUNDY` image
and is placed in a `CANVAS` by `CANVASY` image.
If `BOUNDY` and `CANVASY` are not provided,
they will default to `BOUND` and `CANVAS` respectively.

Since otherwise images would be _too_ small,
`BOUND`, `BOUNDY`, `CANVAS`,and `CANVASY`
must be at least 50.

All images will be "converted" and saved into a folder `destination`
with the same filename.

== Inferred mode

Inferred mode is enabled if `-infer` is passed.

Considering that the images parsed may be of different sizes,
inferred mode creates a padding of at least PAD pixels on all sides
but keeps the canvas as a square,
unless if `-nosquare` is passed.

If `-atleast` is passed,
and the photo's size is still less than `MINSIZExMINSIZE`
after being added with padding,
then the canvas becomes `MINSIZExMINSIZE`.

Documentation

Overview

fitToCanvas allows the user to modify photos so that they could have some padding around them. This is done either by making sure a photo is inside some bounded area or by simply adding padding to the image. This command manipulates all the images in a particular source folder and writes all the files in destination. It will ignore all subfolders in source.

Normal mode

Normal mode makes sure each picture is in a grid BOUND pixels wide by BOUNDY pixels high, in the center of a CANVAS pixels wide by CANVASY pixels high PNG image. and will resize the picture if necessary just to be in said bounds. If BOUNDY or CANVASY are not provided, they will take their values from BOUND or CANVAS, thus resulting in a square bound grid or a square canvas image.

The images will be in PNG format with a transparent background. If the image to be opened contains a solid background, it will keep the solid background but will still add the transparent padding.

BOUND, BOUNDY, CANVAS, and CANVASY are uint and must be at least 50. The limit is chosen as images with a smaller bound or canvas size would be ridiculously small. Choosing the bound grid to be larger than the canvas grid may lead to unexpected behavior.

./fitToCanvas -b BOUND [-by BOUNDY] -c CANVAS [-cy CANVASY] source destination

Inferred mode

Inferred mode creates a transparent padding of at least PAD pixels on all sides of an image. The script will invoke Inferred mode if -infer is passed and PAD is not zero. The written images will have equal width and height, unless if -nosquare is passed, which simply adds PAD pixels to all sides.

If -atleast is passed, it will make sure that the written image is at least MINSIZE pixels wide by MINSIZE pixels high, and will write more padding if necessary.

./fitToCanvas -infer PAD [-nosquare] [-atleast MINSIZE] source destination

Errors and glog

The program will terminate execution if it encounters an error, which occurs for several reasons. Some ways to return an error are if the non-flag arguments are too few (missing a source or destination folder?), too many (don't provide multiple folders), if source is not a directory, or if destination cannot be created or is not a directory. Nevertheless, if the program cannot continue, it will produce the stack trace to stdout.

This script uses the Google logging module https://github.com/golang/glog for fine tuned logging. As the script iterates through the source folder, it may encounter files that it could not open:

It prints to Error if it could not write the file to the destination folder.

It prints to Warning if a "file" is actually a directory, if a file cannot be opened, or if a file cannot be parsed as an image.

It prints to Info the stack traces of what it prints to Warning and Error, as well as if an image has been saved.

Note that printing these Errors and Warnings will not result to halting execution. The script will continue reading through the files nevertheless.

Examples

All images should be in a 48x48px bound grid in a 64x64px image:

./fitToCanvas -b 48 -c 64 source destination

All images should have at least 10px of padding and make sure images are at least 64x64px:

./fitToCanvas -infer 10 -atleast 64 source destination

Do the previous command but overwrite the files:

./fitToCanvas -infer 10 -atleast 64 source source

License

fitToCanvas is part of Project Sonchou, which is released under the MIT license. See https://gitlab.com/melancholera/sonchou for more information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL