Converting portrait images to landscape

As seen here, I had a bit of an issue to get my vertical images working with the 4k Slideshow Maker. It could recognize the image orientation but would zoom the images too much as to pixelate them. This rendered the images right in the face of the viewer. I needed a way to best fit these images on the screen while the background could be black as in most other software I have used. Sure I could quickly overlay the image onto a black canvas in photo editing software and merge down the layers to create a horizontal image more suited to 4k’s liking. But I couldn’t possibly keep editing tens or hundreds of such images before making a photo dvd. It would frustrate me to no end.

To get around this tricky situation, I took help of some Imagemagick commands and put my unix scripting skills to some practical use. The idea was to create a template black background and superimpose a portrait image on top of it an save the edited image. This would give me the required files in landscape mode and thus make it more convinient to create a photo slideshow.

Well if only things were that easy. The script that I wanted write would have to be smart to check the orientation of the images and edit only those which were portrait, plus landscapes could have different aspect ratios. 16:9, 4:3, 3:2 are all valid landscape aspect ratios. I decided to go with 16:9. For the images that would be identified as portraits, I would create a black background which is 16:9 in dimensions based on the height of the current image.

To check dimensions of the image I am using the identify command from the Imagemagick suite.

$ identify image_portrait.jpg
image_portrait.jpg JPEG 1440x2560 1440x2560+0+0 8-bit DirectClass 1.752MB 0.010u 0:00.010
$ identify image_landscape.jpg
image_landscape.jpg JPEG 2560x1440 2560x1440+0+0 8-bit DirectClass 1.939MB 0.010u 0:00.019

This lists the dimensions of the image in the third column of the output, this value can then be parsed further to get the height and width of the image. This helps in identifying the image orientation.

Next command was to generate a black background template.

convert -size 2560x1440 canvas:none -fill black black.jpg

This will create a black background. The script calculates the new dimensions before creating a new template for each conversion. Finally the magic would happen using the composite command.

composite -gravity center portrait.jpg black.jpg new_landscape.jpg

This simply super imposes the first file onto the second to create the final file.

The script also works a bit to backup original files so that they remain unharmed. With some trial and error I was able to get it working just the way I wanted. The full script is here. And it results pasted below.

#!/bin/sh

if [ ! -d backup ]
then
mkdir backup
fi

alljpegs=`ls *.jpg`

for file in $alljpegs
do
fileinfo=`identify $file`
filedimensions=`echo $fileinfo | cut -d " " -f  3`
x=`echo $filedimensions | cut -d "x" -f 1`
y=`echo $filedimensions | cut -d "x" -f 2`
if [ $x -lt $y ]
then
newx=`awk -v m=$y 'BEGIN {print int((16 / 9 * m)+1)}'` # stretch to a 16:9 image
identitycommand="convert -size "$newx"x"$y" canvas:none -fill black black.jpg"
`$identitycommand`
mv $file backup/$file
composite -gravity center backup/$file black.jpg $file
fi
done

if [ -f black.jpg ]
then
rm black.jpg
fi

echo "DONE"

Seems to work for me, but I see several improvements that I can work on as time moves along. I am thinking the script could be parameterized so that user can provide the file extensions (jpg or png or some other), also specify a different acpect ratio and maybe also the solid color for the background. The idea would be to invoke this script with user defined parameters and let it work its magic.

$ makelandscapes -a 4:3 -e png -b red

where the flags mean this
-a aspect ratio taking in values like 16:9 4:3 or 3:2
-e extension of the files to process
-b fill color for the background

Also since the script depends heavily on Imagemagick commands, it would make sense to check for its installation before processing any further. I think this will make for a great utility for me and my photo dvd experiments on Linux.

Making Photo DVDs on Linux

Photo DVDs have become an ideal way to preserve memories from life events, synch-ed to some apt music, text overlays and cool menu graphics. Be it the last vacation you went on or a grand birthday bash or an adventure trip or an anniversary celebration or someone’s graduation ceremony. In this digital age, we have countless photos for all occasions and unless preserved well, these digital canvases soon go into obscurity. Photo management solutions are a good place to catalog them, but imagine how frustrating and boring things will be when you browse through scores of photos at a later time. Photo DVDs are a fun way to relive those memories.

I have always made a separate photo video for such important occasions. My go-to software for the same was a trial version of Photodex ProShow Gold. This is a fantastic program and unbeaten when it comes to making photo dvds. But it is Windows based and running it on Linux using wine is easier said than done. I have been using it on and off with some success on Linux but always found myself borrowing a friends Windows laptop to get the final job done. This irritated me, since ProShow would be the only reason why I could never be free of a Windows PC. At some point I always felt the need for a Windows to get a photo dvd done.

I set out to find an equivalent program which will eliminate the need for ProShow and ultimately Wine. There are a few contenders in this space. Linux does have options for programs to make a photo dvd. But they are just not in the same league as ProShow. I would eagerly wait for the day when Linux does have a software to rival ProShow.

The first in the list is Imagination. It will fairly do things that you would expect of it. It is easy to use and creates results which are good enough. But it does leave me wanting for more. Sure it has slide transitions and music overlay, but simple things like image pan and zoom and better transition effect are some things which I want. Lets say I would settle for Imagination as my second best option, only because I could never find something better.

The next software I checked was PhotoFilmStrip. This is a very intuitive software and users can get to using it in no time. Simply add images and music track and let it do the rest. The downfall I saw was that it does not take multiple sound tracks to go with the images when they are in large numbers. I could have lived with that as well, but when it came to rendering the video, the software simply refused to work. Waiting for long did not work either. After all the tinkering of image sequence and song tracks and pan and zoom settings, the fact that no video was being created seemed like a waste of time. Moving on…

Smile (Slideshow Maker In Linux Environment) also looked like a sensible option with download of just over 10MB. But it turned out to be just the source code bundle. No executable. I was expected to compile it and then work with it. The source code is in C++ which I am not familiar with it and so goes my chance to build and execute this software. Cant be wasting more time than what’s already been wasted.

And finally I landed with something which was workable. 4k Slideshow Maker has a simple to use interface. It lets you add images, quickly adjust their sequence, rotate them to suit orientation, add a music track and start rendering the video. It was a quick preview option as well. When it comes to saving the video, I was pleasantly surprised at the options it offered in terms of video settings and quality. After some trial and error I settled for the HD quality mp4 file format. It also has a 4k resolution saving format but it isn’t necessary since the images that I had with me were from a 5MP shooter. The images in the video had the pan and zoom and ken burn effects for transition. I prefer this motion of the images rather than stare at a static image for 5 seconds and then see some crappy transition to the next. Pan/Zoom with ken burns make the video more lively and not feel like an office presentation. So all in all things seemed to work for me.

But I was in for a surprise to see the final video. Seems the 4k slideshow maker is optimized for the landscape mode and portrait images are scaled so much that they look pixelated. Specially the selfie images that I had from a low-res front facing camera. They were bang in the face of the viewer. Too much zoom. As with other software like ProShow, I would expect it to keep orientation of the images as Portrait and fill the background with black or some other solid color, while still doing the pan and zoom. But this wasn’t the case. I wasn’t able to find any settings for this. So for now, I guess I was stuck with best results with landscape photographs only.

I eventually found a workaround to this limitation. I plan to cover it in the next blog.

After all the trial and error, I found 4k slideshow maker the best fit for my requirements. The things I liked are its simplicity. Just add photos, keep orientation as landscape for best results, add a music track. Settings allow you to set the duration for each photo and transition period. If the final video is longer than the music track, it loops the song again, which isn’t essentially bad. And it also fades out the music as the video ends so that you have a smooth finish and not an annoying, choppy end of the soundtrack. All in all I am happy with the results. Able to create a HD quality mp4 file with ease. The other formats and resolutions also include 3gp, avi, low-res output for youtube, facebook etc which are plenty of options to consider.

As a special mention, here is the hack to avoid being limited just one song for the video. It is possible to edit tracks using audio editing app like Audacity to append multiple tracks into a single long track and use it with slideshow makes. Its a bummer that this feature isn’t built in. But this hack will give the video some much needed variety in audio tracks.

Though not a perfect replacement for ProShow, 4k Slideshow Maker is the closest free software I could find. Let me trust this one to do the job until some better options are available.