script to convert 360 degree image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
yds
Posts: 9
Joined: 2013-09-11T16:56:12-07:00
Authentication code: 6789

script to convert 360 degree image

Post by yds »

Hi. Could use some help with a script to convert an image that is taken with a 360 degree camera into a rectilinear panoramic image. From a command line, the following ImageMagick command works wonderfully

Code: Select all

convert source_picture.jpg +distort DePolar 0 output_picture.jpg
I'd like to be able to create a web page, which runs that command on-the-fly to my original image and displays to the user the converted panoramic image. I believe I can do this using a php script, but I'm a relative newbie to writing php. Wonder if someone might be able to provide a simple php example script that would do this, that I can learn from??
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: script to convert 360 degree image

Post by fmw42 »

I am not the best at PHP, but you can run any IM command via PHP exec()

exec("path2/convert path2/source_picture.jpg +distort DePolar 0 path2/output_picture.jpg");

See http://www.rubblewebs.co.uk/imagemagick/index.php

If on Unix/Mac (or Windows w/Cygwin), you might like to see my script, fisheye2pano at the link below. It has a few more features, but is slower, since it was built before distort depolar.

Note that both distort depolar and my script require either a nadir (downlooking) or zenith (uplooking) fisheye view.
yds
Posts: 9
Joined: 2013-09-11T16:56:12-07:00
Authentication code: 6789

Re: script to convert 360 degree image

Post by yds »

fmw42 wrote: If on Unix/Mac (or Windows w/Cygwin), you might like to see my script, fisheye2pano at the link below. It has a few more features, but is slower, since it was built before distort depolar.
Thanks for this. I had actually tried your script previously. It's a bit too slow however for the "real-time" conversion I was hoping for. I will try playing around with the PHP exec option. Though I've never done any PHP scripting either, so I was hoping someone might be able to provide me with a basic script which I could learn from and build on possibly.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: script to convert 360 degree image

Post by Bonzo »

php is quite simple in your case:

Code: Select all

<?php
exec("convert source_picture.jpg +distort DePolar 0 output_picture.jpg");
?>
You can replace the input and output images with variables containing the image paths and lots of other things.

Check my website out below - I would use Imagemagick with the command line as the example above rather than Imagick which can be built into php. Imagick might be quicker but can be a pain to get working and is lacking in a lot of the options.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: script to convert 360 degree image

Post by fmw42 »

Just one further comment. Unless your PHP is set up to know where IM resides, you may have to put the path to IM convert in your command

<?php
exec("path2/convert source_picture.jpg +distort DePolar 0 output_picture.jpg");
?>

You can often find where it resides by

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

Most likely it will be at either /usr/bin/convert or /usr/local/bin/convert. Also you may find more than one version of PHP on shared servers. So you need to be sure you are using the correct one.

<?php
exec("/usr/bin/convert -version",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
yds
Posts: 9
Joined: 2013-09-11T16:56:12-07:00
Authentication code: 6789

Re: script to convert 360 degree image

Post by yds »

Thanks all. The simple exec() code worked like a charm! Takes about 1-2 seconds to convert the image and display it. Many thanks.
Post Reply