Compare commits

..

10 Commits

3 changed files with 102 additions and 5 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
testcanvas.png *.png

23
README.md Normal file
View File

@ -0,0 +1,23 @@
# griddle
`griddle` is a program for practicing drawing using the [Grid Technique](https://www.art-is-fun.com/grid-method).
It takes an input image and uses [ImageMagick](https://imagemagick.org) to automatically draw a grid (of specified dimensions) over it.
## Installation
`griddle` is a shell script; you can copy it to somewhere in your `$PATH` or just clone the repository and execute it.
## Usage
The CLI interface for `griddle` is `griddle <inputfile> <number_of_columns> <number_of_rows> <outputfile>`.
This is the number of **columns** and **rows**, not the number of separators.
For example, specifying "2" columns will result in **one** line splitting the image vertically.
Border lines around the edge of the image are always generated.
It supports any input and output file formats that ImageMagick supports.
The input and output files don't need to be the same format; you can input a PNG and output a JPEG, for example.
## Planned Features
- Generate an additional output image (or PDF?) containing a blank copy of just the generated grid which can be printed out, to save the effort of manually recreating the grid on your drawing paper.
- Improve the CLI interface with `--options` to remove the arbitrary ordering of `<number_of_columns>` and `<number_of_rows>`.
- Make border lines optional.
- Allow the user to adjust the color and transparency of grid lines.
- Add a default output filename (something like `<inputfilename>_grid.<inputextension>`) if no output filename is explicitly given.

82
griddle
View File

@ -1,15 +1,89 @@
#!/bin/sh #!/bin/sh
set -e
WIDTH=1
HEIGHT=2
get_image_dimension() {
inputfile="$1"
dimension="$2"
height="$(identify $inputfile | cut -d ' ' -f 3 | cut -d 'x' -f $dimension)"
printf "%s" "$height"
}
generate_lines() {
columns="$1"
rows="$2"
width="$3"
height="$4"
# Generate border lines
border_width=$((width - 1))
border_height=$((height - 1))
printf "line 0, 0 0, %d " $border_height
printf "line 0, 0 %d, 0 " $border_width
printf "line 0, %d %d, %d " $border_height $border_width $border_height
printf "line %d, 0 %d, %d " $border_width $border_width $border_height
# Generate column separators
colwidth=$((width / columns))
for i in $(seq 1 $columns); do
current_colwidth=$((colwidth * i))
printf "line %d, 0 %d, %d " $current_colwidth $current_colwidth $height
done
# Generate row separators
rowheight=$((height / rows))
for i in $(seq 1 $rows); do
current_rowheight=$((rowheight * i))
printf "line 0, %d %d, %d " $current_rowheight $width $current_rowheight
done
}
create_image() {
inputfile="$1"
lines="$2"
outputfile="$3"
convert -draw "$lines" "$inputfile" "$outputfile"
}
main() { main() {
if test "$#" -ne 2; then if test "$#" -ne 4; then
echo "Usage: griddle <inputfile> <outputfile>" printf "Usage: griddle <inputfile> <columns> <rows> <outputfile>\n"
return 1 return 1
fi fi
inputfile="$1" inputfile="$1"
outputfile="$2" if ! test -e "$inputfile"; then
printf "Input file %s does not exist.\n" "$inputfile"
return 2
fi
echo "$inputfile" "$outputfile" columns="$2"
rows="$3"
outputfile="$4"
if test -e "$outputfile"; then
printf "Output file $outputfile already exists. Overwrite? (y/N) "
read response
if ! test "$response" = "y" -o "$response" = "Y"; then
printf "Not overwriting $outputfile.\n"
return 0
else
printf "Overwriting $outputfile.\n"
fi
fi
width="$(get_image_dimension $inputfile $WIDTH)"
height="$(get_image_dimension $inputfile $HEIGHT)"
lines="$(generate_lines $columns $rows $width $height)"
create_image "$inputfile" "$lines" "$outputfile"
} }
main "$@" main "$@"