Page 1 of 1

TUTORIAL: Using NConvert with PHP

Posted: Fri Feb 16, 2007 11:36 pm
by daniel
NConvert is a quite powerfull tool and comparing it to Imagemagick it has some relevant performance advantages. To be tested is the multiple user access on webservers and how stable the latest release is. So please feel free trying this approach out and report your experiences here if you like.

It is not much different to implement into your PHP code, and here is a basic snippet how to do it.

Required is PHP, a webserver, OSX, linux or Windows. And of course NConvert. Make the nconvert folder accessable for your PHP built. Than you can use it doing the following:

Code: Select all

define('XNVIEW_HOME','C:/Programme/XnView/');	# Windows enviroment, Path to XnView
$cmd = XNVIEW_HOME."nconvert -out jpeg -o ".$target." -thumb 500 500 ".$source;
Big performance improvement is the -thumb flag in xconvert. This can quickly downsize your image (in this example to 500px) of any file format (add ghostscript to process vector files). The second value (500 in this example) is needed but is keeping the aspect ratio. Don't wonder about it, just use the same value as for the width. The ratio is kept, without the value it won't work.

To gather quickly all information about a picture, use the following:

Code: Select all

$cmd = XNVIEW_HOME."nconvert -info ".$image;
		exec("$cmd 2>&1", &$o, $r);
		$return = (join("\n", $o)."\n</pre>\n");
Using the -info flag gives you basicly the same information but is way faster than the -verbose flag. That is very usefull if you need to know e.g. the filesize for calculating the new resizing width or scale factor of your picture before you process it.

Please note that their might be some multi user access issues concerning your server to run into some timeouts, please read therefore all information at which deal with calling commandline codes.

I would be greatfull about any comments on any issues with this method.


Posted: Sat May 05, 2007 6:29 pm
by Guest
PHP conversion EPS to JPEG doesn't work on Mac.
For -info works just fine.
Any ideas?

Posted: Sun May 06, 2007 9:34 am
by xnview
Anonymous wrote:PHP conversion EPS to JPEG doesn't work on Mac.
For -info works just fine.
Any ideas?
NConvert use AFPL ghostscript, on Mac i have not yet implemented that