Shell script that slices a single image into any number of vertical and horizontal sections. Using ImageMagik convert
#!/bin/bash
IMAGE=$1
IMAGE_W=$2
IMAGE_H=$3
ROWS=$4
COLS=$5
if [ $# -eq 0 ]
then
echo "usage: image width height rows cols"
echo "example: ./slice.sh Sunset.jpg 800 600 16 16"
exit
else
for (( x = 1; x <= COLS; x++ ))
do
for (( y = 1 ; y <= ROWS; y++ ))
do
let CROP_X = `expr $IMAGE_W-IMAGE_W/$x`
let CROP_Y = `expr $IMAGE_H-IMAGE_H/$y`
let CROP_W = `expr $IMAGE_W/$ROWS`
let CROP_H = `expr $IMAGE_H/$COLS`
echo -n "crop ${CROP_W}x${CROP_H}+${CROP_X}+${CROP_Y} result: [${x},${y}]_$IMAGE"
echo ""
convert $IMAGE -crop ${CROP_W}x${CROP_H}+${CROP_X}+${CROP_Y} [${x},${y}]_$IMAGE
done
done
fi
more...
mel notepad with various code snippets
nodes
process selection list
string $select[] = `ls -sl`;
for ( $node in $select ) // process each
{
/* ... */
}
if node exists
string $node = "object";
if ( `objExists $node` )
{
// The node exists
}
regexp
Strip component
string $node = "pCube1.f[2]";
string $no_component = `match "^[^\.]*" $node`;
// Result: "pCube1" //
Extract component or attribute, with ‘.’
string $node = "pCube1.f[2]";
string $component = `match "\\..*" $node`;
// Result: ".f[2]" //
string $nodeAttr = "blinn1.color";
string $attrName = `match "\\..*" $nodeAttr`;
// Result: ".color" //
Extract attribute name, without ‘.’
string $node = "pCube1.f[2]";
string $component = `substitute "^[^.]*\\." $node ""`;
// Result: "f[2]" //
string $nodeAttr = "blinn1.color";
string $attrName = `substitute "^[^.]*\\." $nodeAttr ""`;
// Result: "color" //
Extract parent UI control from full path
string $uiControl = "OptionBoxWindow|formLayout52|formLayout55|button6";
string $uiParent = `substitute "|[^|]*$" $uiControl ""`;
// Result: OptionBoxWindow|formLayout52|formLayout55 //
Strip trailing Line Break (\n), if any.This is useful when processing text input read from a file using fgetline.
string $input = "line\n";
$string $line = `match "^[^(\r\n)]*" $input`;
// Result: "line" //
Extract directory from path.
Keep the trailing slash for ease of use.
string $path = "C:/AW/Maya5.0/bin/maya.exe";
string $dir = `match "^.*/" $path`;
// Result: "C:/AW/Maya5.0/bin/"
Extract file from path
string $path = "C:/AW/Maya5.0/bin/maya.exe";
string $filepart = `match "[^/\\]*$" $path`;
// Result: "maya.exe"
Strip numeric suffix
string $node = "pCube1|pCubeShape223";
string $noSuffix = `match ".*[^0-9]" $node`;
// Result: "pCube1|pCubeShape"
Extract numeric suffix
string $node = "pCube1|pCubeShape223";
string $suffix = `match "[0-9]+$" $node`;
// Result: "223" //
Extract short name of DAG or control path
string $dagPath = "pCube1|pCubeShape223";
string $shortName = `match "[^|]*$" $dagPath`;
// Result: pCubeShape223 //
more references
more...