Page 1 of 1

Cylinderize

Posted: 2012-02-07T11:14:03-07:00
by eswoosh
Specifically looking at the URL:
http://www.fmwconcepts.com/imagemagick/ ... /index.php

I am trying to use/implement this script using PHP (either PHP 4 OR PHP5 it doesn't matter)

I am extremely interested in getting this up and running but hitting a bit of a wall.

My IM installation is:
"Version: ImageMagick 6.5.7-9 2009-11-19 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC"

I've downloaded the cylinderize.sh script, uploaded it to my hosting, then tried to call it using the exec("...") method.

I found examples on this forum trying to explain how to load the script in PHP and I gather that I have to complete parts of the script with paths and directories to get it working.

Can someone hand-hold me through the process of getting it running? I know it's a big ask, but I've not seen (40mins - 1 hour of Googling) any PHP examples using this Cylinderize script..

So I guess if anyone wants to help the first question (dummy question) is:

1.. What is my path to IM ? (it's a shared host and I had them install it for me).

Re: Cylinderize

Posted: 2012-02-07T11:31:23-07:00
by Bonzo
There are some examples of php and Imagemagick on my site which if you can find it answer all these questions :D

Find out the path to ImageMagick

Code: Select all

 <?php
echo "<pre>";
system("type convert"); 
echo "</pre>";
?> 
or
<?php
echo "<pre>";
system('which convert',$path); print_r($path); 
echo "</pre>";
?>
1.Download the script and upload it to your server.
2.Change the permissions to 755 on the script
3.Write your php code like this using the full path to the script

Code: Select all

 <?php
    // Run the script
    exec("/FULL PATH TO CYLINDERIZE/cylinderize.sh  input output 2>&1", $array); 
    //Display any errors
    echo "<br>".print_r($array)."<br>"; 
    echo "</pre>";
    ?> 

Re: Cylinderize

Posted: 2012-02-07T11:33:32-07:00
by fmw42
to get your path, try

<?php
echo "<pre>";
system("which -a convert");
echo "</pre>";
?>

or

<?php
echo "<pre>";
system("type -a convert");
echo "</pre>";
?>

typically it will be /usr/local/bin or /usr/bin, unless they custom installed it somewhere else just for you.


To convert the script, see pointers at http://www.fmwconcepts.com/imagemagick/index.php for using with PHP exec. Be sure the script is made executable (step 3) and also make sure to follow steps 5) and 6) to set the IM command alias so you don't have to edit every IM command in the script.


To set up your PHP command something like

<?php
exec("bash pathto/cylinderize -m vertical -p 20 pathto/img5967.jpg pathto/img5967_cyl.jpg 2>&1",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>

The bash may or may not be needed. The 2>&1 and $out and foreach... echo... will allow the script to print any error messages or textual information that might help you debug. That can be removed later if you want.

Re: Cylinderize

Posted: 2012-02-07T11:36:09-07:00
by fmw42
Sorry Bonzo, we were posting at the same time.

Re: Cylinderize

Posted: 2012-02-07T12:16:02-07:00
by Bonzo
Thats Ok Fred - at least our answers were very similar 8)

Re: Cylinderize

Posted: 2012-02-07T12:28:02-07:00
by eswoosh
Bonzo - yes your pages are the top favourite for me in this topic - Must of read 2/3 of the pages on there - can i just say a huge thank you for all of your help via those pages - it really opened my eyes.

I'll post back once I've had a chance to try the methods posted by you both - thanks again

Re: Cylinderize

Posted: 2012-02-07T12:52:02-07:00
by eswoosh
Ok so:

Code: Select all

exec("bash cyl.sh -m vertical -p 20 paul.png warped_paul.png 2>&1",$out,$returnval);
foreach($out as $text)
{
echo "$text<br>";
}
Gives an output of:

Code: Select all

cyl.sh: line 174: type: cyl.sh: not found
dirname: too few arguments
Try `dirname --help' for more information.
basename: too few arguments
Try `basename --help' for more information.

I've shortened the script name because :
a) i struggle spelling cylinderize (at the best of times, least after staring at small screen for 8 hours)
b) quicker to type

Re: Cylinderize

Posted: 2012-02-07T12:52:58-07:00
by eswoosh
Line 174 from cyl.sh:

Code: Select all

174: PROGNAME=`type $0 | awk '{print $3}'`  # search for executable on path
175: PROGDIR=`dirname $PROGNAME`            # extract directory of program
176: PROGNAME=`basename $PROGNAME`          # base name of program

Re: Cylinderize

Posted: 2012-02-07T13:20:09-07:00
by fmw42

exec("bash cyl.sh -m vertical -p 20 paul.png warped_paul.png 2>&1",$out,$returnval);

cyl.sh: line 174: type: cyl.sh: not found
dirname: too few arguments
You did not provide the full path to cyl.sh? I presume you renamed the file to cyl.sh from cylinderize or cylinderize.sh. Be sure the .sh is appended if that is exactly the file name.

Try also without the bash (that is try both ways -- with and without bash).

Re: Cylinderize

Posted: 2012-02-07T13:37:41-07:00
by Bonzo
As Fred says you need the full path ro cyl.sh from the root so running the code below should give you the directory and then add the cyl.sh part.

Code: Select all

<?php
$docRoot = getenv("DOCUMENT_ROOT");
echo $docRoot;
?>
Your code will then be something lik:

Code: Select all

exec("bash /user/public/folder/cyl.sh -m vertical -p 20 paul.png warped_paul.png 2>&1",$out,$returnval);
foreach($out as $text)
{
echo "$text<br>";
}
Its good to know my site has been of use.

Re: Cylinderize

Posted: 2012-02-07T14:07:54-07:00
by eswoosh
You guys are the best.

This forum is probably the fastest, most efficient and well educated resource i think i've ever visited.

Ok so my entire script:

Code: Select all

<?php$docRoot = getenv("DOCUMENT_ROOT");
//echo $docRoot;


exec("bash ".$docRoot."/create/cyl.sh -m vertical -p 20 paul.png warped_paul.png 2>&1",$out,$returnval);
foreach($out as $text)
{
echo "$text<br>";
}
?>
Is working perfectly - thank you a million times - both of you!