Jonathan Kulp wrote:
Ok I changed a couple of things to make it even more flexible. I changed
pnmto__ to ppmto__, giving quite a few more output options. I've suggested a
few in the script. Also added an option to choose either gif or png when
choosing transparent background. this is fun :)
Jonathan, on my system there's no ppmtopng or ppmtotiff and ppmtojpeg is a link
to pnmtojpeg. This is with Hardy Ubuntu and a fresh install of the utils.
Annoying, no? It makes the changes to your script break on my machine.
I've found that creating symbolic links in /usr/bin like:
ln -s pnmtopng ppmtopng
ln -s pnmtotiff ppmtotiff
fixes the problem, but why wouldn't that have been done automagically? I
removed the netpbm package and it didn't remove my links, so they're really not
part of the package. Maybe I should file a bug against the package. It does
reinstall the link from ppmtojpeg to pnmtojpeg when I reinstall it. How is it
set up on your system?
It seems like to be bulletproof, the script needs to check and see which of
ppmto$FORMAT and pnmto$FORMAT exists and use that, that's easy to do with which,
it already has all the code to look through your PATH.
I'm attaching a new version of my version of your script with that change and a
new routine, getval, that validates input, you use it like:
prompt= "Enter desired output format (jpeg, png, tiff, gif, pcx, bmp): "
goodvals=("jpeg" "png" "tiff" "gif" "pcx" "bmp")
getval
FORMAT=$outval
If the user enters something that's not on the goodvals list, for example joe,
it reprompts them after telling them what they might have entered:
Enter desired output format (jpeg, png, tiff, gif, pcx, bmp): joe
Expecting one of : jpeg png tiff gif pcx bmp
Enter desired output format (jpeg, png, tiff, gif, pcx, bmp):
Cool, no? I suppose I should add validation to the command line arguments as
well.
Ok, just did that, resolution checked for numeric both on input and from the
command line, format checked for one of the allowable things, and check to make
sure there's a filename, and print meaningful error message and a usage
statement. Try it and see if it works for you.
I'm almost tempted to check for all the pnmto and ppmto and automatically
build the list of allowed types instead of hard coding them--nah, I'll leave
that as an exercise for the reader;) It really needs to be done with my version
because I only let people use what's on the list:( Yours will just work as long
as it's a valid format. You could grab the outcmd part of my version of your
script. It automagically picks either ppmto or pnmto and exits with an error if
neither are found.
I also check for the existence of pnmtojpeg and abort the script if not
found with
a message that the netpbm utilities have to be installed to use the script.
Now the script is /much/ larger because of all the checking.
Patrick
Jon
script attached this time...
Patrick Horgan wrote:
Jonathan Kulp wrote:
I'm guessing that one of the netpbm tools will handle transparency, it's
just a matter of figuring out which one. Didn't this come up on a recent
thread? I seem to remember trying it out on something and getting a
transparent background. When I get some time later I'll look into it. It
would be simple enough to add a prompt asking if you'd like a transparent
background, I guess.
Now that you mention it that rings a bell with me too! I'll have to search---
giftoppm foobar.gif | ppmtogif -transparent '#rgb' > fooquux.gif
works if you want gif. First translate to ppm, then translate back to gif
with the -transparent flag specifying which color, (in this case #fff) will
be transparent.
pnmtopng has the transparent argument, but pnmtotiff and jpeg don't since
they don't support transparency...so, using your script, if you want
transparency, you have to choose png for the output, then on the translation
step from ppm just add the appropriate flags. I just tried it adding a quick
-transparent '#ffffff' to the command line and then selecting png so it would
work. It worked like a charm:)