Resizing images in a Tcl script

  • Permalink
  • submit to reddit
  • Email
  • Follow


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
Reply will181 (163) 11/5/2008 3:45:18 PM

See related articles to this posting


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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply martin.lemburg.siemens-plm (152) 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply el_supremoNN (18) 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
Reply eric1562 (1) 11/8/2008 9:37:29 AM
comp.lang.tcl 21988 articles. 12 followers. Post

16 Replies
243 Views

Similar Articles

[PageSpeed] 44


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Script to resize image
Hello! I need to create a script that resizes an image, of which i don't know the original size. I must check if the image is larger or higher Ex: If height > width then height = 300 else width = 300 end if How can I modify the script below? How can I read the variable 300 from ".ini" file or windows registry? This script was created automatically by PSP. .. .... def Do(Environment): # Ridimensiona App.Do( Environment, 'Resize', { 'AspectRatio': 0.75, ( I DONT KNOW THIS) 'CurrentDimensionU...

InDesign: Scripting image resize
The last thing I do before sending a document to press is to resize all images in Photoshop so that in the document itself no image is resized/resampled (ie, all images are at 100% size). Then, obviously, I apply sharpening etc. appropriate to the final image size, update all links in the document and go back through it resizing all images to 100%. I'm guessing this is a pretty basic and normal part of any designer's workflow. Question: is there a way to automate any part of it? It seems there should be a button in InDesign (or Quark) that lets you simply resize all images in t...

Script : resize images depending on orientation ?
Hello to all, I'd like to resize a big number of images, and a friend of mine can do that with a script. Problem : he doesn't seem to be able to calculate the size depending on the picture's orientation. eg the final size of a "landscape" should be 640x480, while a "portrait" should be 480x640. Yet, with the script he has, I get a picture that's about 640x850 ! Any idea / hint / link ? Thank in advance ! Dworkin Dworkin wrote: > Hello to all, > I'd like to resize a big number of images, and a friend of mine can do > that with a script. Pr...

Perl Script to Resize Images .jpgs (and .gifs too)
Hi folks... I'm trying to find a perl script that I can hopefully reference from a http link (like http://www.mysite.com/cgi-bin/resize.cgi?image=jpeg.jpg&width=100). I need it to shrink down uploaded user profile pics to a maximum width. I have a lame server which won't let me install Image magick, but it does have NETPBM and GDLib (though I don't want to use PHP for this). I have exhausted all search engine possibilities... any help would be VASTLY, Greatly appreciated. Thanks dubious dub wrote: > Hi folks... I'm trying to find a perl script that I can hopefully ...

Any one has a script to upload files or images to web server with TCL CGI ?
Subject : Any one has a script to upload files or images to web server with TCL CGI ? Hello all, Any one has a script to upload files or images to web server with TCL CGI ? I would like my users to be able to upload using a FORM multi part files or pics ... Thank you for the help, Sean - HeliHobby.com Yes, but don't post the same thing so many times. IIRC, this is from a recipe that Jeff Hobbs posted on the ActiveState recipes site: set bound "-----NEXT_PART_[clock seconds].[pid]" set fl [open AngeloFish.jpg r] fconfigure $fl -translation binary set data...

d fAny one has a script to uploailes or images to web server with TCL CGI ?
Subject : Any one has a script to upload files or images to web server with TCL CGI ? Hello all, Any one has a script to upload files or images to web server with TCL CGI ? I would like my users to be able to upload using a FORM multi part files or pics ... Thank you for the help, Sean - HeliHobby.com born2net@HeliHobby.com wrote: > Any one has a script to upload files or images to web server with TCL > CGI ? http://aspn.activestate.com/ASPN/Cookbook/Tcl/Recipe/109363 -- Jeff Hobbs, The Tcl Guy http://www.ActiveState.com/, a division of Sophos ...

Subject : Any one has a script to upload files or images to web server with TCL CGI ?
Subject : Any one has a script to upload files or images to web server with TCL CGI ? Hello all, Any one has a script to upload files or images to web server with TCL CGI ? I would like my users to be able to upload using a FORM multi part files or pics ... Thank you for the help, Sean - HeliHobby.com ...

Mapping Resized image coordinate to Original image(before resizing) coordinate
Hi, if I select a coordinate in a resized image is there anyway to find out the corresponding coordinate in the original image? ...

Resizable image with image text
I'm looking for some help with a group of templates for images on my blog. The images appear in the main content column, and will normally span 100% of its allocated width. The column layout is flexible and I want the images to resize automatically with it. Here's my solution: <div class="image-box"> <img src="..."/> <div class="image-text">...</div> </div> ..image-box { clear: both; } ..image-box img { display: block; width: 100%; } ..image-text { padding: 6px 10px 8px 10px; ba...

Tcl command to evaluate a tcl script?
Hi all, I need to evaluate a separate tcl file within a tcl file. Is there any tcl command to evaluate a tcl file ? Regards, Prabu.K prabu wrote: > Hi all, > > I need to evaluate a separate tcl file within a tcl file. Is there any > tcl command to evaluate a tcl file ? > > Regards, > Prabu.K > hi, try: source your_other_tcl_file.tcl cheers, Tobi ...

Resizing image control with jpg image
Using A2K I have an image control on a report and use code to set the image.picture to the required jpg. 3 of the jpgs resize properly but 2 do not - they display much smaller than the image control. The problem jpgs were originally created as line drawings in Word. They were then copy and pasted to Paint where they were saved as jpg files. Sizemode is set to stretch.(have tried clip and zoom but no better). I cannot find any way to make them expand to the size of the image control. Here is a previous post of mine on this subject. If you did a search on GoogleGroups you would find a l...

Resize Image to fit Picturebox or Image
I have two Pictureboxes on my form. I have also tried using the image box and renamed it picXLData to work with code already using. Image box has the stretch option that Picturebox doesn't but then the image is too small and doesn't even take up much of the area of the image box. I am pulling sheet1 of an Excel file into the clipboard which is then passed to my Picturebox. The range is A1 to N90 so it does cover a large area. Maybe it isn't possible to view the whole picture. Does anyone have any suggestions to make this work? See code below. There is a routine to resize bu...

Script to convert Tcl scripts to Python?
Hi, I have a 10k+ line Tcl program that I would like to auto convert over to Python. Do any scripts exist that can convert ~90% of the standard Tcl syntax over to Python? I know Python doesn't handle strings, but just for general syntax e.g., puts > print, expr > math operations thanks On Apr 23, 9:17 am, "Achillez" <n...@na.com> wrote: > Hi, > > I have a 10k+ line Tcl program that I would like to auto convert over to > Python. Do any scripts exist that can convert ~90% of the standard Tcl > syntax over to Python? I know Python doesn't hand...

Random Image Script for more than one image slot
Greetings: I have found a random image script that I like. It is located here: http://www.javascriptcity.com/scripts/local/simage3.htm I'd like to edit this to have 4 different slots for images with a different set of 5 images for each slot, something like this page: http://www.uchsc.edu The script says /* no need to edit past this point (unless you want to add more image slots) */ Does this mean that you can add more pictures to your array, or, that you can add more image slots to your web site? Any thoughts on how to edit this? Or, do you have another script that can do the same t...

How will I execute an expect script from a tcl script?
I have tried to execute an expect script from a tcl script. But I am unable to do that. I have used following options: one is exec {expect myexpect.exp} another one is source myexpect.exp only "expect myexpect.exp" is running properly. But while trying execute in both ways from tcl script the tcl script is not responding. Please help me to solve this problem. On Jun 7, 7:05 am, manasi.bis...@gmail.com wrote: > I have tried to execute an expect script from a tcl script. But I am > unable to do that. > > I have used following options: > one is > exec {expect my...

Script-fu script saves (wrong) image
Hello people. I do a few things with an image, then save it, make a smaller version and save that under another name (the last action does not save the scaled version, but the larger version): (set! fname (car (gimp-image-get-filename img))) (gimp-file-save 1 img drawable fname fname) Ok till here. (gimp-image-scale img 120 height); (plug-in-sharpen 1 img drawable 30) (gimp-displays-flush) The script actually does all the operations (scale/sharpen) (set! tname (substring fname 0 (- (string-length fname) 3) ) ) (set! fname (string-append tname "tn.jpg&q...

Splitting an image in half (into two images) from a script
Hi, How does one split an image into two images from a script. For instance if we have a number of files that are scans of a journal containing two pages. How does one split each scan into two images contianing one page each. The method needs to be applicable to a length wise split or a width wise split The problem I have with using convert (from imagemagick) is specifying image dimension in pixels . These are not going to be know if all this has to be done in a bash script. sincerely B Thomas In article <d0TJd.60502$re1.21693@fe2.columbus.rr.com>, B Thomas <thomasb> wrote: &g...

Run Matlab Script within TCL Script
Hello TCL Experts, I am new to the world of TCL/TK. So, pardon me if you think my question is very basic. I have an .m file which I need to run within my tcl script. Ideally, I would like to run the tcl script on machines where there is no MATLAB installed. Do you think there is a way to do it? If yes, can you please direct me to do the same/ Sanket jainsanket1@gmail.com wrote: > Hello TCL Experts, > > I am new to the world of TCL/TK. So, pardon me if you think my > question is very basic. > Basic questions are welcome. However, your description is confusing: > I hav...

Tcl command to evaluate a tcl script? #2
Hi all, I need to evaluate a separate tcl file within a tcl file. Is there any tcl command to evaluate a tcl file ? Regards, Prabu.K prabu wrote: > I need to evaluate a separate tcl file within a tcl file. Is there any > tcl command to evaluate a tcl file ? You're probably looking for the "source" command. Other commands of interest would be "package require" or "eval". The command "load" is for binary shared libraries. -- Darren New / San Diego, CA, USA (PST) Scruffitarianism - Where T-shirt, jeans, and a three-day beard...

checking if image generation is supported and image resize
Hi there, How would I check if image generation is supported on my server? I used phpinfo() but didnt know what to look for. Also, I just want to resize image when they are uploaded using PHP. Is this possible? What is the quality like after resize? Cheers Burnsy On 5 Dec 2004 08:19:50 -0800, bissatch@yahoo.co.uk (mr_burns) wrote: >How would I check if image generation is supported on my server? I >used phpinfo() but didnt know what to look for. Look for a section titled 'gd'. This corresponds to the following: http://uk2.php.net/image >Also, I just want to resize ima...

tcl script not working when called from cgi script
Why does this executable tcl file work when launched from a terminal window but not when called from a cgi script? notice the PITA space in the filename. ######################### contents of test.tcl: ######################## #! /bin/sh # the next line restarts using tclsh \ exec tclsh "$0" ${1+"$@"} set cmd "/bin/cp" set my_arg_1 "/data/log/2009/April/04-22-2009\ Data.txt" set my_arg_2 "/tmp/data.txt" set runcmd [list exec $cmd $my_arg_1 $my_arg_2] if {[catch $runcmd res]} { error "Failed to run command $runcmd: $res" } puts ...

Imager Pixel Spacing for resized DERIVED images
We have encountered a number of "CR" and "DX" images that have been resized after the original acquisition and I am wondering if the way they indicate that they have been resized is correct. The Image Type value correctly indicates that the images are "DERIVED" and the way they indicate that they have been resized is to keep the same Imager Pixel Spacing (0018,1164) value as the ORIGINAL images and then convey different values in Pixel Spacing (0028,0030) to indicate the amount of resizing. For one thing, Pixel Spacing should not be used for these IODs so ...

tcl code to read an image and write tcl code?
Does anyone know where I can find a tcl proc that would take an image, say a gif, and output pure tcl code that I could paste into a program? I saw something about a unix program that did something with mimes but I'm on windows. In article <4403BC94.447A7341@rocketship1.com>, Eric Taylor <et2@rocketship1.com> wrote: > > >Does anyone know where I can find a tcl proc >that would take an image, say a gif, and output >pure tcl code that I could paste into a program? > >I saw something about a unix program that did >something with mimes but I'm on wi...

Dose there any tcl script to translate an file with embedded tcl
Hi I need to generate some big file, but there are rules for generate these files Ex . ============================== Start input a [0] wire input a [1] wire .. .. .. .. input a [1000] wire End ================================= Dose there any tcl script can help to translate a file with embedded tcl script into a new file For example this is a source file ======================== Start * set i 0 * for { set i 0 } { $i < 1000 } { incr i } { * puts input a [$i] wire * } End ========================== After Translate ======================= Start input a [0] wire input a [1] wire .. .. ...