Forums » Linux

For you Linux ppl who doesn't want to open every image to convert

12»
Jul 07, 2003 The Kid link
Ok, this is a tga to png script, as far as I can tell, it works well, good enough:
requirements:
wpng (part of libpng package in 1.2.x and 1.0.15)
netbpm (includes tgatoppm)
the script itself:
---------------------------------------------------------
#! /bin/sh
file="$*"

tgatoppm $file.tga > $file.ppm
wpng -gamma 1.1 $file.ppm
echo Created $file.png
rm $file.ppm
mv $file.png ./pngs/$file.png
echo Done.
----------------------------------------------------------
save this as a text file named "makepng" or something.
Then all you do is:
cd .vendetta (or where your tgas are)
make a folder named pngs where your screenshots are located (so things can be sorted easier)
makepng filename
then it'll create a filename.png picture ;)
you can modify that script all you want.
Jul 07, 2003 The Kid link
JPEG version ("w00t: -Roguelazer):
does not require libpng, just netbpm
----------------------------------------------------
#! /bin/sh
file="$*"

tgatoppm $file.tga > $file.ppm
ppmtojpeg $file.ppm > $file.jpeg
echo Created $file.jpeg
rm $file.ppm
mv $file.jpeg ./jpegs/$file.jpeg
echo Done.
----------------------------------------------------
name it makejpeg or something :)
Jul 07, 2003 roguelazer link
Now, if I type "makejpeg *", will it work? What if I run the script on some other type of file? How about if I rename a text file textfile.tga? Will it work? What would the pic look like? How many stupid questions can I think of?
Jul 07, 2003 The Kid link
no, makejpeg * will not work. don't even try it.
you have to do makejpeg dump0000 wait, press up arrow, change the last 0 to 1, etc etc.
The pics look like normal compressed jpegs.
Jul 09, 2003 The Kid link
New, IMPROVED version for making tga to png, same requirements as before.. BUT it includes a safe system that won't even try to proceed if file isn't found:
-----------------------------------------------------------
#! /bin/sh
file="$*"
ls $file.tga
if [ "$?" = "0" ]; then
echo found file moving on...
else
echo could not find file. Exiting.
exit 0
fi
tgatoppm $file.tga > $file.ppm

ls $file.ppm
if [ "$?" = "0" ]; then
echo found file moving on...
else
echo tga to ppm conversion failed. Exiting.
exit 0
fi
wpng -gamma 1.1 $file.ppm

ls $file.png
if [ "$?" = "0" ]; then
echo created $file.png
else
echo ppm to png conversion failed. Exiting.
exit 0
fi
mv $file.ppm ./ppms/$file.ppm
mv $file.png ./pngs/$file.png
echo Done.
-------------------------------------------------------------
I'm adjusting it for jpeg now but to also get it through testing, it might not be ready for tonight.
Jul 09, 2003 The Kid link
Ok, JPEG version is ready enough... ready for testing:
---------------------------------------
#! /bin/sh
file="$*"

ls $file.tga
if [ "$?" = "0" ]; then
echo found file moving on...
else
echo could not find file. Exiting.
exit 0
fi
tgatoppm $file.tga > $file.ppm
ls $file.ppm
if [ "$?" = "0" ]; then
echo found file moving on...
else
echo tga to ppm conversion failed. Exiting.
exit 0
fi
ppmtojpeg $file.ppm > $file.jpeg
ls $file.jpeg
if [ "$?" = "0" ]; then
echo created $file.jpeg
else
echo ppm to jpeg conversion failed. Exiting.
exit 0
fi
mv $file.ppm ./ppms/$file.jpg
mv $file.jpeg ./jpegs/$file.jpeg
echo Done.
------------------------------------------------
Jul 14, 2003 Philmannn Dark link
Suggestion: Install "ImageMagick" (yep, with ck). Then you get a convenient "convert" command.

To convert every file with a .tga extension use this small script:

for f in *.tga ; do convert "$f" "$(basename "$f" .tga).jpg" ; done

Neat trick: basename will strip the paths from the files. So if you run this script in a different directory and use path/to/tga/*.tga in the argument to the for-loop, then the jpegs will be created in the different directory.

L00s3rs would of course just but a path between " and $(basename... ahem :-)

And since convert is smart about the files, you can even run it on anything and it will figure out what to do (print an error if its a text, for example).
Jul 14, 2003 The Kid link
yeah, I already looked into ImageMagick, didn't like it.
Nov 17, 2003 birre link
I don't claim my script is better, but it works for me.

#!/bin/bash
#
# Convert TrueVision Targa file (tga) snapshots to jpeg /Birre
umask 22
for i in *.tga
do
snap=`basename $i .tga`
tgatoppm $i | ppmtojpeg > $snap.jpg 2>/dev/null && rm -f $i
done

<http://norsborg.net/vendetta/tga2jpg>

/Birre
Jul 29, 2003 roguelazer link
convert is slower than Blaster's implimentation. I tested them both on the same computer, his is faster. However, convert is more user-friendly.
Jul 29, 2003 The Kid link
roguelazer, it is? heh, never compared side by side.
Aug 15, 2003 thurisaz link
sillies, GIMP likes to munch on TGA just fine, thank you...

:<=> (munchmunch)
Aug 15, 2003 roguelazer link
'cept the internet doesn't, and the gimp takes a loooong time to load.
Aug 15, 2003 BusMasteR link
Does it... tell me rogue... what comp are u using?
Aug 15, 2003 roguelazer link
Um. My linux desktop. Why?
Aug 17, 2003 The Kid link
GIMP takes about 5 seconds just to load... sooo ;)
Aug 22, 2003 BusMasteR link
Yeah - i meant the s-p-e-e-d of it... My old (very beaten) comp do it in 10 - 15 secs... ;)

Aug 26, 2003 roguelazer link
5 secs? A lot more than that for me. Extension script-fu or something like that takes 15 secs all by its lonesome.
Sep 30, 2003 roguelazer link
Bump: I made up a little scriptie... It changed my .vendetta directory from 985M to 67M:



#!/bin/bash

for f in *.tga
do convert "$f" "$(basename "$f" .tga).jpg"
done

for f in *.tga
do rm -f "$f"
done

Only took about 15 minutes to process all 350+ screenshots.
Oct 01, 2003 The Kid link
convert, ok.
well... what happens like if... it didn't covert right to .jpg, you delete .tga immediately after.