1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
package require Img
package require img::raw
# Red Green Blue Cyan Magenta Yellow Magenta Black White
set colorList {
"#FF0000"
"#00FF00"
"#0000FF"
"#00FFFF"
"#FF00FF"
"#FFFF00"
"#000000"
"#FFFFFF"
}
set wr 5
set hr 7
set h $hr
set w [expr $wr * [llength $colorList]]
set xres [expr $w * 2]
set yres [expr $h * 2]
set fmtList [list \
"img" "bmp" ".bmp" "" \
"img" "gif" ".gif" "" \
"img" "ico" ".ico" "" \
"img" "jpeg" ".jpg" "" \
"img" "pcx" ".pcx" "" \
"img" "png" ".png" "" \
"img" "ppm" ".ppm" "" \
"img" "raw" ".raw" "-useheader true -nchan 3" \
"img" "sgi" ".rgb" "" \
"img" "sun" ".ras" "" \
"img" "tga" ".tga" "" \
"img" "tiff" ".tif" "" \
"img" "xbm" ".xbm" "" \
"img" "xpm" ".xpm" "" \
"dpi" "bmp" ".bmp" "-xresolution $xres -yresolution $yres" \
"dpi" "jpeg" ".jpg" "-xresolution $xres -yresolution $yres" \
"dpi" "pcx" ".pcx" "-xresolution $xres -yresolution $yres" \
"dpi" "png" ".png" "-xresolution $xres -yresolution $yres" \
"dpi" "tiff" ".tif" "-xresolution $xres -yresolution $yres" \
]
proc DrawBmpRect { img xs ys w h mask } {
set scanline [list]
for { set x 0 } { $x < $w } { incr x } {
for { set y 0 } { $y < $h } { incr y } {
$img put "#FFFFFF" -to [expr $xs + $x] [expr $ys + $y]
$img transparency set [expr $xs + $x] [expr $ys + $y] $mask
}
}
}
proc DrawPhotoRect { img xs ys w h color } {
set scanline [list]
for { set x 0 } { $x < $w } { incr x } {
lappend scanline $color
}
set data [list]
lappend data $scanline
for { set y 0 } { $y < $h } { incr y } {
$img put $data -to $xs [expr $ys + $y]
}
}
set photo [image create photo -width $w -height $h]
set bmp [image create photo -width $w -height $h]
set x 0
set y 0
foreach color $colorList {
DrawPhotoRect $photo $x $y $wr $hr $color
set x [expr $x + $wr]
}
set x 0
set y 0
set mask false
foreach color $colorList {
DrawBmpRect $bmp $x $y $wr $hr $mask
set x [expr $x + $wr]
set mask [expr ! $mask]
}
foreach { name fmt ext opt } $fmtList {
set fileName "testimgs/$name$ext"
puts "Generate image $fileName"
if { $fmt eq "xbm" } {
$bmp write $fileName -format $fmt
} else {
$photo write $fileName -format "$fmt $opt"
}
}
set fileName "testimgs/img2.jpg"
image create photo jpg2 -file "testimgs/img.jpg"
puts "Generate image $fileName"
jpg2 write $fileName -format jpeg
set fileName "testimgs/img.jp2"
puts "Generate image $fileName"
file copy -force "sourceimgs/img.jp2" $fileName
set fileName "testimgs/img.dt0"
puts "Generate image $fileName"
file copy -force "sourceimgs/e10n48.dt0" $fileName
set fileName "testimgs/img.fpf"
puts "Generate image $fileName"
file copy -force "sourceimgs/example1.fpf" $fileName
set fileName "testimgs/img.svg"
puts "Generate image $fileName"
file copy -force "sourceimgs/img.svg" $fileName
# Create PostScript file.
set fileName "testimgs/img.ps"
puts "Generate image $fileName"
canvas .c -borderwidth 0 -highlightthickness 0 -width $w -height $h
.c create image 0 0 -image $photo -anchor nw
pack .c
update
.c postscript -file $fileName -height $h -width $w -pageanchor nw -pagewidth 40 -pagex 40 -pagey 7
# Replace line specifying BoundingBox manually with the following values:
# %%BoundingBox: 40 0 80 7
# Create PDF file.
# PDF file img.pdf was created manually using IrfanView.
exit 0
|