exec() and netpbm probs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tinfoilgrrl
Forum Newbie
Posts: 2
Joined: Fri Jan 24, 2003 11:41 am

exec() and netpbm probs

Post by tinfoilgrrl »

I'm trying to code a simple image resizing function using the netpbm tools. (I wish I could use GD, but in this instance, I cannot.) Netpbm works fine from the command line but I'm getting odd output when I use it from within PHP.

I'll quote the code below, but essentially this is the situation. I'm using netpbm to transform jpeg to pnm, scale the pnm, then transform back to jpeg. When I run the commands through PHP using exec() (or system()) the correct files are created, but they are 0k files and so unusable. (www has permission to write to the directory.)

However, when I echo the exact commands into the browser, then copy those and paste them into the command line, it works perfectly.

Here's the code. Both of the filenames are absolute references.

Code: Select all

<?php
$command = 'jpegtopnm ' . $image . ' > ' . IMAGE_DIR . $name . '.ppm';

exec($command);

$command =  'pnmscale -width=' . $max_width . ' ' . IMAGE_DIR . $name . '.ppm' . ' > ' .  IMAGE_DIR .  '1_' . $name . '.ppm';

exec($command);

$command = 'pnmtojpeg ' . IMAGE_DIR .  '1_' . $name . '.ppm' . ' > ' . IMAGE_DIR . $name;

exec($command);

?>
If it didn't work at all, I'd be less puzzled than what's happening. Any suggestions would be greatly appreciated.

Apache/1.3.26, PHP 4.1.2, OS X 10.2.3, Netpbm 9.25

-tinfoilgrrl
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you might fetch the output and examin it. Maybe it has some usefull information

Code: Select all

exec ($command, $output);
echo '<pre>'; print_r($output); echo '</pre>';
http://www.php.net/manual/en/function.exec.php
tinfoilgrrl
Forum Newbie
Posts: 2
Joined: Fri Jan 24, 2003 11:41 am

Post by tinfoilgrrl »

Thanks for the suggestion. I tried it, but there was no output.

I finally figured out the problem through trial and error. When calling the netpbm tools by using exec(), I had to give the full location of the tool, like /sw/bin/jpegtopnm. Once I added that, it worked fine.
noobSaibot
Forum Newbie
Posts: 1
Joined: Sun Aug 10, 2003 3:49 am
Location: Europe [Germany]

still problem with netpbm

Post by noobSaibot »

Hi tinfoilgrrl,

i have the same problem. i get a 0KB File, so it's unusable for further transformation. Even with the full path to the netpbm binaries.

Code: Select all

$bin_dir = "c:/Programme/Apache Group/Apache2/htdocs/bildbearbeitung/php_netpbm/netpbm/bin/";
$gifToPnm = $bin_dir . "giftopnm";
$gifFile = "c:/gif_bild.gif";
$output = array();

exec ("$gifToPnm $gifFile > c:/pnm_bild.pnm", $output, $return);
print_r ($output);
print "<br>$return";
The output is:

Code: Select all

Array()
1
And the filesize of c:/pnm_bild.pnm is 0 KB.

What's wrong?
Post Reply