Cylinderize script and PHP help

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
odd_duck
Posts: 8
Joined: 2016-02-19T03:28:23-07:00
Authentication code: 1151

Cylinderize script and PHP help

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post 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.
odd_duck
Posts: 8
Joined: 2016-02-19T03:28:23-07:00
Authentication code: 1151

Re: Cylinderize script and PHP help

Post 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();
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post 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">
odd_duck
Posts: 8
Joined: 2016-02-19T03:28:23-07:00
Authentication code: 1151

Re: Cylinderize script and PHP help

Post 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?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post 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:-");
?>
odd_duck
Posts: 8
Joined: 2016-02-19T03:28:23-07:00
Authentication code: 1151

Re: Cylinderize script and PHP help

Post 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");
?>
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post 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
odd_duck
Posts: 8
Joined: 2016-02-19T03:28:23-07:00
Authentication code: 1151

Re: Cylinderize script and PHP help

Post 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 :)
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post by Bonzo »

That's OK and I am glad you have it working now.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cylinderize script and PHP help

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post 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:-
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cylinderize script and PHP help

Post 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.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post 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.
Post Reply