Batch convert 360° panoramic shots to 2:1 ratio with padding for 360° / VR tours

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
SirCasey
Posts: 1
Joined: 2018-07-05T06:38:45-07:00
Authentication code: 1152

Batch convert 360° panoramic shots to 2:1 ratio with padding for 360° / VR tours

Post by SirCasey » 2018-07-06T06:13:28-07:00

Quickly, easily, and automatically batch convert / batch process (in Windows) an entire folder of Cardboard Camera / 360°degree panoramic (pano) pictures into a 2:1 aspect ratio with black background padding / edges so the perspective looks good in VR and doesn't give upload errors like "Photospheres must have a 2:1 aspect ratio" on Google VR Tour Creator.

More details about the batch file and how it's useful can be found on a page I made here:
https://sites.google.com/view/batchconv ... forvr/home

Posting this here because it's a script I was looking for but could not find, so had to cobble together the right set of ImageMagick commands and some nested FOR loops to make it work, and wanted to give back the results for others like me.

1) Download and install ImageMagick if you haven't already (but you're here, so chances are you have).
2) Copy the following code into a blank text file and save it as something like "2to1.bat" in the same folder with the pictures you'd like to convert

Code: Select all

setlocal enabledelayedexpansion
@echo off
for %%i in (*.JPG) do (
   for /f %%a in ('identify -format %%w "%%~i"') do (
   set /A width=%%~a /2
   echo "%%~i" !width!
   convert -monitor "%%~i" -gravity center -background black -extent 0x!width! "converted\%%~i"
   )
)
3) Create a folder in that folder called "Converted" for the batch script to put the new images in (so as to not overwrite your originals).
4) Open DOS Command Prompt via WindowsKey+R or search for CMD in the Windows menu.
5) Change directories (CD) until you're in the source images folder.
6) Run 2to1.bat (or whatever you named it).
7) Watch the magic happen!

Post Reply