Compare commits
10 Commits
56578bdc3e
...
cf15edd064
Author | SHA1 | Date |
---|---|---|
The Magician | cf15edd064 | |
The Magician | b87abe46c3 | |
The Magician | 72461058ed | |
The Magician | 823513e474 | |
The Magician | db78301f80 | |
The Magician | 26d0e38bec | |
The Magician | c5be149197 | |
The Magician | e05ad2c262 | |
The Magician | cc18a6cdf1 | |
The Magician | 54b22aa38f |
|
@ -1 +1 @@
|
|||
testcanvas.png
|
||||
*.png
|
||||
|
|
|
@ -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
82
griddle
|
@ -1,15 +1,89 @@
|
|||
#!/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() {
|
||||
if test "$#" -ne 2; then
|
||||
echo "Usage: griddle <inputfile> <outputfile>"
|
||||
if test "$#" -ne 4; then
|
||||
printf "Usage: griddle <inputfile> <columns> <rows> <outputfile>\n"
|
||||
return 1
|
||||
fi
|
||||
|
||||
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 "$@"
|
||||
|
|
Loading…
Reference in New Issue