programming image creator in tcl

programming image creator in tcl

Post by francois.s » Wed, 07 May 2008 01:14:13

Hello,

I only need to create or to edit a simple image with a uniform
background color and some text or other simple images added on.

I know that such programs already exist like ImageMagick but it seems
a little bit too complete to me.

what are the librairies that I will need?

 
 
 

programming image creator in tcl

Post by Neil Madde » Wed, 07 May 2008 01:45:56


Depends what format image you want. You could probably do quite well
with the Tk canvas for creating the graphics and then export to
postscript (which can then be converted to other formats). You might
also want to check out the Img extension that adds support for a variety
of different image formats (jpeg, png etc).

There is also a TclMagick extension...

-- Neil

 
 
 

programming image creator in tcl

Post by George Pet » Wed, 07 May 2008 08:38:57


You should checkout megaimage and the tools relating to it. You can use
megaimage from Tcl (without Tk), and it has companion extensions for
encoding/decoding JPEG and PNG images.

Sources:
http://www.yqcomputer.com/ ~georgeps/implementation/software/megapkg/megapkg_common-1.1.tar.bz2
Win32 .dll files built in Ubuntu with a MinGW cross compiler:
http://www.yqcomputer.com/ ~georgeps/implementation/software/megapkg/megapkg_common-1.1_winbuild.tar.bz2


See the demos/ directory. For the text you can use the freetypeext with
a TTF font to create text buffers for use with megaimage.


That tarball lacks the freetypeext demos, so here's a sample:

set fontid [freetype-file-font /path/to/Font.ttf 14]

#The list is used for the RGBA color
set fbuf [freetype $fontid "Hello World" [list 255 255 255 255] width height]

set mobj [megaimage-blank 400 400]
$mobj rectangle 10 10 380 380 [list 127 127 127 255]

#We blend with the background so that the antialiased text looks good
$mobj blend 30 30 $fbuf

set fd [open output.png w]
fconfigure $fd -translation binary
puts -nonewline $fd [pngext2:encode [$mobj getdata]]
close $fd
rename $mobj {}; #cleanup


George
 
 
 

programming image creator in tcl

Post by francois.s » Wed, 07 May 2008 17:56:09

thank you, it should help me a lot.

I already knew for TclMagick, you need ImageMagick to make it works,
isn't it?

The megaimage solution seems to be (very) close to what I am searching
for, so I will keep it in mind.

More precisely, I want to code a program that can create an image with
a background color and a text. And I want to create copies of this
image that are different of background color and/or of text attributes
(not the text itself, but its fontsize, its fontcolor, ...) by
applying a pre-defined model.

For instance, an image with white background and un text in black, I
want to create copies of it, one with green background and same text
attributes, another with red background and white font color, and so
on...

fs
 
 
 

programming image creator in tcl

Post by Eric Hasso » Thu, 08 May 2008 00:10:55


XXXX@XXXXX.COM a rit :

Hello,

Here is an example using Pixane extension (no dependencies on system).

http://www.yqcomputer.com/

# Load package first of all
package require pixane

# Generate list of colors for tests
set colors [list]
foreach r {0 255} {
foreach g {0 255} {
foreach b {0 255} {
lappend colors [format "\#%02x%02x%02x" $r $g $b]
}
}
}

# Load font. Fonts can be defined either from a truetype font
# (-file or -data), or one may use builtin fonts
set fnt [pixfont create -builtin "serif"]

# Generate images for all combinaisons
set bgid 0
foreach bg $colors {
incr bgid

set fgid 0
foreach fg $colors {
incr fgid

if {$bg eq $fg} continue

# Create image
set p [pixane create]
# Resize
pixane resize $p 64 32

# Fill background
pixane compose $p replace
pixane color $p $bg
pixane fill $p

# Draw text
pixane compose $p over
pixane color $p $fg
pixane text $p 32 24 \
-font $fnt -size 20 \
-align center -valign baseline \
-text "Hello"

# Save as PNG (also supports GIF, BMP, JPG, ...)
pixane save $p -file "i_${bgid}_${fgid}.png" -format png

# Clean up
pixane delete $p
}
}

Eric

-----
Eric Hassold
Evolane - http://www.yqcomputer.com/
 
 
 

programming image creator in tcl

Post by francois.s » Thu, 08 May 2008 16:09:18


> ttp://www.evolane.com/software/pixane/index.html >> >> # Load package first of all >> package require pixane >> >> # Generate list of colors for tests >> set colors [list] >> foreach r {0 255} { >> oreach g {0 255} {> > oreach b {0 255}>{
> append colors [format "\#%02x%02x%02x" $r $> $b]
>>> >>> >> > }
>
> # Load font. Fonts can be defined either from a truet>pe font
> # (-file or -data), or one may use built>n fonts
> set fnt [pixfont create -builtin >se>if"]
>
> # Generate images for all comb>naisons
> se> bgid 0
> foreach bg $>olors {
> gt;nc> bgid
>
> gt;et fgid 0
> oreach f> $colors {
> gt;>incr fgid
>
> f {$bg eq>$f>} ontinue
>
> gt; Create image
> >t p [pixane c>eate]
> Resize
> > gt;ixane resize $p 64 32 >>
> Fill background
> > ixane compose $p rep>ace
> ixane c>lo> $p $bg
> gt;ixane fill $p
>
> D>aw text
> ixane co>pose $p over
> ixane >olor $p $fg
> ixane t>xt $p 32 24 \
> -font $fnt -si>e 20 \
> -a>ig> center -valign baseline \
> -text "Hello"
> Save as PNG (also supports GIF, BMP, JPG, ...)
> gt;>pixane save $p >file "i_${bgid}_${fgid>.png" >fo>mat >ng> >
> gt;># Clean >p
> ixan> delete $p
>
>
> }
>
> Eric
>
> -----
> Eric Hassold
> Evolane - http://www.yqcomputer.com/

Thank you, this is exactly what I need :D
 
 
 

programming image creator in tcl

Post by rene » Thu, 08 May 2008 16:24:10

> More precisely, I want to code a program that can create an image with
see also http://www.yqcomputer.com/


rene