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 » 2016-02-23T05:41:54-07:00

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: 2851
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post by Bonzo » 2016-02-23T08:37:55-07:00

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 » 2016-02-23T09:00:37-07:00

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: 2851
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post by Bonzo » 2016-02-23T09:39:43-07:00

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 » 2016-02-23T09:51:35-07:00

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: 2851
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post by Bonzo » 2016-02-23T09:56:28-07:00

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 » 2016-02-23T10:19:54-07:00

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: 2851
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post by Bonzo » 2016-02-23T10:46:19-07:00

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: 2851
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post by Bonzo » 2016-02-23T14:17:42-07:00

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 » 2016-02-24T04:32:07-07:00

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: 2851
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post by Bonzo » 2016-02-24T05:46:52-07:00

That's OK and I am glad you have it working now.

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Cylinderize script and PHP help

Post by fmw42 » 2016-02-24T10:16:42-07:00

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: 2851
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post by Bonzo » 2016-02-24T11:26:27-07:00

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: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Cylinderize script and PHP help

Post by fmw42 » 2016-02-24T11:37:14-07:00

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: 2851
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Cylinderize script and PHP help

Post by Bonzo » 2016-02-24T13:55:12-07:00

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