Php -> call C program -> return .png to php

So, I am creating a web-based application where a php file needs to call a C file with a set of parameters. These will be a set of .png file locations

Say this symbol represents the images '[]'

What I need the C program to do is load the images from their directory into memory (this directory will be on the same web server as the C program). What I need the program to then do is compile these loaded images together like this [][][][]. So basically, the files will have the same height and width, and I want the C program to put them all horizontally next to one another and then produce a large .png file with this new multiple-image file.

I'm sure you could gain an edge by
- only dealing with PNG files
- only dealing with files which have the same dimensions
- only dealing with a single output layout.

How much of an edge - hard to say. ImageMagick is already written in C or C++ to begin with, so you're not going to get a huge win. Factor in that it is already bug free and probably optimised to an extent anyway.

So you're looking at
- a few hours to figure out the exact command line to pass to montage.
vs
- several weeks of reading libpng manual, finding out how the API works, writing code to parse arguments, read files, create a new image etc etc, and debugging it.

I suggest you go with the choice 1 and actually measure some performance before embarking on choice 2.

I'm sure you could gain an edge by
- only dealing with PNG files
- only dealing with files which have the same dimensions
- only dealing with a single output layout.

How much of an edge - hard to say. ImageMagick is already written in C or C++ to begin with, so you're not going to get a huge win. Factor in that it is already bug free and probably optimised to an extent anyway.

So you're looking at
- a few hours to figure out the exact command line to pass to montage.
vs
- several weeks of reading libpng manual, finding out how the API works, writing code to parse arguments, read files, create a new image etc etc, and debugging it.

I suggest you go with the choice 1 and actually measure some performance before embarking on choice 2.