Sunday, May 14, 2006

ImageMagick in servlets

ImageMagick is probably one of the best tools to convert between image formats and in one of my applications I try to make preview thumbnails of almost any image format -- so that seems to be a logical choice. JMagick claims to be an "open source Java interface of ImageMagick" and it looks impressive. However you have to do some special stuff to accomodate JNI in servlets. Furthermore JMagick doesn't work with some out-of-the-box ImageMagick installation -- it seems you have to compile ImageMagick yourself.

Another approach to circumvent all this is to call the convert utility as an external command Essentially you are calling "convert - jpg:-" as an external command and feeding it the source image as standard input and reading the converted image (in this case jpeg) as standard output (Note: This doesn't work with Windows 98). All the other options like scale should work that way, too.

Unfortuantely the Runtime.exec has some pitfalls so we end up with this rather luxurious solution:


public class play {

* @param args
public static void main(String[] args) throws Exception {
//set up the demo streams
FileInputStream in = new FileInputStream("/home/german/projects/anat/i1377439.MRDC.106");
FileOutputStream out = new FileOutputStream("/tmp/out.jpg");


public static void convertToJPEG(InputStream is, OutputStream os) throws IOException, InterruptedException{
System.out.println("Start ImageMagick...");
Process p = Runtime.getRuntime().exec("convert - jpg:-");
//initialize Gobblers
StreamGobbler inGobbler = new StreamGobbler(p.getInputStream(), os);
StreamGobbler errGobbler = new StreamGobbler(p.getErrorStream(), System.err);
//start them
copy2(is, new BufferedOutputStream(p.getOutputStream()));
System.out.println("Image copied...");
//copy2(p.getErrorStream(), System.err);
if (p.waitFor()!=0) {
System.out.println("End Process...");

public static void copy2(InputStream is, OutputStream os) throws IOException {
byte[] buffer = new byte[512];
while (true) {
int bytesRead =;
if ( bytesRead == -1 ) break;
os.write(buffer, 0, bytesRead);

class StreamGobbler extends Thread
InputStream is;
OutputStream os;

StreamGobbler(InputStream is, OutputStream redirect)
{ = new BufferedInputStream(is);
this.os = redirect;

public void run()
play.copy2(is, os);
} catch (IOException ioe)

Thursday, May 11, 2006

Why VC's are bad

I had the pleasure the other day to attend a start-up bootcamp on campus. Lots of Venture Capitalists (VC) were talking in little discussion groups and sharing their wisdom. Where with bio or nano companies the technology is perceived as difficult in software there is still the idea that if you spend enough money anything can be done and the idea and/or the market is the limiting factor. That is outright stupid!

If you have ever been in a software project you know the technology isn't easy like in we write a specification, ship it offshore, and get a great product back. And if you look at badly engineered systems like orkut or even myspace you understand why they come to that conclusion.

But in order to push the envelope to make really great software there is a technical challenge and it isn't easy. How many tried to do search engines -- and only some Stanford PhD's put it into the reality. Sure everybody can cut&paste together some social networking page (like myspace or orkut) but for the real big one you encounter technical challenges (how to automatically bring the right people together -- what kind of AI could do that?)

I believe that's where the value is and funding some click&paste operations might make you some money but the real big money is done with technical difficult and risky endeavours. But they don't get funded because the market is everything: If there isn't a market you don't have a product. But most companies kind of evolve. Google didn't have advertising back in the day -- they had this great technology but no business model -- that came later. So disregarding the technological challenge and hence not funding it is stupid.

Monday, May 08, 2006

SGI files for chapter 11

I remember when they demonstrated their C++ IDE back in the day (about 1994 or so) -- you could run your program in Debug, fix something, and without recompiling it would use the new code. Something which was revolutionary then and I haven't encountered until now on the Linux world. (I know MS Visusal Studio can do it -- but the generated code has trouble with Linux).

Another Gem was Cosmo Creator the very first HTML wysiwyg editor (something like a relief if you were using emacs' HTML mode). Anyway I played around but it never clicked for me. Another thing which really clicked was that every user could have his picture (taken with the Indy cam) and use that at login (click on the picture, type in password, ...).

Needless to say that OpenGL, OpenInventor and to some extend Performer were little gems all on their own. I am currently struggling with VTK and, believe me, I could work better with Inventor in 1995 then what VTK does today (needless to say that VRML is also a better standard for output than whatever VTK uses;-) I almost got a job doing Performer stuff...

Now I have a R5000 Indy (are is for RISC and, yes, MIPS used to be the processor for embedded stuff) in my house, but the Irix 6.4 I am trying to install never really boots up -- maybe one long night and I will figure it out. Irix by the way was and probably still is the best GUI operating system. All the icons where real photos -- cool, very cool.

How did the company decline? There were essentially three major decisions done wrong:
  1. They hired some Italian CEO whou couldn't speak Italian. Listen, if you are Italian and you can't speak your own language what does this say about yourself --
  2. That CEO pulled the plug on MIPS and spun it out (MIPS Technologies). The business model was to subsidise the development of high end MIPS processors to be used in SGI's hardware with the sale of older ones in volume to the embedded market. By selling the MIPS unit this model was obsolete and they had to embrace Itanic.
  3. And the other bad decision was to sell a Windows NT SGI. Terrific hardware, the best backplane ever, but who needs Windows NT?? I pointed that out to the SGI reps and they made fun of me -- sometimes I hate it when I am right. With their resources focused on the Windows thing they aboslutely missed the boat on Linux. A Linux workstation together with 4DWM (SGI's windows mananger) and all the other stuff would have been big in 1996 and probably still is...
With the risk of making myseld ridiculous: During my college years when other people had maybe posters of H&M models I had posters of most of the SGI models... With SGI, or Silicon Graphics, in chapter 11 also a part of myself died. Rest in peace!!