I needed a quick and easy way to make image strips.
package require Tk
proc CombineImages {width height output_name image_names} {
set fullwidth [expr {[llength $image_names] * $width}]
set img_tar [image create photo -height $height -width $fullwidth]
set img_ndx 0
foreach image_name $image_names {
set img_in [image create photo -file $image_name]
set dest_x [expr $img_ndx * $width]
set dest_x2 [expr $dest_x + $width]
$img_tar copy $img_in -to $dest_x 0 $dest_x2 $height
image delete $img_in
incr img_ndx
}
$img_tar write $output_name
}
# Example usage:
CombineImages 16 16 battleship.gif [list stearn_norm.gif mid1_norm.gif mid2_norm.gif bow_norm.gif \
stearn_dead.gif mid_dead.gif bow_dead.gif \
hit.gif miss.gif]
Note: As-is, this code will only make strips. A few changes could turn it into a big 2d map maker.
This will be very handy for anyone wanting to write games or place there tool-bar icons into strips.
A nice utility is just a few lines. Yet another example of the power and ease of our un-cool language.