Jump to content
Sign in to follow this  
jim_d

Give UltraPICs the path to Netpbm?

Recommended Posts

My web host gave me the path to Netpbm ( /usr/share/netpbm ), but I don't know what to do with it. How do I get this contribution (HTML Editor + UltraPICs Combined Contribution) to work with Netpbm?

Share this post


Link to post
Share on other sites
My web host gave me the path to Netpbm ( /usr/share/netpbm ), but I don't know what to do with it.  How do I get this contribution (HTML Editor + UltraPICs Combined Contribution) to work with Netpbm?

 

 

Bump :D

Share this post


Link to post
Share on other sites

Here are a few of the things that I have tried, but so far nothing has worked. (That is, I haven?t been able to upload images using the resize feature.)

 

1. I tried finding the correct Netpbm files for the server that I?m on, but can only find RPM versions. From what I can tell, you need more authority than I have to unpack an RPM file.

 

2. In admin/. . . /config.inc.php I changed

define("NETPBM_DIR", trim(DIR_FS_CATALOG));

to

define("NETPBM_DIR",'/usr/share/netpbm/');

 

3. I wrote some php code (!) which copied the Netpbm files located at /usr/share/netpbm to the Netpbm directory that came with this contribution. (And of course changed config.inc.php back to the way it was originally.) It turned out that I couldn?t change the permissions on the files with CPanel. (All of the permissions were at 644.) So, I moved the entire netpbm directory to another location, created a new netpbm directory under public_html, and finally copied the netpbm files over to the new directory. I was then able to chmod all of the files (and of course the directory) to 755.

 

4. I noticed that if I

chdir(trim(DIR_FS_CATALOG));

echo getcwd() . "\n";

then I get

/home/xxplans/public_html

as the result. So, I tried changing the config.inc.php again. This time I changed define("NETPBM_DIR", trim(DIR_FS_CATALOG));

to

define("NETPBM_DIR",'/home/xxplans/public_html/netpbm/');

 

5. I tried a few other things that make even less sense than the other attempts, but so far, nothing appears to make any difference at all.

 

I?ve been pushing my knowledge limits, and am quickly running out of ideas. I?ve started looking at lister.php, but haven?t really done much with that yet.

 

Also, I?ve noticed that I dont have ALL of the netpbm files that I see in config.inc.php. But I do have all of the ones shown for NETPBM_JPG. JPEGs are the only files I?ve tried uploading so far.

 

Any ideas other than ?Bump??

Share this post


Link to post
Share on other sites

OK, I got into lister.php, and stripped it down to its essence so that someone who knows what they're doing should be able to look at the code and quickly understand it, and hopefully be able to figure out what's wrong with it.

 

I've posted the entire file below. I named it test_netpbm.php and put it in public_html. I also put a JPG file named test_pic_source.jpg in public_html. I set the permissions for public_html, test_netpbm.php, and test_pic_source.jpg to 777.

 

I verified that jpegtopnm, pnmscale, and pnmtojpeg are located in /usr/share/netpbm/ and executable as my web hosting provider claims. (I used php is_executable to verify.)

 

The results are the same. That is, the new file test_pic_dest.jpg is created, but it is empty.

 

Does anybody see what the problem is?

 

test_netpbm.php:

 

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title><?php echo "Test NETPBM"; ?></title>

</head>

<body>

<p>By loading this page, I am testing to see if I can get Netpbm to work.</p>

<?php

define("NETPBM_DIR", "/usr/share/netpbm/");

define("NETPBM_JPG", "jpegtopnm \"%s\" | pnmscale %s | pnmtojpeg >\"%s\"");

$script = NETPBM_JPG;

$temp = "/home/xxplans/public_html/test_pic_source.jpg";

$width = 100;

$height = 100;

$options = "-xsize=$width -ysize=$height";

$path = "/home/xxplans/public_html/test_pic_dest.jpg";

$dir = getcwd();

chdir(NETPBM_DIR);

shell_exec(sprintf($script, $temp, $options, $path));

chdir($dir);

?>

</body>

</html>

Share this post


Link to post
Share on other sites

Up until now, I?ve been wondering if there is a problem with the way Netpbm is configured on my server. So, today I did this experiment to determine if that?s the problem:

 

I installed Gallery on my site and it was set up to use the Netpbm files located in /usr/share/netpbm. I was able to resize and rotate images without any problems.

 

Then, I changed the configuration for Gallery to use the Netpbm files located in /home/xxplans/public_html/netpbm. Again, no problems.

 

So, Netpbm appears to be functioning properly. That tells me that there really is something wrong with the Ultra-Pics contribution, or at least with my implementation of it. And, there?s something wrong with my stripped down test_netpbm.php file.

 

I think I?ll focus on test_netpbm.php for now because there is so little there. It shouldn?t be that hard to figure out . . . but it is for me! I?ve been trying to get a better understanding of php syntax, shell_exec, and particularly sprintf. Often, I?ll make changes that seem logical to me, and I?ll get parsing errors or alternatively an error that says I?m trying to call an undefined function (jpegtopnm).

 

In any case, I?d appreciate any hints, tips, advice, or solutions!

Share this post


Link to post
Share on other sites
Up until now, I?ve been wondering if there is a problem with the way Netpbm is configured on my server.  So, today I did this experiment to determine if that?s the problem:

 

I installed Gallery on my site and it was set up to use the Netpbm files located in /usr/share/netpbm.  I was able to resize and rotate images without any problems.

 

Then, I changed the configuration for Gallery to use the Netpbm files located in /home/xxplans/public_html/netpbm.  Again, no problems.

 

So, Netpbm appears to be functioning properly.  That tells me that there really is something wrong with the Ultra-Pics contribution, or at least with my implementation of it.  And, there?s something wrong with my stripped down test_netpbm.php file.

 

I think I?ll focus on test_netpbm.php for now because there is so little there.  It shouldn?t be that hard to figure out . . . but it is for me!  I?ve been trying to get a better understanding of php syntax, shell_exec, and particularly sprintf.  Often, I?ll make changes that seem logical to me, and I?ll get parsing errors or alternatively an error that says I?m trying to call an undefined function (jpegtopnm).

 

In any case, I?d appreciate any hints, tips, advice, or solutions!

Share this post


Link to post
Share on other sites

I'm finally able to get Netpbm to work after weeks of learning and testing. At this point, it appears that the problem is related to changing the directory to the Netpbm directory and then trying to execute the Netpbm command files. It doesn't seem to work for some reason. So, I changed the commands to include the Netpbm path and like magic . . . it works!

 

Next, I'm going to try to integrate what I've learned back into UltraPics.

 

I've learned a bit about file permissions. Before, I was setting all permissions to 777 just to be sure there weren't any problems, but generally that isn't necessary. However, for consistency here in this forum, I'm still working with everything in the public_html directory. That means that the usual 755 permission will not be enough for test_netpbm.php to work. That's because test_netpbm.php writes to test_pic_dest.jpg.

 

In other words, if you want to test this file for yourself without any modifications, you'll need to set your permissions in your public_html folder to allow reading, writing, and executing (use 777), and also make sure you put a valid jpeg file named test_pic_src.jpg in your public_html folder.

 

Here's the new test_netpbm.php:

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>Getting NetPBM To Work!</title>

</head>

<body>

<p>By loading this page, Netpbm will take the source file (test_pic_source.jpg) and create a reduced size image (test_pic_dest.jpg).

<?php

 

define("NETPBM_DIR", "/home/xxplans/public_html/netpbm/");

 

/* Prefix the Netpbm command files with the Netpbm directory path so that executing the files won't require changing to the Netpbm directory. */

$jtp = NETPBM_DIR . "jpegtopnm";

$psc = NETPBM_DIR . "pnmscale";

$ptj = NETPBM_DIR . "pnmtojpeg";

 

define("NETPBM_JPG", "$jtp \"%s\" | $psc %s | $ptj > \"%s\"");

$script = NETPBM_JPG;

$temp = "/home/xxplans/public_html/test_pic_source.jpg";

$width = 100;

$height = 100;

$options = "-xsize=$width -ysize=$height";

$path = "/home/xxplans/public_html/test_pic_dest.jpg";

 

/* Prints out the command pipeline to aid in understanding what this file is actually doing. */

echo "<p>This is the command pipeline being executed via shell:<p>" . sprintf($script, $temp, $options, $path);

 

shell_exec(sprintf($script, $temp, $options, $path));

 

echo "<p>Look at the list of files in the public_html directory to verify that test_pic_dest.jpg was created and that it is a scaled down version of the source file.";

 

?>

</body>

</html>

Share this post


Link to post
Share on other sites

I found a solution!

 

I found two problems. The first problem is that the Netpbm directory is not properly specified, and the second problem relates to the use of the shell_exec command in catalog/admin/htmlarea/popups/lister.php.

 

From what I can tell from some of the User Contributed Notes in the online PHP documentation of the shell_exec command ( http://www.php.net/manual/en/function.shell-exec.php ), there are cases where PHP needs to reference the FULL PATH to the application it's calling. I think this may be dependent on the type of system that it's on as well as perhaps some other factors.

 

In order to solve these two problems, make the following changes in catalog/admin/htmlarea/popups/config.inc.php:

 

find

define("NETPBM_DIR", trim(DIR_FS_CATALOG));
and replace with
define("NETPBM_DIR", trim(DIR_FS_CATALOG . "/netpbm/"));

find

define("NETPBM_BMP", "bmptopnm  \"%s\" | pnmscale %s | ppmtobmp  >\"%s\"");

define("NETPBM_GIF", "giftopnm  \"%s\" | pnmscale %s | ppmtogif  >\"%s\"");

define("NETPBM_JPG", "jpegtopnm \"%s\" | pnmscale %s | pnmtojpeg >\"%s\"");

define("NETPBM_PNG", "pngtopnm  \"%s\" | pnmscale %s | pnmtopng  >\"%s\"");

and replace with
define("NETPBM_BMP", NETPBM_DIR . "bmptopnm \"%s\" | " . NETPBM_DIR . "pnmscale %s | " . NETPBM_DIR . "ppmtobmp > \"%s\"");

define("NETPBM_GIF", NETPBM_DIR . "giftopnm \"%s\" | " . NETPBM_DIR . "pnmscale %s | " . NETPBM_DIR . "ppmtogif > \"%s\"");

define("NETPBM_JPG", NETPBM_DIR . "jpegtopnm \"%s\" | " . NETPBM_DIR . "pnmscale %s | " . NETPBM_DIR . "pnmtojpeg > \"%s\"");

define("NETPBM_PNG", NETPBM_DIR . "pngtopnm \"%s\" | " . NETPBM_DIR . "pnmscale %s | " . NETPBM_DIR . "pnmtopng > \"%s\"");

Also, make sure that the permissions in the Image folders that you plan to use are set to 777.

 

The nine Netpbm files above are the only ones you'll need in your Netpbm folder.

Share this post


Link to post
Share on other sites
I found a solution!

 

I found two problems.  The first problem is that the Netpbm directory is not properly specified, and the second problem relates to the use of the shell_exec command in catalog/admin/htmlarea/popups/lister.php.

 

From what I can tell from some of the User Contributed Notes in the online PHP documentation of the shell_exec command ( http://www.php.net/manual/en/function.shell-exec.php ), there are cases where PHP needs to reference the FULL PATH to the application it's calling.  I think this may be dependent on the type of system that it's on as well as perhaps some other factors.

 

In order to solve these two problems, make the following changes in catalog/admin/htmlarea/popups/config.inc.php:

 

findand replace with

find  and replace with

Also, make sure that the permissions in the Image folders that you plan to use are set to 777.

 

The nine Netpbm files above are the only ones you'll need in your Netpbm folder.

 

 

 

 

Just a recommendation to people installing this package for the first time. Don't use this code above as a fix. The original code that comes with the package works already. I had originally modified the original php file during my first installation of this contrib with this code above thinking it was a legit patch fix for some problem with it and my resize never worked at all. I finally remembered what I did then I uploaded the original php file from the package from maxdvd without this code change and now my files can be resized. At least the jpegs. Gif's don't resize correctly but I only needed it for jpeg anyway.


Thom

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×