Objectmix
Tags Register Mark Forums Read

Annotate and save a JPEG image : TCL

This is a discussion on Annotate and save a JPEG image within the TCL forums in Programming Languages category; I have various JPEG files that I would like to manipulate in Tcl. I can read them in fine via the Img extension. What I want to do is read in an image, add a bit of size to the height. In this added part of the image, I want to put text. Basically I want to add a space under an image and put text there. I need to save this as a new JPEG. I know how to read the image, make another that is some amount taller, and copy the image into this bigger image. What I ...


Object Mix > Programming Languages > TCL > Annotate and save a JPEG image

Reply

 

LinkBack Thread Tools
  #1  
Old 01-23-2008, 03:51 AM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Annotate and save a JPEG image

I have various JPEG files that I would like to manipulate in Tcl. I
can read them in fine via the Img extension. What I want to do is read
in an image, add a bit of size to the height. In this added part of
the image, I want to put text. Basically I want to add a space under
an image and put text there. I need to save this as a new JPEG.

I know how to read the image, make another that is some amount taller,
and copy the image into this bigger image.

What I can't see is how best to get text into the image. I want the
text in the new bit I am adding. So I have been looking how I can use
photo to accomplish this. I suspect there is something very obvious
that I am missing here.

Any pointers?

Roger Oberholtzer
  #2  
Old 01-23-2008, 04:21 AM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Annotate and save a JPEG image

On Jan 23, 9:51 am, roger.oberholt...@gmail.com wrote:
> I have various JPEG files that I would like to manipulate in Tcl. I
> can read them in fine via the Img extension. What I want to do is read
> in an image, add a bit of size to the height. In this added part of
> the image, I want to put text. Basically I want to add a space under
> an image and put text there. I need to save this as a new JPEG.


You might want to look into the TclMagick extension - it does what you
need, although you should be aware that it's not really maintained
right now.
  #3  
Old 01-23-2008, 05:14 AM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Annotate and save a JPEG image

roger.oberholtzer@gmail.com wrote :
> I have various JPEG files that I would like to manipulate in Tcl. I
> can read them in fine via the Img extension. What I want to do is read
> in an image, add a bit of size to the height. In this added part of
> the image, I want to put text. Basically I want to add a space under
> an image and put text there. I need to save this as a new JPEG.
>
> I know how to read the image, make another that is some amount taller,
> and copy the image into this bigger image.
>
> What I can't see is how best to get text into the image. I want the
> text in the new bit I am adding. So I have been looking how I can use
> photo to accomplish this. I suspect there is something very obvious
> that I am missing here.
>


Hi,

Pixane extension has been designed especially for scripting this kind of
images transformations. It embeds a TrueType engine (freetype) and
several TTF fonts for rendering scalable antialiases text, with no
external dependencies. Pixane can be used either as part of eTcl
distribution, on all supported platforms (including WinCE) :

http://www.evolane.com/software/etcl/index.html

or as a standalone extension, available as a loadable shared library:

http://www.evolane.com/software/pixane/index.html

Documentation is available from
http://www.evolane.com/software/pixane/pixane.html
http://www.evolane.com/software/pixane/pixfont.html

but to make it simpler, below is a sample code which does what you ask
for in your post.

Regards,

Eric

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


package require pixane

# File to comment
set fin [file join [file dirname [info script]] test.jpg]
set fout [file rootname $fin]_new[file extension $fin]

# Comment
set caption "This is some comment rendered into photo"

set p [pixane create]
pixane load $p -file $fin

set w [pixane width $p]
set h [pixane height $p]

set h2 [expr {$h+32}]
pixane resize $p $w $h2

pixane color $p "\#C0C0F0"
pixane rect $p 0 $h $w $h2

pixane color $p "\#101020"
set font [pixfont create -builtin "sansserif"]
pixane text $p [expr {$w/2}] [expr {$h2-($h2-$h)/4}] \
-font $font -size 20 \
-align center -valign baseline \
-text $caption

# Save
pixane save $p -file $fout -format jpg
  #4  
Old 01-23-2008, 10:28 AM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Annotate and save a JPEG image

On Jan 23, 11:14 am, Eric Hassold <hass...@evolane.com> wrote:
> roger.oberholt...@gmail.com wrote :
>
> > I have various JPEG files that I would like to manipulate in Tcl. I
> > can read them in fine via the Img extension. What I want to do is read
> > in an image, add a bit of size to the height. In this added part of
> > the image, I want to put text. Basically I want to add a space under
> > an image and put text there. I need to save this as a new JPEG.

>
> > I know how to read the image, make another that is some amount taller,
> > and copy the image into this bigger image.

>
> > What I can't see is how best to get text into the image. I want the
> > text in the new bit I am adding. So I have been looking how I can use
> > photo to accomplish this. I suspect there is something very obvious
> > that I am missing here.

>
> Hi,
>
> Pixane extension has been designed especially for scripting this kind of
> images transformations. It embeds a TrueType engine (freetype) and
> several TTF fonts for rendering scalable antialiases text, with no
> external dependencies. Pixane can be used either as part of eTcl
> distribution, on all supported platforms (including WinCE) :


Yes! This is it exactly. And it does exactly what I need. I have tried
it on Linux. Next will be on Windows. Which should be no trouble. Tcl
has all these just things lurking out there...

Roger Oberholtzer
  #5  
Old 01-26-2008, 06:37 PM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Annotate and save a JPEG image

when I try Eric's sample below, all is fine except

pixane color $p "\#C0C0F0"
expected integer but got "#C0C0F0"

It doesn't seem to like color words:

pixane color $p red
expected integer but got "red"

or hex

set C1 \x0C0
lappend C1 \x0C0
lappend C1 \x0F0
pixane color $p $C1
expected integer but got "?"

But if I feed it a list of rbg decimals, I get what I expect.

#pixane color $p "\#C0C0F0"
set C1 192
lappend C1 192
lappend C1 240
pixane color $p $C1

Am I missing something obvious?

I am running 8.4.9 on Win2k. The libpixane.dll is dated August 01,
2007, 1:57:44 AM





On Wed, 23 Jan 2008 11:14:00 +0100, Eric Hassold <hassold@evolane.com>
wrote:

>
>-----
>Eric Hassold
>Evolane - http://www.evolane.com/
>
>
>package require pixane
>
># File to comment
>set fin [file join [file dirname [info script]] test.jpg]
>set fout [file rootname $fin]_new[file extension $fin]
>
># Comment
>set caption "This is some comment rendered into photo"
>
>set p [pixane create]
>pixane load $p -file $fin
>
>set w [pixane width $p]
>set h [pixane height $p]
>
>set h2 [expr {$h+32}]
>pixane resize $p $w $h2
>
>pixane color $p "\#C0C0F0"
>pixane rect $p 0 $h $w $h2
>
>pixane color $p "\#101020"
>set font [pixfont create -builtin "sansserif"]
>pixane text $p [expr {$w/2}] [expr {$h2-($h2-$h)/4}] \
> -font $font -size 20 \
> -align center -valign baseline \
> -text $caption
>
># Save
>pixane save $p -file $fout -format jpg



  #6  
Old 01-27-2008, 06:15 AM
Junior Member
 
Join Date: Nov 2009
Posts: 0
Application Development is on a distinguished road
Default Re: Annotate and save a JPEG image

PTurner wrote :
> when I try Eric's sample below, all is fine except
>
> pixane color $p "\#C0C0F0"
> expected integer but got "#C0C0F0"
>


Pixane parse colors as either:
- a list of RGB or RGBA components, e.g.
pixane color $p {0xc0 0xc0 0xf0}
pixane color $p {0xc0 0xc0 0xf0 0x80}
- a single integer for grayscale
pixane color $p 0xf0
- a color in #RRGGBB or #RRGGBBAA (or #RGB or #RGBA) format
pixane color $p "\#C0C0F0"
pixane color $p "\#C0C0F080"

Some (older) pixane code were missing a Tcl_ResetResult() call, so
"pixane color" or "pixane bgcolor" returns the error message from
Tcl_GetIntFromObj() (grayscale variant) which failed. However, even if
this message can be one believe comamnd failed, return code is TCL_OK,
and color has been accepted. You may check this as:

% catch {pixane color $p "\#C0C0F0"} res
0

To put it shortly, when experimenting with this pixane command in
interactive mode, something which looks like an error is shown in
console, but actually comamnd succeed. And if same command is part of
the script, it works as expected. So you may just ignore the confusing
but painless message.

Of course, I will regenerate and make available an up to date version of
the standalone distrib of Pixane (that is out of eTcl) to fix this.

Eric
Reply

Thread Tools



All times are GMT -5. The time now is 12:56 PM.

Managed by Infnx Pvt Ltd.