Page 1 of 1

Cylinderize script and PHP help

Posted: 2016-02-23T05:41:54-07:00
by odd_duck
I am trying to get to grips with Fred's cylinderize script in PHP but as of yet cannot output anything. I am also new to using php's exec() function.

I have installed the sh script, and also bc onto my server.

I am trying to replicate the 'Pitch in Both Directions' example here: http://www.fmwconcepts.com/imagemagick/ ... /index.php

My code is currently:

Code: Select all

<?php
$docRoot = getenv("DOCUMENT_ROOT");
exec("bash ".$docRoot."/cylinderize.sh -m vertical -r 150 -l 310 -w 100 -p 6 -d both -e 1.4 -a 0 -v background -b none -f none");
?>
But I'm unsure where I...

1. define the background image ('mug.png')
2. define the image to cylinderize ('sharks.png')
3. how/where I actually output the image in the browser

Can anyone help? Apologies if this is all straight forward and I am missing anything obvious but I am very new to this.

Re: Cylinderize script and PHP help

Posted: 2016-02-23T08:37:55-07:00
by Bonzo
I would try:

Code: Select all

<?php
$docRoot = getenv("DOCUMENT_ROOT");
exec("bash ".$docRoot."/cylinderize.sh -m vertical -r 150 -l 310 -w 100 -p 6 -d both -e 1.4 -a 0 -v background -b none -f none sharks.png mug.png output.png");
?>
You would probably submit the sharks.png from a form if you have user input or hardcode it otherwise. If you are doing a lot of files you could loop over the files and sharks.png would be a variable.

In this case you would probably need to save the file and then display it.

Re: Cylinderize script and PHP help

Posted: 2016-02-23T09:00:37-07:00
by odd_duck
Thank you Bonzo, really appreciate that. it all works and now saves the file as output.png like you state at the end of the command.

Is there way I can store the image as a variable (to use later on in my script) rather than saving it onto the server?
I'd like to output it like so in the browser not as a saved file:

header("Content-Type: image/jpg");
echo $imagick->getImageBlob();

Re: Cylinderize script and PHP help

Posted: 2016-02-23T09:39:43-07:00
by Bonzo
I am not quite sure and as you may have found the script will not run in Imagick.

You could try:
Have your code on its own on a php page called for instance mug.php
then on another page have <img src="mug.php">

Re: Cylinderize script and PHP help

Posted: 2016-02-23T09:51:35-07:00
by odd_duck
The main thing is making sure I can output the file as an image in the browser without actually saving it on the server? Is that possible?

Re: Cylinderize script and PHP help

Posted: 2016-02-23T09:56:28-07:00
by Bonzo
I had not tried my last post for a few years and looking back it probably needs a bit more code on the php page:

Code: Select all

<?php
$docRoot = getenv("DOCUMENT_ROOT");
system("bash ".$docRoot."/cylinderize.sh -m vertical -r 150 -l 310 -w 100 -p 6 -d both -e 1.4 -a 0 -v background -b none -f none sharks.png mug.png JPG:-");
header("Content-type: image/jpeg");
?>
Or on the same page where you want the image displayed replace exec with system and the output as JPG:-

Code: Select all

<?php
$docRoot = getenv("DOCUMENT_ROOT");
system("bash ".$docRoot."/cylinderize.sh -m vertical -r 150 -l 310 -w 100 -p 6 -d both -e 1.4 -a 0 -v background -b none -f none sharks.png mug.png JPG:-");
?>

Re: Cylinderize script and PHP help

Posted: 2016-02-23T10:19:54-07:00
by odd_duck
Really sorry to keep going on but when I try either of the above I get an output of:

http://tiltworld.co.uk/cylinder.php

For that page my exact code is below but I have also tried without the header(Content...) with the same result.

Code: Select all

<?php
$docRoot = getenv("DOCUMENT_ROOT");
system("bash ".$docRoot."/cylinderize.sh -m vertical -r 150 -l 310 -w 100 -p 6 -d both -e 1.4 -a 0 -v background -b none -f none sharks.png mug.png JPG:-");
header("Content-type: image/jpeg");
?>

Re: Cylinderize script and PHP help

Posted: 2016-02-23T10:46:19-07:00
by Bonzo
I sometimes had that and removing the header part used to work. At the bottom of your image you will see a header error; I would recommend trying this on a page of its own to get it working and when it works try it on a real webpage.

I can not try the code at the moment but will have a go later this evening and see what I get.

Re: Cylinderize script and PHP help

Posted: 2016-02-23T14:17:42-07:00
by Bonzo
I have tried to run the script on my server but although bcmath is installed the script can not find it!

Another thing to try is change system to passthru

Re: Cylinderize script and PHP help

Posted: 2016-02-24T04:32:07-07:00
by odd_duck
Managed to get this working now by using passthru and echo'ing it out after setting the header type

Code: Select all

<?php
$docRoot = getenv("DOCUMENT_ROOT");
header("Content-type: image/jpeg");
echo passthru("bash ".$docRoot."/cylinderize.sh -m vertical -r 150 -l 310 -w 100 -p 6 -d both -e 1.4 -a 0 -v background -b none -f none sharks.png mug.png JPG:-");
?>
Thank you for your help in getting this working :)

Re: Cylinderize script and PHP help

Posted: 2016-02-24T05:46:52-07:00
by Bonzo
That's OK and I am glad you have it working now.

Re: Cylinderize script and PHP help

Posted: 2016-02-24T10:16:42-07:00
by fmw42
odd_duck wrote:Managed to get this working now by using passthru and echo'ing it out after setting the header type

Code: Select all

<?php
$docRoot = getenv("DOCUMENT_ROOT");
header("Content-type: image/jpeg");
echo passthru("bash ".$docRoot."/cylinderize.sh -m vertical -r 150 -l 310 -w 100 -p 6 -d both -e 1.4 -a 0 -v background -b none -f none sharks.png mug.png JPG:-");
?>
Thank you for your help in getting this working :)

Would you post the full code including the part that does the display for the benefit of others.

Re: Cylinderize script and PHP help

Posted: 2016-02-24T11:26:27-07:00
by Bonzo
Would you post the full code including the part that does the display for the benefit of others.
The code posted should run your script and display the image using the echo on the passthru line with the JPG:-

Re: Cylinderize script and PHP help

Posted: 2016-02-24T11:37:14-07:00
by fmw42
Bonzo,

OK. Thanks. I overlooked the echo. I had assumed it had to go via an <img ...> html tag. So I was wondering how the JPG:- standard out was being transferred to the display.

Re: Cylinderize script and PHP help

Posted: 2016-02-24T13:55:12-07:00
by Bonzo
I have used the image tag in the past for on the fly images but not using one of your scripts. It is a shame I am having a problem with bcmath as I could have tried it.