TUTORIAL: Using NConvert with PHP

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, xnview

Post Reply
daniel
Posts: 8
Joined: Tue Jan 09, 2007 9:54 pm
Location: Frankfurt, Germany

TUTORIAL: Using NConvert with PHP

Post by daniel » Fri Feb 16, 2007 11:36 pm

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

//PHP
define('XNVIEW_HOME','C:/Programme/XnView/');	# Windows enviroment, Path to XnView
$cmd = XNVIEW_HOME."nconvert -out jpeg -o ".$target." -thumb 500 500 ".$source;
		exec("$cmd");
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

//PHP
$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 http://www.php.net/exec which deal with calling commandline codes.

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

daniel
Windows XP Pro SP2 | XnView 1.82.4 | GhostScript gs854w32

Guest

Post by Guest » Sat May 05, 2007 6:29 pm

PHP conversion EPS to JPEG doesn't work on Mac.
For -info works just fine.
Any ideas?
Thanks.

User avatar
xnview
Author of XnView
Posts: 33644
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Post by xnview » Sun May 06, 2007 9:34 am

Anonymous wrote:PHP conversion EPS to JPEG doesn't work on Mac.
For -info works just fine.
Any ideas?
Thanks.
NConvert use AFPL ghostscript, on Mac i have not yet implemented that
Pierre.

Post Reply