Some quick hacks that do the seamless texture splits.
This commit is contained in:
parent
15a2a69ac1
commit
024d5b30e1
3 changed files with 650 additions and 0 deletions
372
magick/position
Normal file
372
magick/position
Normal file
|
@ -0,0 +1,372 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Developed by Fred Weinhaus 2/24/2022 .......... revised 2/24/2022
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# Licensing:
|
||||
#
|
||||
# Copyright © Fred Weinhaus
|
||||
#
|
||||
# My scripts are available free of charge for non-commercial use, ONLY.
|
||||
#
|
||||
# For use of my scripts in commercial (for-profit) environments or
|
||||
# non-free applications, please contact me (Fred Weinhaus) for
|
||||
# licensing arrangements. My email address is fmw at alink dot net.
|
||||
#
|
||||
# If you: 1) redistribute, 2) incorporate any of these scripts into other
|
||||
# free applications or 3) reprogram them in another scripting language,
|
||||
# then you must contact me for permission, especially if the result might
|
||||
# be used in a commercial or for-profit environment.
|
||||
#
|
||||
# My scripts are also subject, in a subordinate manner, to the ImageMagick
|
||||
# license, which can be found at: http://www.imagemagick.org/script/license.php
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
####
|
||||
#
|
||||
# USAGE: position [-m method] [-d direction] [-o offset] [-l leftpt]
|
||||
# [-r rightpt] [-b bcolor] [-f format] [-T trim] infile1 infile2 outfile
|
||||
#
|
||||
# USAGE: position [-h or -help]
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -m method positioning method; choices are: offset or cpoints;
|
||||
# default=offset
|
||||
# -d direction positioning direction; choices are: horizontal or
|
||||
# vertical; default=horizontal
|
||||
# -o offset offset +X+Y values for left/ope edge of second image
|
||||
# relative to right/bottom edge of first image. Used when
|
||||
# method=offset; positive or negative offsets are allowed;
|
||||
# default=+0+0
|
||||
# -l leftpt left (first) image control x,y point; default=0,0
|
||||
# -r rightpt right (second) image control x,y point; default=0,0
|
||||
# -b bcolor background color to fill empty spaces
|
||||
# -f format output color format; choices are: RG, GB, BR or RGB;
|
||||
# default=RGB
|
||||
# -T trim trim output to remove any background fill areas
|
||||
#
|
||||
###
|
||||
#
|
||||
# NAME: POSITION
|
||||
#
|
||||
# PURPOSE: To position one image relative to another image.
|
||||
#
|
||||
# DESCRIPTION: POSITION aligns or offsets one image relative to a another
|
||||
# image. The second image is positioned relative to the first image either
|
||||
# horizontally or vertically. Positioning can be done using X and Y offsets
|
||||
# or by specifying one controll point for each image.
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -m method ... positioning METHOD. The choices are: offset (o) or cpoints (c).
|
||||
# The default=offset.
|
||||
#
|
||||
# -d direction ... positioning DIRECTION. The choices are: horizontal (h) or
|
||||
# vertical (v). The default=horizontal.
|
||||
#
|
||||
# -o offset ... OFFSET +X+Y values for left/top edge of second image relative
|
||||
# to right/bottom edge of first image. This is used when method=offset.
|
||||
# Position X and Y offsets may be either positive or negative. The default=+0+0
|
||||
#
|
||||
# -l leftpt ... LEFT (first) image control x,y POINT. Values are integers>0.
|
||||
# The default=0,0
|
||||
#
|
||||
# -r rightpt ... RIGHT (second) image control x,y POINT. Values are integers>0.
|
||||
# The default=0,0
|
||||
#
|
||||
# -b bcolor ... BGCOLOR is the background color to fill empty spaces. Any
|
||||
# Imagemagick color is allowed. The default=none (transparent)
|
||||
#
|
||||
# -f format ... output color FORMAT; The choices are: RG, GB, BR or RGB.
|
||||
# RGB is the normal color image. RG, for example, is first image in Red and
|
||||
# second image in Green and any overlay will show in yellow (mix of Red and
|
||||
# Green). The default=RGB.
|
||||
#
|
||||
# -T trim ... TRIM output to remove any background fill areas.
|
||||
# Choices are: yes (y) or no (n). The default=no. Background color must be
|
||||
# unique in the image for the trim to work properly.
|
||||
#
|
||||
# LIMITATIONS: TRIM option only works for Imagemagick 7.0.9-0 or higher.
|
||||
#
|
||||
# CAVEAT: No guarantee that this script will work on all platforms,
|
||||
# nor that trapping of inconsistent parameters is complete and
|
||||
# foolproof. Use At Your Own Risk.
|
||||
#
|
||||
######
|
||||
#
|
||||
|
||||
# set default values
|
||||
method="offset" # offset or cpoints
|
||||
direction="horizontal" # horizontal or vertical
|
||||
offset=+0+0 # offset
|
||||
#offset=-90-40 # offset
|
||||
leftpt="0,0" # left image single control point
|
||||
rightpt="0,0" # right image single control point
|
||||
#leftpt="287,49" # left image single control point
|
||||
#rightpt="76,89" # right image single control point
|
||||
bcolor=none # background color
|
||||
format="RGB" # RG or GB or BR or RGB output color format
|
||||
trim="no" # trim output; yes or no
|
||||
|
||||
# set directory for temporary files
|
||||
tmpdir="/tmp"
|
||||
|
||||
# set up functions to report Usage and Usage with Description
|
||||
PROGNAME=`type $0 | awk '{print $3}'` # search for executable on path
|
||||
PROGDIR=`dirname $PROGNAME` # extract directory of program
|
||||
PROGNAME=`basename $PROGNAME` # base name of program
|
||||
usage1()
|
||||
{
|
||||
echo >&2 ""
|
||||
echo >&2 "$PROGNAME:" "$@"
|
||||
sed >&2 -e '1,/^####/d; /^###/g; /^#/!q; s/^#//; s/^ //; 4,$p' "$PROGDIR/$PROGNAME"
|
||||
}
|
||||
usage2()
|
||||
{
|
||||
echo >&2 ""
|
||||
echo >&2 "$PROGNAME:" "$@"
|
||||
sed >&2 -e '1,/^####/d; /^######/g; /^#/!q; s/^#*//; s/^ //; 4,$p' "$PROGDIR/$PROGNAME"
|
||||
}
|
||||
|
||||
|
||||
# function to report error messages
|
||||
errMsg()
|
||||
{
|
||||
echo ""
|
||||
echo $1
|
||||
echo ""
|
||||
usage1
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
# function to test for minus at start of value of second part of option 1 or 2
|
||||
checkMinus()
|
||||
{
|
||||
test=`echo "$1" | grep -c '^-.*$'` # returns 1 if match; 0 otherwise
|
||||
[ $test -eq 1 ] && errMsg "$errorMsg"
|
||||
}
|
||||
|
||||
# test for correct number of arguments and get values
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
# help information
|
||||
echo ""
|
||||
usage2
|
||||
exit 0
|
||||
elif [ $# -gt 19 ]
|
||||
then
|
||||
errMsg "--- TOO MANY ARGUMENTS WERE PROVIDED ---"
|
||||
else
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
# get parameter values
|
||||
case "$1" in
|
||||
-h|-help) # help information
|
||||
echo ""
|
||||
usage2
|
||||
exit 0
|
||||
;;
|
||||
-m) # method
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID METHOD SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
method=`echo "$1" | tr "[:upper:]" "[:lower:]"`
|
||||
case "$method" in
|
||||
offset|o) method="offset" ;;
|
||||
cpoints|c) method="cpoints" ;;
|
||||
*) errMsg "--- METHOD=$method IS AN INVALID VALUE ---"
|
||||
esac
|
||||
;;
|
||||
-d) # direction
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID DIRECTION SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
direction=`echo "$1" | tr "[:upper:]" "[:lower:]"`
|
||||
case "$direction" in
|
||||
horizontal|h) direction="horizontal" ;;
|
||||
vertical|v) direction="vertical" ;;
|
||||
*) errMsg "--- DIRECTION=$direction IS AN INVALID VALUE ---"
|
||||
esac
|
||||
;;
|
||||
-o) # offset
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID OFFSET SPECIFICATION ---"
|
||||
#checkMinus "$1"
|
||||
offset=`expr "$1" : '\([-+][0-9]*[-+][0-9]*\)'`
|
||||
[ "$offset" = "" ] && errMsg "--- OFFSET=$offset IS INVALID ---"
|
||||
;;
|
||||
-l) # leftpt
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID LEFTPT SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
leftpt=`expr "$1" : '\([0-9]*,[0-9]*\)'`
|
||||
[ "$leftpt" = "" ] && errMsg "--- LEFTPT=$leftpt IS INVALID ---"
|
||||
;;
|
||||
-r) # rightpt
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID RIGHTPT SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
rightpt=`expr "$1" : '\([0-9]*,[0-9]*\)'`
|
||||
[ "$rightpt" = "" ] && errMsg "--- RIGHTPT=$rightpt IS INVALID ---"
|
||||
;;
|
||||
-b) # bcolor
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID BCOLOR SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
bcolor="$1"
|
||||
;;
|
||||
-f) # format
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID FORMAT SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
format=`echo "$1" | tr "[:lower:]" "[:upper:]"`
|
||||
case "$format" in
|
||||
RG) ;;
|
||||
GB) ;;
|
||||
BR) ;;
|
||||
RGB) ;;
|
||||
*) errMsg "--- FORMAT=$format IS AN INVALID VALUE ---"
|
||||
esac
|
||||
;;
|
||||
-T) # trim
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID TRIM SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
trim=`echo "$1" | tr "[:upper:]" "[:lower:]"`
|
||||
case "$trim" in
|
||||
yes) ;;
|
||||
no) ;;
|
||||
*) errMsg "--- TRIM=$trim IS AN INVALID VALUE ---"
|
||||
esac
|
||||
;;
|
||||
-) # STDIN and end of arguments
|
||||
break
|
||||
;;
|
||||
-*) # any other - argument
|
||||
errMsg "--- UNKNOWN OPTION ---"
|
||||
;;
|
||||
*) # end of arguments
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift # next option
|
||||
done
|
||||
#
|
||||
# get infiles and outfile
|
||||
infile1="$1"
|
||||
infile2="$2"
|
||||
outfile="$3"
|
||||
fi
|
||||
|
||||
# test that infile1 provided
|
||||
[ "$infile1" = "" ] && errMsg "--- NO INPUT FILE 1 SPECIFIED ---"
|
||||
|
||||
# test that infile2 provided
|
||||
[ "$infile2" = "" ] && errMsg "--- NO INPUT FILE 2 SPECIFIED ---"
|
||||
|
||||
# test that outfile provided
|
||||
[ "$outfile" = "" ] && errMsg "--- NO OUTPUT FILE SPECIFIED ---"
|
||||
|
||||
|
||||
dir="$tmpdir/POSITION.$$"
|
||||
|
||||
mkdir "$dir" || echo "--- FAILED TO CREATE TEMPORARY FILE DIRECTORY ---"
|
||||
trap "rm -rf $dir; exit 0" 0
|
||||
trap "rm -rf $dir; exit 1" 1 2 3 15
|
||||
|
||||
# read input images
|
||||
# test if infile exists, is readable and is not zero size
|
||||
convert -quiet "$infile1" +repage $dir/tmpI1.mpc ||
|
||||
echo "--- FILE $infile1 DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---"
|
||||
|
||||
convert -quiet "$infile2" +repage $dir/tmpI2.mpc ||
|
||||
echo "--- FILE $infile2 DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---"
|
||||
|
||||
# get image1 dimensions
|
||||
ww=`convert $dir/tmpI1.mpc -format "%w" info:`
|
||||
hh=`convert $dir/tmpI1.mpc -format "%h" info:`
|
||||
#echo "ww=$ww; hh=$hh;"
|
||||
|
||||
# get page values for second image
|
||||
if [ "$method" = "cpoints" ]; then
|
||||
lx=`echo "$leftpt" | cut -d, -f1`
|
||||
ly=`echo "$leftpt" | cut -d, -f2`
|
||||
rx=`echo "$rightpt" | cut -d, -f1`
|
||||
ry=`echo "$rightpt" | cut -d, -f2`
|
||||
pagex=$((lx-rx))
|
||||
pagey=$((ly-ry))
|
||||
|
||||
else # offsets
|
||||
xoff=`echo $offset | sed -n 's/^\([+-].*\)[+-].*$/\1/p'`
|
||||
yoff=`echo $offset | sed -n 's/^[+-].*\([+-].*\)$/\1/p'`
|
||||
if [ "$direction" = "horizontal" ]; then
|
||||
pagex=$((ww+xoff))
|
||||
pagey=$((yoff))
|
||||
else
|
||||
# vertical
|
||||
pagex=$((xoff))
|
||||
pagey=$((hh+yoff))
|
||||
fi
|
||||
fi
|
||||
#echo "ww=$ww; hh=$hh; xoff=$xoff; yoff=$yoff; lx=$lx; ly=$ly; rx=$rx; ry=$ry; pagex=$pagex; pagey=$pagey;"
|
||||
|
||||
# set up for trim
|
||||
[ "$trim" = "yes" ] && trimming="-background $bcolor -define trim:percent-background=0% -trim +repage"
|
||||
|
||||
# align the two images
|
||||
if [ "$format" = "RG" ]; then
|
||||
convert \
|
||||
\( $dir/tmpI1.mpc -colorspace gray -set page +0+0 -write mpr:img1 +delete \) \
|
||||
\( $dir/tmpI2.mpc -colorspace gray -set page +${pagex}+${pagey} -write mpr:img2 +delete \) \
|
||||
\( \( mpr:img2 -background black -colorize 100 \) \( mpr:img1 +level-colors "black,red" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
\( \( mpr:img1 -background black -colorize 100 \) \( mpr:img2 +level-colors "black,green1" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
-compose over -compose blend -composite $trimming \
|
||||
"$outfile"
|
||||
|
||||
elif [ "$format" = "GB" ]; then
|
||||
convert \
|
||||
\( $dir/tmpI1.mpc -colorspace gray -set page +0+0 -write mpr:img1 +delete \) \
|
||||
\( $dir/tmpI2.mpc -colorspace gray -set page +${pagex}+${pagey} -write mpr:img2 +delete \) \
|
||||
\( \( mpr:img2 -background black -colorize 100 \) \( mpr:img1 +level-colors "black,green1" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
\( \( mpr:img1 -background black -colorize 100 \) \( mpr:img2 +level-colors "black,blue" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
-compose over -compose blend -composite $trimming \
|
||||
"$outfile"
|
||||
|
||||
elif [ "$format" = "BR" ]; then
|
||||
convert \
|
||||
\( $dir/tmpI1.mpc -colorspace gray -set page +0+0 -write mpr:img1 +delete \) \
|
||||
\( $dir/tmpI2.mpc -colorspace gray -set page +${pagex}+${pagey} -write mpr:img2 +delete \) \
|
||||
\( \( mpr:img2 -background black -colorize 100 \) \( mpr:img1 +level-colors "black,blue" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
\( \( mpr:img1 -background black -colorize 100 \) \( mpr:img2 +level-colors "black,red" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
-compose over -compose blend -composite $trimming \
|
||||
"$outfile"
|
||||
|
||||
else # RGB
|
||||
convert \
|
||||
\( $dir/tmpI1.mpc -set page +0+0 \) \
|
||||
\( $dir/tmpI2.mpc -set page +${pagex}+${pagey} \) \
|
||||
-background "$bcolor" -layers merge +repage $trimming \
|
||||
"$outfile"
|
||||
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
268
magick/splitcrop
Normal file
268
magick/splitcrop
Normal file
|
@ -0,0 +1,268 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Developed by Fred Weinhaus revised 6/9/2012 .......... revised 4/25/2015
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# Licensing:
|
||||
#
|
||||
# Copyright © Fred Weinhaus
|
||||
#
|
||||
# My scripts are available free of charge for non-commercial use, ONLY.
|
||||
#
|
||||
# For use of my scripts in commercial (for-profit) environments or
|
||||
# non-free applications, please contact me (Fred Weinhaus) for
|
||||
# licensing arrangements. My email address is fmw at alink dot net.
|
||||
#
|
||||
# If you: 1) redistribute, 2) incorporate any of these scripts into other
|
||||
# free applications or 3) reprogram them in another scripting language,
|
||||
# then you must contact me for permission, especially if the result might
|
||||
# be used in a commercial or for-profit environment.
|
||||
#
|
||||
# My scripts are also subject, in a subordinate manner, to the ImageMagick
|
||||
# license, which can be found at: http://www.imagemagick.org/script/license.php
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
####
|
||||
#
|
||||
# USAGE: splitcrop [-x xcoord] [-y ycoord] [-L] infile [outfile]
|
||||
# USAGE: splitcrop [-h or -help]
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -x xcoord x coordinate for split; 0<integer<width; default=center
|
||||
# -y xcoord y coordinate for split; 0<integer<height; default=center
|
||||
# -L list crop dimensions and offsets to the terminal
|
||||
#
|
||||
# Note, the output images will be named automatically from the outfile name and
|
||||
# suffix. Two or four of the following: _left, _right, _top, _bottom,
|
||||
# _topleft, _topright, _bottomleft, _bottomright will be appended before the
|
||||
# suffix. If no outfile is provided, then the infile name and suffix will be
|
||||
# used for the output.
|
||||
#
|
||||
###
|
||||
#
|
||||
# NAME: SPLITCROP
|
||||
#
|
||||
# PURPOSE: To crop an image into two or four sections according to the given
|
||||
# x,y coordinates.
|
||||
#
|
||||
# DESCRIPTION: SPLITCROP crops an image into two or four sections according to
|
||||
# the given x,y coordinates. One or both of the x,y coordinates may be
|
||||
# specified. If one coordinate is specified, then the image will be split into
|
||||
# two parts. If two coordinate are specified, then the image will be split both
|
||||
# ways into four parts. Note that these are coordinates and not sizes. The top,
|
||||
# left or topleft section will include the coordinate specified. The size of
|
||||
# the split will be the coordinate plus 1. If the image dimension is odd,
|
||||
# then the top, left or topleft will contain the extra pixel(s).
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -x xcoord ... XCOORD is the x coordinate for the split. Values are
|
||||
# 0<integers<width. The default=center of image
|
||||
#
|
||||
# -y ycoord ... YCOORD is the y coordinate for the split. Values are
|
||||
# 0<integers<height. The default=center of image
|
||||
#
|
||||
# -L ... LIST crop dimensions and offsets to the terminal
|
||||
#
|
||||
# CAVEAT: No guarantee that this script will work on all platforms,
|
||||
# nor that trapping of inconsistent parameters is complete and
|
||||
# foolproof. Use At Your Own Risk.
|
||||
#
|
||||
######
|
||||
#
|
||||
|
||||
# set default values
|
||||
xcoord="" # x coordinate for split
|
||||
ycoord="" # y coordinate for split
|
||||
list="off"
|
||||
|
||||
# set directory for temporary files
|
||||
dir="." # suggestions are dir="." or dir="/tmp"
|
||||
|
||||
# set up functions to report Usage and Usage with Description
|
||||
PROGNAME="splitcrop" # search for executable on path
|
||||
PROGDIR=`dirname $PROGNAME` # extract directory of program
|
||||
PROGNAME=`basename $PROGNAME` # base name of program
|
||||
usage1()
|
||||
{
|
||||
echo >&2 ""
|
||||
echo >&2 "$PROGNAME:" "$@"
|
||||
sed >&2 -e '1,/^####/d; /^###/g; /^#/!q; s/^#//; s/^ //; 4,$p' "$PROGDIR/$PROGNAME"
|
||||
}
|
||||
usage2()
|
||||
{
|
||||
echo >&2 ""
|
||||
echo >&2 "$PROGNAME:" "$@"
|
||||
sed >&2 -e '1,/^####/d; /^######/g; /^#/!q; s/^#*//; s/^ //; 4,$p' "$PROGDIR/$PROGNAME"
|
||||
}
|
||||
|
||||
|
||||
# function to report error messages
|
||||
errMsg()
|
||||
{
|
||||
echo ""
|
||||
echo $1
|
||||
echo ""
|
||||
usage1
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
# function to test for minus at start of value of second part of option 1 or 2
|
||||
checkMinus()
|
||||
{
|
||||
test=`echo "$1" | grep -c '^-.*$'` # returns 1 if match; 0 otherwise
|
||||
[ $test -eq 1 ] && errMsg "$errorMsg"
|
||||
}
|
||||
|
||||
|
||||
# test for correct number of arguments and get values
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
# help information
|
||||
echo ""
|
||||
usage2
|
||||
exit 0
|
||||
elif [ $# -gt 6 ]
|
||||
then
|
||||
errMsg "--- TOO MANY ARGUMENTS WERE PROVIDED ---"
|
||||
else
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
# get parameter values
|
||||
case "$1" in
|
||||
-h|-help) # help information
|
||||
echo ""
|
||||
usage2
|
||||
exit 0
|
||||
;;
|
||||
-x) # get xcoord
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID XCOORD SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
xcoord=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$xcoord" = "" ] && errMsg "--- XCOORD=$xcoord MUST BE A NON-NEGATIVE INTEGER ---"
|
||||
;;
|
||||
-y) # get ycoord
|
||||
shift # to get the neyt parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID YCOORD SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
ycoord=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$ycoord" = "" ] && errMsg "--- YCOORD=$ycoord MUST BE A NON-NEGATIVE INTEGER ---"
|
||||
;;
|
||||
-L) # get list
|
||||
list="on"
|
||||
;;
|
||||
-) # STDIN and end of arguments
|
||||
break
|
||||
;;
|
||||
-*) # any other - argument
|
||||
errMsg "--- UNKNOWN OPTION ---"
|
||||
;;
|
||||
*) # end of arguments
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift # next option
|
||||
done
|
||||
#
|
||||
# get infile and outfile
|
||||
infile="$1"
|
||||
outfile="$2"
|
||||
fi
|
||||
|
||||
# test that infile provided
|
||||
[ "$infile" = "" ] && errMsg "NO INPUT FILE SPECIFIED"
|
||||
|
||||
# test that outfile provided
|
||||
|
||||
if [ "$outfile" = "" ]; then
|
||||
# separate infile to outname and suffix
|
||||
outname=`echo "$infile" | sed -n 's/^\(.*\)[\.].*$/\1/p'`
|
||||
suffix=`echo "$infile" | sed -n 's/^.*[\.]\(.*\)$/\1/p'`
|
||||
else
|
||||
# separate outfile to outname and suffix
|
||||
outname=`echo "$outfile" | sed -n 's/^\(.*\)[\.].*$/\1/p'`
|
||||
suffix=`echo "$outfile" | sed -n 's/^.*[\.]\(.*\)$/\1/p'`
|
||||
fi
|
||||
|
||||
# setup temporary images
|
||||
tmpA1="$dir/split_A_$$.mpc"
|
||||
tmpA2="$dir/split_A_$$.cache"
|
||||
trap "rm -f $tmpA1 $tmpA2;" 0
|
||||
trap "rm -f $tmpA1 $tmpA2; exit 1" 1 2 3 15
|
||||
trap "rm -f $tmpA1 $tmpA2; exit 1" ERR
|
||||
|
||||
|
||||
# read the input image into the temporary cached image and test if valid
|
||||
convert -quiet "$infile" +repage "$tmpA1" ||
|
||||
errMsg "--- FILE $infile DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO size ---"
|
||||
|
||||
|
||||
# get input dimensions
|
||||
ww=`convert $tmpA1 -format "%w" info:`
|
||||
hh=`convert $tmpA1 -format "%h" info:`
|
||||
#echo "ww=$ww; hh=$hh"
|
||||
|
||||
x=$xcoord
|
||||
y=$ycoord
|
||||
|
||||
# trap for no coordinates specified
|
||||
if [ "$x" = "" -a "$y" = "" ]; then
|
||||
x=`convert xc: -format "%[fx:round($ww/2)-1]" info:`
|
||||
y=`convert xc: -format "%[fx:round($hh/2)-1]" info:`
|
||||
fi
|
||||
|
||||
# trap for coordinates at boundary or outside image
|
||||
if [ "$x" != "" ]; then
|
||||
( [ $x -eq 0 ] || [ $x -ge $ww ] ) && errMsg "--- INVALID X COORDINATE SPECIFIED ---"
|
||||
fi
|
||||
if [ "$y" != "" ]; then
|
||||
( [ $y -eq 0 ] || [ $y -ge $ww ] ) && errMsg "--- INVALID Y COORDINATE SPECIFIED ---"
|
||||
fi
|
||||
|
||||
# options depending upon whether x or y or (x and y) specified
|
||||
if [ "$x" != "" -a "$y" != "" ]; then
|
||||
#split into four parts
|
||||
tlsize=`convert xc: -format "%[fx:$x+1]x%[fx:$y+1]+0+0" info:`
|
||||
trsize=`convert xc: -format "%[fx:$ww-$x-1]x%[fx:$y+1]+%[fx:$x+1]+0" info:`
|
||||
blsize=`convert xc: -format "%[fx:$x+1]x%[fx:$hh-$y-1]+0+%[fx:$y+1]" info:`
|
||||
brsize=`convert xc: -format "%[fx:$ww-$x-1]x%[fx:$hh-$y-1]+%[fx:$x+1]+%[fx:$y+1]" info:`
|
||||
if [ "$list" = "on" ]; then
|
||||
echo "tlsize=$tlsize"
|
||||
echo "trsize=$trsize"
|
||||
echo "blsize=$blsize"
|
||||
echo "brsize=$brsize"
|
||||
fi
|
||||
convert $tmpA1 -crop $tlsize +repage "${outname}_topleft.$suffix"
|
||||
convert $tmpA1 -crop $trsize +repage "${outname}_topright.$suffix"
|
||||
convert $tmpA1 -crop $blsize +repage "${outname}_bottomleft.$suffix"
|
||||
convert $tmpA1 -crop $brsize +repage "${outname}_bottomright.$suffix"
|
||||
elif [ "$x" != "" ]; then
|
||||
#split into two parts horizontally
|
||||
lsize=`convert xc: -format "%[fx:$x+1]x${hh}+0+0" info:`
|
||||
rsize=`convert xc: -format "%[fx:$ww-$x-1]x${hh}+%[fx:$x+1]+0" info:`
|
||||
if [ "$list" = "on" ]; then
|
||||
echo "lsize=$lsize"
|
||||
echo "rsize=$rsize"
|
||||
fi
|
||||
convert $tmpA1 -crop $lsize +repage "${outname}_left.$suffix"
|
||||
convert $tmpA1 -crop $rsize +repage "${outname}_right.$suffix"
|
||||
elif [ "$y" != "" ]; then
|
||||
#split into two parts vertically
|
||||
tsize=`convert xc: -format "${ww}x%[fx:$y+1]+0+0" info:`
|
||||
bsize=`convert xc: -format "${ww}x%[fx:$hh-$y-1]+0+%[fx:$y+1]" info:`
|
||||
if [ "$list" = "on" ]; then
|
||||
echo "tsize=$tsize"
|
||||
echo "bsize=$bsize"
|
||||
fi
|
||||
convert $tmpA1 -crop $tsize +repage "${outname}_top.$suffix"
|
||||
convert $tmpA1 -crop $bsize +repage "${outname}_bottom.$suffix"
|
||||
fi
|
||||
|
||||
exit 0
|
10
magick/texture_setup.sh
Normal file
10
magick/texture_setup.sh
Normal file
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
./splitcrop -x $1 -y $1 $2 corners.png
|
||||
|
||||
./position -d horizontal corners_bottomright.png corners_bottomleft.png bottom.png
|
||||
|
||||
./position -d horizontal corners_topright.png corners_topleft.png top.png
|
||||
|
||||
./position -d vertical bottom.png top.png result-grid.png
|
Loading…
Add table
Add a link
Reference in a new issue