Compare commits
No commits in common. "cf15edd064b8f1938b45598f82c57f4738db035e" and "56578bdc3e44dc7425a73c1413f4fc27a1d51457" have entirely different histories.
cf15edd064
...
56578bdc3e
|
@ -1 +1 @@
|
|||
*.png
|
||||
testcanvas.png
|
||||
|
|
23
README.md
23
README.md
|
@ -1,23 +0,0 @@
|
|||
# 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,89 +1,15 @@
|
|||
#!/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 4; then
|
||||
printf "Usage: griddle <inputfile> <columns> <rows> <outputfile>\n"
|
||||
if test "$#" -ne 2; then
|
||||
echo "Usage: griddle <inputfile> <outputfile>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
inputfile="$1"
|
||||
if ! test -e "$inputfile"; then
|
||||
printf "Input file %s does not exist.\n" "$inputfile"
|
||||
return 2
|
||||
fi
|
||||
outputfile="$2"
|
||||
|
||||
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"
|
||||
echo "$inputfile" "$outputfile"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
Loading…
Reference in New Issue