Resizing images in a Tcl script

My app needs to be able to resize images on the fly.  Tk's native
"$img copy -subsample" option yields poor results, and will only scale
images down, not up.  What other options are available?

I've tried Pixane (http://www.evolane.com/software/pixane/pixane.html)
which appears to do the job both reasonably well, and reasonably
quickly; BUT.  It doesn't coexist well with the Img extension.  Once
I've loaded Pixane, I can't load the Img extension; I get the error "
couldn't use "jpegtcl": please upgrade to at least version 6a".  If I
load the Img extension first, followed by Pixane, then calls like this
fail:

   image create photo -file foo.jpg

Pixane has a way to link a Pixane image to a Tk photo image;
consequently, I can use Pixane to load JPEG images into Tk photo
images.  This, however, is horribly, horribly slow.

I've heard of TclMagick, but I don't know how good it is; my past
attempts to get a copy have (IIRC) led me into dependency hell.  It
certainly isn't in the teapot.

Any thoughts?
0
will181 (163)
11/5/2008 3:45:18 PM
comp.lang.tcl 22831 articles. 0 followers. Post Follow

16 Replies
389 Views

Similar Articles

[PageSpeed] 54
will@wjduquette.com wrote:
> My app needs to be able to resize images on the fly.  Tk's native
> "$img copy -subsample" option yields poor results, and will only scale
> images down, not up.  What other options are available?
> 
> I've tried Pixane (http://www.evolane.com/software/pixane/pixane.html)
> which appears to do the job both reasonably well, and reasonably
> quickly; BUT.  It doesn't coexist well with the Img extension.  Once
> I've loaded Pixane, I can't load the Img extension; I get the error "
> couldn't use "jpegtcl": please upgrade to at least version 6a".  If I
> load the Img extension first, followed by Pixane, then calls like this
> fail:
> 
>    image create photo -file foo.jpg
> 
> Pixane has a way to link a Pixane image to a Tk photo image;
> consequently, I can use Pixane to load JPEG images into Tk photo
> images.  This, however, is horribly, horribly slow.
> 
> I've heard of TclMagick, but I don't know how good it is; my past
> attempts to get a copy have (IIRC) led me into dependency hell.  It
> certainly isn't in the teapot.
> 
> Any thoughts?

Tk Magik (aka the Tcl extension to ImageMagik)?

-- 
+------------------------------------------------------------------------+
| Gerald W. Lester                                                       |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
0
Gerald.Lester (2014)
11/5/2008 3:50:24 PM
On Nov 5, 7:45=A0am, w...@wjduquette.com wrote:
> Pixane has a way to link a Pixane image to a Tk photo image;
> consequently, I can use Pixane to load JPEG images into Tk photo
> images. =A0This, however, is horribly, horribly slow.

Aha!  What I was doing was using "pixane create -tkphoto $img" to link
a Pixane image to a Tk photo image; then, any operations on the Pixane
image appear in the Tk image as well.  This is, as I say, horribly
slow.

However, it develops that Pixane also has a "pixcopy" command, defined
when Tk is available, that converts Pixane images to Tk images and
back again; this is much faster.  I'm not sure it's a perfect
solution,
but it's better.

0
will181 (163)
11/5/2008 4:01:46 PM
On Nov 5, 7:50=A0am, "Gerald W. Lester" <Gerald.Les...@cox.net> wrote:
> w...@wjduquette.com wrote:
> > I've heard of TclMagick, but I don't know how good it is; my past
> > attempts to get a copy have (IIRC) led me into dependency hell. =A0It
> > certainly isn't in the teapot.
>
> > Any thoughts?
>
> Tk Magik (aka the Tcl extension to ImageMagik)?

Hi, Gerald!  Have you actually used Tk Magik (I thought it was
TclMagick?)
What's your experience been with it?
0
will181 (163)
11/5/2008 4:02:47 PM
will@wjduquette.com wrote:
> My app needs to be able to resize images on the fly.  Tk's native
> "$img copy -subsample" option yields poor results, and will only scale
> images down, not up.  What other options are available?
> 
> I've tried Pixane (http://www.evolane.com/software/pixane/pixane.html)
> which appears to do the job both reasonably well, and reasonably
> quickly; BUT.  It doesn't coexist well with the Img extension.  Once
> I've loaded Pixane, I can't load the Img extension; I get the error "
> couldn't use "jpegtcl": please upgrade to at least version 6a".  If I
> load the Img extension first, followed by Pixane, then calls like this
> fail:
> 
>    image create photo -file foo.jpg
> 
> Pixane has a way to link a Pixane image to a Tk photo image;
> consequently, I can use Pixane to load JPEG images into Tk photo
> images.  This, however, is horribly, horribly slow.
> 
> I've heard of TclMagick, but I don't know how good it is; my past
> attempts to get a copy have (IIRC) led me into dependency hell.  It
> certainly isn't in the teapot.
> 
> Any thoughts?

Will,

I've started using TkCximage in my apps:

http://amsn.svn.sourceforge.net/viewvc/amsn/trunk/amsn/utils/TkCximage/

It's a Tk interface to the Cximage library 
(http://www.xdp.it/cximage.htm). Cximage can do all kinds of cool things 
with a variety of image formats--not just read them but manipulate them.

The aMSN folks (http://www.amsn-project.net) developed TkCximage to use 
in that app, for the reasons you outline--on-the-fly-image-resizing, as 
well as other manipulations. TkImg doesn't provide this.

TkCximage hasn't been adopted outside of aMSN. I persuaded them to make 
it available under the LGPL, which they've done. A standalone package 
isn't available. Binary libs for Windows and Mac are part of aMSN's SVN 
archive, and you can build it for *Nix from the SVN archive (see 
http://amsn.sourceforge.net/wiki/tiki-index.php?page=Installation+Instructions 
for instructions--running "configure" will build TkCximage if you have 
libpng and libjpeg installed, those are dependencies).

I'm going to put TkCximage through more paces on my apps before 
"evangelizing" it more, but since you're looking for what it provides, I 
hope it helps you!

Kevin

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
0
kw564 (720)
11/5/2008 4:12:12 PM
will@wjduquette.com wrote:
> On Nov 5, 7:50 am, "Gerald W. Lester" <Gerald.Les...@cox.net> wrote:
>> w...@wjduquette.com wrote:
>>> I've heard of TclMagick, but I don't know how good it is; my past
>>> attempts to get a copy have (IIRC) led me into dependency hell.  It
>>> certainly isn't in the teapot.
>>> Any thoughts?
>> Tk Magik (aka the Tcl extension to ImageMagik)?
> 
> Hi, Gerald!  Have you actually used Tk Magik (I thought it was
> TclMagick?)
> What's your experience been with it?

Used it once several years ago.  Seemed to work, but did not stress test it.

And yeap, it is TclMagik.

-- 
+------------------------------------------------------------------------+
| Gerald W. Lester                                                       |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
0
Gerald.Lester (2014)
11/5/2008 4:39:42 PM
On Nov 5, 7:45 am, w...@wjduquette.com wrote:
> My app needs to be able to resize images on the fly.  Tk's native
> "$img copy -subsample" option yields poor results, and will only scale
> images down, not up.  What other options are available?
>
> I've tried Pixane (http://www.evolane.com/software/pixane/pixane.html)
> which appears to do the job both reasonably well, and reasonably
> quickly; BUT.  It doesn't coexist well with the Img extension.  Once
> I've loaded Pixane, I can't load the Img extension; I get the error "
> couldn't use "jpegtcl": please upgrade to at least version 6a".  If I
> load the Img extension first, followed by Pixane, then calls like this
> fail:
>
>    image create photo -file foo.jpg
>
> Pixane has a way to link a Pixane image to a Tk photo image;
> consequently, I can use Pixane to load JPEG images into Tk photo
> images.  This, however, is horribly, horribly slow.
>
> I've heard of TclMagick, but I don't know how good it is; my past
> attempts to get a copy have (IIRC) led me into dependency hell.  It
> certainly isn't in the teapot.
>
> Any thoughts?

http://wiki.tcl.tk/11924
is good code for me.

Also note that there is both
Tclmagick and Tkmagick. Tclmagick doesn't
require tk and can't work with tk images.
tkmagick is basically a copy bridge between
image magick and Tk images (in memory)
Finally, there is a largish update of tclmagick
adding api calls. The new version is tclwand.
0
royterry (360)
11/5/2008 4:52:18 PM
On Nov 5, 11:52=A0am, Roy Terry <royte...@earthlink.net> wrote:
> On Nov 5, 7:45 am, w...@wjduquette.com wrote:
>
>
>
> > My app needs to be able to resize images on the fly. =A0Tk's native
> > "$img copy -subsample" option yields poor results, and will only scale
> > images down, not up. =A0What other options are available?
>
> > I've tried Pixane (http://www.evolane.com/software/pixane/pixane.html)
> > which appears to do the job both reasonably well, and reasonably
> > quickly; BUT. =A0It doesn't coexist well with the Img extension. =A0Onc=
e
> > I've loaded Pixane, I can't load the Img extension; I get the error "
> > couldn't use "jpegtcl": please upgrade to at least version 6a". =A0If I
> > load the Img extension first, followed by Pixane, then calls like this
> > fail:
>
> > =A0 =A0image create photo -file foo.jpg
>
> > Pixane has a way to link a Pixane image to a Tk photo image;
> > consequently, I can use Pixane to load JPEG images into Tk photo
> > images. =A0This, however, is horribly, horribly slow.
>
> > I've heard of TclMagick, but I don't know how good it is; my past
> > attempts to get a copy have (IIRC) led me into dependency hell. =A0It
> > certainly isn't in the teapot.
>
> > Any thoughts?
>
> http://wiki.tcl.tk/11924
> is good code for me.

I second that. I needed something for image rotation and
I found tcl magick too bulky for such a simple task.

Only problem is that I haven't been able to get it to
work under Unix. Has anybody had any luck?

Keith


0
kvetter (178)
11/5/2008 5:08:08 PM
On Wed, 5 Nov 2008, Roy Terry wrote:

> Date: Wed, 5 Nov 2008 08:52:18 -0800 (PST)
> From: Roy Terry <royterry@earthlink.net>
> Newsgroups: comp.lang.tcl
> Subject: Re: Resizing images in a Tcl script
> 
> On Nov 5, 7:45 am, w...@wjduquette.com wrote:
>> My app needs to be able to resize images on the fly.  Tk's native
>> "$img copy -subsample" option yields poor results, and will only scale
>> images down, not up.  What other options are available?
>>
>> I've tried Pixane (http://www.evolane.com/software/pixane/pixane.html)
>> which appears to do the job both reasonably well, and reasonably
>> quickly; BUT.  It doesn't coexist well with the Img extension.  Once
>> I've loaded Pixane, I can't load the Img extension; I get the error "
>> couldn't use "jpegtcl": please upgrade to at least version 6a".  If I
>> load the Img extension first, followed by Pixane, then calls like this
>> fail:
>>
>>    image create photo -file foo.jpg
>>
>> Pixane has a way to link a Pixane image to a Tk photo image;
>> consequently, I can use Pixane to load JPEG images into Tk photo
>> images.  This, however, is horribly, horribly slow.
>>
>> I've heard of TclMagick, but I don't know how good it is; my past
>> attempts to get a copy have (IIRC) led me into dependency hell.  It
>> certainly isn't in the teapot.
>>
>> Any thoughts?
>
> http://wiki.tcl.tk/11924
> is good code for me.
>
> Also note that there is both
> Tclmagick and Tkmagick. Tclmagick doesn't
> require tk and can't work with tk images.
> tkmagick is basically a copy bridge between
> image magick and Tk images (in memory)
> Finally, there is a largish update of tclmagick
> adding api calls. The new version is tclwand.

One thing you might want to consider is extracting the thumbnail from the 
exif data to scale "downwards", and only "scale" if necessary ... that is, 
to scale fast, don't scale at all ...

Actually, tkMagick is unnecessary, as all one needs is to copy the blob 
from tclMagick into a tk image -- note wand2Image below ... :

   proc blob2wand { wand blob } {
         $wand readblob $blob
         return $wand
   }
   proc wand2Image { wand img } {
         $img put [ $wand writeblob ]
   }
   proc resize { wand width height } {
         $wand resize $width $height
   }
   proc getImage { path } {
         set ret [image create photo]
         $ret read $path
         return $ret
   }
   proc putImage { img path } {
         return [$img write $path]
   }
   proc putWand { wand path } {
         return [$wand write $path]
   }

.... As for building tclMagick ... once you have a working version of 
ImageMagick, you can adapt the following script to build only the required 
parts of tclMagick ... You don't need the entire autotools config/make to 
do so ...

wnd=/usr/local/bin/Wand-config
#CC=mingw32-gcc
CC=gcc
$CC -shared -DUSE_TCL_STUBS -fPIC -DUSE_TK_STUBS -DUSE_TK_STUBS -I. \
         -I/usr/local/include -L/usr/local/lib -L/usr/lib \
         `$wnd --ldflags --libs` \
         -L /usr/local/lib -ltclstub8.5 \
         -o tclmagick.so -O2 -DNDEBUG TclMagick.c
#        -o tclmagick.so -O2 -DNDEBUG -Wl,-s TclMagick.c


If you are on windows, you'll need MingW or CygWin ...

HTH ...
Cheers,
Rob
       ---- Posted via Pronews.com - Premium Corporate Usenet News Provider ----
http://www.pronews.com offers corporate packages that have access to 100,000+ newsgroups
0
Spam159 (460)
11/5/2008 5:09:33 PM
On Nov 5, 8:52=A0am, Roy Terry <royte...@earthlink.net> wrote:
> On Nov 5, 7:45 am, w...@wjduquette.com wrote:
> > My app needs to be able to resize images on the fly. =A0Tk's native
> > "$img copy -subsample" option yields poor results, and will only scale
> > images down, not up. =A0What other options are available?
>
>
> http://wiki.tcl.tk/11924
> is good code for me.

That sounds just about perfect...if it works on Linux.
0
will181 (163)
11/5/2008 5:23:29 PM
Hi Rob,

to extract the thumbnail from the EXIF data I used simply the tcllib
jpeg package and stored the thumbnail into a file.

Ok - if the EXIF orientation tag tells, that the thumbnail should be
rotated, than I used pixane to rotate the thumbnail before saving it.

I also tried Image/TclMagick, but while building and using starpacks a
lot I ran into problems with the DLL/registry dependencies on systems,
where ImageMagick wasn't installed properly.
Pixane worked right out of the (starpack) box. And it worked really
quick!

But I never needed Linux/Unix support, so I don't know about the Linux/
Unix support of pixane.

Best Regards,

Martin

On Nov 5, 6:09=A0pm, S...@ControlQ.com wrote:
> On Wed, 5 Nov 2008, Roy Terry wrote:
> > Date: Wed, 5 Nov 2008 08:52:18 -0800 (PST)
> > From: Roy Terry <royte...@earthlink.net>
> > Newsgroups: comp.lang.tcl
> > Subject: Re: Resizing images in a Tcl script
>
> > On Nov 5, 7:45 am, w...@wjduquette.com wrote:
> >> My app needs to be able to resize images on the fly. =A0Tk's native
> >> "$img copy -subsample" option yields poor results, and will only scale
> >> images down, not up. =A0What other options are available?
>
> >> I've tried Pixane (http://www.evolane.com/software/pixane/pixane.html)
> >> which appears to do the job both reasonably well, and reasonably
> >> quickly; BUT. =A0It doesn't coexist well with the Img extension. =A0On=
ce
> >> I've loaded Pixane, I can't load the Img extension; I get the error "
> >> couldn't use "jpegtcl": please upgrade to at least version 6a". =A0If =
I
> >> load the Img extension first, followed by Pixane, then calls like this
> >> fail:
>
> >> =A0 =A0image create photo -file foo.jpg
>
> >> Pixane has a way to link a Pixane image to a Tk photo image;
> >> consequently, I can use Pixane to load JPEG images into Tk photo
> >> images. =A0This, however, is horribly, horribly slow.
>
> >> I've heard of TclMagick, but I don't know how good it is; my past
> >> attempts to get a copy have (IIRC) led me into dependency hell. =A0It
> >> certainly isn't in the teapot.
>
> >> Any thoughts?
>
> >http://wiki.tcl.tk/11924
> > is good code for me.
>
> > Also note that there is both
> > Tclmagick and Tkmagick. Tclmagick doesn't
> > require tk and can't work with tk images.
> > tkmagick is basically a copy bridge between
> > image magick and Tk images (in memory)
> > Finally, there is a largish update of tclmagick
> > adding api calls. The new version is tclwand.
>
> One thing you might want to consider is extracting the thumbnail from the
> exif data to scale "downwards", and only "scale" if necessary ... that is=
,
> to scale fast, don't scale at all ...
>
> Actually, tkMagick is unnecessary, as all one needs is to copy the blob
> from tclMagick into a tk image -- note wand2Image below ... :
>
> =A0 =A0proc blob2wand { wand blob } {
> =A0 =A0 =A0 =A0 =A0$wand readblob $blob
> =A0 =A0 =A0 =A0 =A0return $wand
> =A0 =A0}
> =A0 =A0proc wand2Image { wand img } {
> =A0 =A0 =A0 =A0 =A0$img put [ $wand writeblob ]
> =A0 =A0}
> =A0 =A0proc resize { wand width height } {
> =A0 =A0 =A0 =A0 =A0$wand resize $width $height
> =A0 =A0}
> =A0 =A0proc getImage { path } {
> =A0 =A0 =A0 =A0 =A0set ret [image create photo]
> =A0 =A0 =A0 =A0 =A0$ret read $path
> =A0 =A0 =A0 =A0 =A0return $ret
> =A0 =A0}
> =A0 =A0proc putImage { img path } {
> =A0 =A0 =A0 =A0 =A0return [$img write $path]
> =A0 =A0}
> =A0 =A0proc putWand { wand path } {
> =A0 =A0 =A0 =A0 =A0return [$wand write $path]
> =A0 =A0}
>
> ... As for building tclMagick ... once you have a working version of
> ImageMagick, you can adapt the following script to build only the require=
d
> parts of tclMagick ... You don't need the entire autotools config/make to
> do so ...
>
> wnd=3D/usr/local/bin/Wand-config
> #CC=3Dmingw32-gcc
> CC=3Dgcc
> $CC -shared -DUSE_TCL_STUBS -fPIC -DUSE_TK_STUBS -DUSE_TK_STUBS -I. \
> =A0 =A0 =A0 =A0 =A0-I/usr/local/include -L/usr/local/lib -L/usr/lib \
> =A0 =A0 =A0 =A0 =A0`$wnd --ldflags --libs` \
> =A0 =A0 =A0 =A0 =A0-L /usr/local/lib -ltclstub8.5 \
> =A0 =A0 =A0 =A0 =A0-o tclmagick.so -O2 -DNDEBUG TclMagick.c
> # =A0 =A0 =A0 =A0-o tclmagick.so -O2 -DNDEBUG -Wl,-s TclMagick.c
>
> If you are on windows, you'll need MingW or CygWin ...
>
> HTH ...
> Cheers,
> Rob
> =A0 =A0 =A0 =A0---- Posted via Pronews.com - Premium Corporate Usenet New=
s Provider ----http://www.pronews.comoffers corporate packages that have ac=
cess to 100,000+ newsgroups

0
11/5/2008 5:43:37 PM
will@wjduquette.com wrote:

> My app needs to be able to resize images on the fly.  Tk's native
> "$img copy -subsample" option yields poor results, and will only scale
> images down, not up.  What other options are available?
> 
> I've tried Pixane (http://www.evolane.com/software/pixane/pixane.html)
> which appears to do the job both reasonably well, and reasonably
> quickly; BUT.  It doesn't coexist well with the Img extension.  Once
> I've loaded Pixane, I can't load the Img extension; I get the error "
> couldn't use "jpegtcl": please upgrade to at least version 6a".  If I
> load the Img extension first, followed by Pixane, then calls like this
> fail:
> 
>    image create photo -file foo.jpg
> 
> Pixane has a way to link a Pixane image to a Tk photo image;
> consequently, I can use Pixane to load JPEG images into Tk photo
> images.  This, however, is horribly, horribly slow.
> 
> I've heard of TclMagick, but I don't know how good it is; my past
> attempts to get a copy have (IIRC) led me into dependency hell.  It
> certainly isn't in the teapot.

I wrote a patch for TclMagick.  It's pretty good code, but I later created
my own solution for my needs.
 
> Any thoughts?

You could use megaimage and my JPEG and/or PNG extensions.  They are BSD
licensed, with the additional restrictions of the libjpeg and libpng
licenses.

They were actually used for the Tcl conference image feed last year, and I
think this year too.  Another extension I wrote to work with megaimage was
freetypeext (for compositing text over an image).

set buf [jpegext2:decode $jpegdata]
set mobj [megaimage $buf]
#For an image half the size use 500 500.  1000 is no change.
#1000 is used for better fixed point accuracy.
#There is also a scaleto for exact width and height.
$mobj scale 500 500 
set newjpegdata [jpegext2:encode [$mobj getdata]]
rename $mobj {}; #cleanup

If you need to convert a megaimage buffer to a Tk photo you can use
megaimagetk with [megaimage.to.photo].

This has some -DUSE_TCL_STUBS binaries I threw together quickly for an MJPEG
viewer before the conference this year:
http://whim.linuxsys.net/files/Tk_MJPEG_Win32_and_Linux-3.zip

The Win32 binaries in this case are newer than the Linux binaries in that
zip file.  They were all built for 8.5 I think.  I can provide updated 8.5
builds if you want for Linux and Win32, or instructions for building.  I
may even be able to provide MacOS X binaries as well.

The documentation is here: 
http://www.xmission.com/~georgeps/implementation/software/megapkg/megaimage.html
http://www.xmission.com/~georgeps/implementation/software/megapkg/megaimagetk.html
Tiffext is another encoder/decoder compatible with megaimage.
http://www.xmission.com/~georgeps/implementation/software/megapkg/tiffext.html

I'm hoping that eventually other Tcl developers will work with me on
the "Imagecore" ideas.  See: http://paste.tclers.tk/1323  Imagecore may
eventually supplant megaimage, and I'm hoping be in the Tcl core as an
optional package, though perhaps (for building and redistribution reasons)
not with the imagecore encoders/decoders that depend on other libraries.

--George
0
georgeps (404)
11/5/2008 5:53:09 PM
will@wjduquette.com schreef:
> On Nov 5, 8:52 am, Roy Terry <royte...@earthlink.net> wrote:
>> On Nov 5, 7:45 am, w...@wjduquette.com wrote:
>>> My app needs to be able to resize images on the fly.  Tk's native
>>> "$img copy -subsample" option yields poor results, and will only scale
>>> images down, not up.  What other options are available?
>>
>> http://wiki.tcl.tk/11924
>> is good code for me.
> 
> That sounds just about perfect...if it works on Linux.

You could also have a look at LRIPhoto (http://wfr.tcl.tk/1004 in 
french), its similar to http://wiki.tcl.tk/11924, but meant to work with 
critcl or odyce, so I would expect it to work on linux. I haven't tried 
it myself (except for clicking on it in the odyce demo on windows).

Peter
0
pwelten (22)
11/5/2008 6:32:24 PM
On Wed, 5 Nov 2008, MartinLemburg@Siemens-PLM wrote:
> Hi Rob,
>
> to extract the thumbnail from the EXIF data I used simply the tcllib
> jpeg package and stored the thumbnail into a file.

Probably a good approach!

>
> Ok - if the EXIF orientation tag tells, that the thumbnail should be
> rotated, than I used pixane to rotate the thumbnail before saving it.
>

Tricky, I find that the orientation varies from data source to data 
source, and can be misleading ...


> I also tried Image/TclMagick, but while building and using starpacks a
> lot I ran into problems with the DLL/registry dependencies on systems,
> where ImageMagick wasn't installed properly.
> Pixane worked right out of the (starpack) box. And it worked really
> quick!
>

Pixane is not BSD licensed, not available on a lot of platforms and source 
is not readily available.  No cigar.

> But I never needed Linux/Unix support, so I don't know about the Linux/
> Unix support of pixane.
>
> Best Regards,
>
> Martin

AFAIR, pixane has some licensing/source/platform availability issues which 
prevent my using them.  I use FreeBSD/OpenBSD/NetBSD/Ubuntu/Debian/Windoze 
and other OS'es ... so again, not helpful.

Admittedly, ImageMagick is a *BIG* but moving target, and the API is in 
flux, and tclMagick is unmaintained for all intents and purposes.

TclWand seems to have some potential, but has all the complexity of 
tclMagick (the big switch statement) as it is based upon tclMagick 0.45, 
and is available for Windoze only at the moment. Though, that might change 
if I can figure out the build process, and hand back a proper 
(non-windoze) build environment for it ... but I don't have time to do 
that just now ...

Here's a quick example of using of tclMagick to extract a thumbnail from 
an image, using the metadata contained within the corresponding wand ... 
and by getting the exif offsets and length, and then just pulling the 
string range out of the blob.  Pretty quick ...

   proc extractThumb { wand blob } {
         set off [wandProperty $wand exif:JPEGInterchangeFormat]
         if ![string length $off] {
                 return {}
         }
         set len [wandProperty $wand exif:JPEGInterchangeFormatLength]
         set chr [format "%s" \xd8]
         set ix [expr [string first $chr $blob $off] - 1 ]
         set lst [expr $ix + $len]
         return [string range $blob $ix $lst]
   }

Here's a small C code snippet to do the same (pull a thumbnail) using 
libexif, but I really can't recommend libexif in the absence of any 
reasonable documentation ... I seem to recall that it took me the better 
part of half a day to excavate enough info to write the code snippet 
below ... though it is fast!

/*
         this mechanism for extracting thumbnails uses libexif ...
*/
Blob_t  *im_ExtractThumb( Img_t *im ){

         ExifData *Exif ;
         Blob_t  *ret ;

         ret = (Blob_t *) NULL ;
         Exif = exif_data_new_from_data( im ->img ->buf, im ->img ->actual ) ;
         if( Exif ->size && Exif ->data ){
                 ret = copyBlob( Exif ->data, Exif ->size ) ;
         }
         exif_data_unref( Exif );
         return( ret ) ;
}

Ideally, a tcl extension based upon a simple library could be built which 
provides the image scaling/rotation/watermark capabilities, is portable, 
fast, and easily built on any platform ... but I'm not sure which library 
would be a sound starting point for such an extension.


Cheers,
Rob Sciuk
       ---- Posted via Pronews.com - Premium Corporate Usenet News Provider ----
http://www.pronews.com offers corporate packages that have access to 100,000+ newsgroups
0
Spam159 (460)
11/5/2008 10:22:05 PM
On Wed, 5 Nov 2008 17:22:05 -0500, Spam@ControlQ.com wrote:
> Admittedly, ImageMagick is a *BIG* but moving target, and the API is in 
> flux, and tclMagick is unmaintained for all intents and purposes.
> 
> TclWand seems to have some potential, but has all the complexity of 
> tclMagick (the big switch statement) as it is based upon tclMagick 0.45, 
> and is available for Windoze only at the moment. Though, that might change 
> if I can figure out the build process, and hand back a proper 
> (non-windoze) build environment for it ... but I don't have time to do 
> that just now ...

Rob:
I wrote the TclWand modification of the original TclMagick.
If you, or anyone, needs a TclWand built for a recent version of
ImageMagick I can make one available.
If you need help changing the build environment I can try to help with that
if/when you get around to it.

Pete
--
===============
NN=01
0
digipete (1)
11/6/2008 8:02:45 PM
On Wed, 5 Nov 2008 17:22:05 -0500, Spam@ControlQ.com wrote:> 
> Admittedly, ImageMagick is a *BIG* but moving target, and the API is in 
> flux, and tclMagick is unmaintained for all intents and purposes.
> 
> TclWand seems to have some potential, but has all the complexity of 
> tclMagick (the big switch statement) as it is based upon tclMagick 0.45, 
> and is available for Windoze only at the moment. Though, that might change 
> if I can figure out the build process, and hand back a proper 
> (non-windoze) build environment for it ... but I don't have time to do 
> that just now ...

Rob:
I wrote the TclWand modification of the original TclMagick. I've added the
ability to execute a command line directly from within TclWand. As a
trivial example, the commnad line "convert logo logo.png" would be:
magick convert logo: logo.png
The composite, mogrify and montage commands can also be called directly
like this.

If you, or anyone, needs a TclWand built for a recent version of
ImageMagick I can make one available.
If you need help changing the build environment I can try to help with that
if/when you get around to it.

Pete
-- 
NN=01
0
11/7/2008 2:25:58 PM
On Nov 5, 6:23=A0pm, w...@wjduquette.com wrote:
> On Nov 5, 8:52=A0am, Roy Terry <royte...@earthlink.net> wrote:
>
> > On Nov 5, 7:45 am, w...@wjduquette.com wrote:
> > > My app needs to be able to resize images on the fly. =A0Tk's native
> > > "$img copy -subsample" option yields poor results, and will only scal=
e
> > > images down, not up. =A0What other options are available?
>
> >http://wiki.tcl.tk/11924
> > is good code for me.
>
> That sounds just about perfect...if it works on Linux.

Hello, have a look at TkImageTools.

http://snackamp.sourceforge.net/releases/

-eric
0
eric1562 (1)
11/8/2008 9:37:29 AM
Reply:
Similar artilces about - Resizing images in a Tcl script: