Forums » Linux

fancy new tga>jpg converter

12»
Mar 13, 2004 red cactus link
Merry christmas, guys, I wrote all you folks a tga to jpg converter. Perl.

#!/usr/bin/perl
# (c) 2004 Tyler Denniston
# a simple tool used to convert tga files to jpeg files,
# using pre-existing tools

foreach $arg (@ARGV) {
if (-f $arg) {
`tgatoppm $arg > a`;
`ppmtojpeg a > b`;
($name,$trash) = split (/\./,$arg);
$name .= ".jpg";
`mv b $name`;
`rm -f a`;
}else{
print "$arg does not exist!\n";
}
}

-rc
Mar 14, 2004 roguelazer link
Merry Christmas, I wrote this last year:

#!/bin/bash
# (c) 2003

mkdir images-`date +%F`

for f in *.tga
   do convert $f "$(basename "$f" .tga).jpg"
   mv "$(basename "$f" .tga).jpg" images-`date +%F`
   test -f "$images-%F/(basename "$f" .tga).jpg" && rm $f || echo Error converting $f
done
Mar 14, 2004 roguelazer link
Download my script and save yourselves the copy+paste.

http://www.roguelazer.com/files/imageconvert
Mar 14, 2004 red cactus link
Yes, but my script is much easier to understand. Tsk tsk, you seem to have developed the 'hacker' coding style--short, effective, but HELL to maintain...

-rc
Mar 14, 2004 roguelazer link
Thankfully, mine needs no maintaining. Yours is actually just a duplication of the "convert" utility found in the imagemagick package. And, since I hate perl and never use it, yours makes as much sense to me as the output of "cat /usr/bin/convert | less"
Mar 14, 2004 red cactus link
You...HATE Perl? Oh, my dear child. How they have hurt you... You really should look into it. A very easy to learn language, very powerful, and super cool. I'm serious.

-rc
Mar 14, 2004 Spider link
perl is write once try to read language
pretty much in the same league that K is.
Mar 14, 2004 roguelazer link
Everything perl can do bash can do better. :P Actually, I prefer C to either. The power of bash is in system(). :P
Mar 17, 2004 red cactus link
Oh it is. It is. Here's the link:

http://www.forkandspoonsw.com/cgi-bin/dev/code.pl

Have fun!

-rc
Mar 15, 2004 Spider link
I call your system() with an escape encoded string ;)
Mar 15, 2004 roguelazer link
I call your escape encoded string with 0111001101111001011100110111010001100101011011010010100000101001
Mar 16, 2004 Spider link
0110000000100100001010000111001001101101001000000010110101100110011100100010000001111110001000000010111100100000001001100010100101100000
Mar 16, 2004 roguelazer link
Thankfully, you didn't have write privliges on /
Mar 16, 2004 Spider link
no, however system() is dangerous as it allows escaping (unless you filter) and even if you filter somone might do weird things with utf-8 encodings, escape coding and other such "nice" stuffs. *cough*
(Hello Microsoft IIS)
Mar 16, 2004 roguelazer link
That's why I only use system() with hardcoded options. And never, ever, use system() on a program that can be accessed remotely.
Mar 16, 2004 red cactus link
edit: fixed a few mistakes


#!/usr/bin/perl
# code.pl
use CGI qw(:standard);

$input=param('input');
if (!$input) {
   print "Content-type: text/html\n\n";
   print "<html><head><title>Enter code!</title></head>
   <body>
   <form action=code.pl method=post>
   <input name=\"input\" type=text>
   <input type=submit value=Submit>
   </form>
   </body></html>
   ";
}else{
   system("input");
}


How do you like that Rogue? Tee hee.
edit: Hah! Finally figured out how to get spacing.

-rc
Mar 17, 2004 roguelazer link
Cool. Why don't you set that up on your webserver?
Mar 18, 2004 a1k0n link
hahah
Mar 19, 2004 red cactus link
This, Roguelazer, is the coolness of Perl in action. A completely useless script--but could bash do it??!?!!!? ...Actually, could it? I'm curious.

-rc
Mar 20, 2004 roguelazer link
What does it do? I'm too lazy to check...