OT: Command-line blues (ImageMagick)

Mike Bonner bonnmike at gmail.com
Fri Oct 28 14:07:50 EDT 2011


Sent this early this morning, but got kicked due to length, so heres the
shorter version minus some of the copy paste.

### From previous message
Don't have a mac any more, but checked over the install instructions to get
up to speed so heres a couple things.

The path export places

This line sets up a temporary sys variable MAGIC_HOME that points to where
image magic is.
$magic> export MAGICK_HOME="$HOME/ImageMagick-6.7.3"


 This line uses the preceeding variable to adjust the path. Notice that the
pointer towards image magic is pre-pended to the existing path which means
that when commands are run (like convert) it will find the image magic
convert first, so of there are any other 'convert' commands you would have
to give the full path to get them to execute instead.
$magic> export PATH="$MAGIC_HOME/bin:$PATH"

Also notice it says this..

*The best way to deal with all the exports is to put them at the end of your
.profile file *


You can export these variables directly from the command line to test things
out, but they are session specific. If you do as instructed and edit your
.profile (in your home directory) and add the export lines at the end, they
should start up at each session.

Now heres one more kicker though. I don't know if shell() from livecode
executes the .profile file. I'm thinking it doesn't, which means your paths
would not be set. If this turns out to be the case you'll need to run it
yourself as part of the shell() command.  Something like

get shell("~/.profile;then your commands here")

The semicolon is a command separator in this case, the tilde ~ stands for
your home directory of course.

Once you have your paths working properly, you can set the defaultfolder to
wherever your images are  and execute your shell. For example if you had
your images in /Users/yourname/images and an image named rose.jpg, something
like this should work.

set the defaultFolder to "/Users/yourname/images"
get shell("~/.profile;convert rose.jpg rose.png")

This first sets the working folder (where your images are, and thereby
avoids issues with spaces or weirdness in pathnames)  then sets the paths by
calling your .profile file so that IM can be found, then calls the convert
command to change rose.jpg to rose.png in the current directory (the
defaultfolder)


Another option you might consider, since it looks as if you will be only
running your app on systems controlled by you..  You could set up the os x
web server to use image magic use the web server to run scripts and do your
processing.   There could be one really nice bonus to this method. Since
apache is multithreaded, you can more easily do async processing. Set up
your scripts, use "load" to hit the web server with all your jobs, (and
using loads callback method so you know when each request completes)

Of course now that I think of it, I seem to recall that imagemagick will
work in batch mode also, so it still might be better to just use shell.

Oh, as far as memory usage goes, yes when you convert with imagemagick, you
specify an infile, an outfile and on completion of the conversion IM should
exit and free any memory that it used.  (or in the case of a batch job, I
think you use the -format switch and specify a target format, and a filemask
for the files to be converted, but don't quote me on this)


Its REALLY early here, so I hope all this is clearer than mud.  G'luck!



More information about the use-livecode mailing list