#!/bin/bash
#
# version 1.1
# $1 is passed filename of jpg
# is used to convert FULL-PAGE images
# 850x1100 (or 1100x850) at 72DPI

if [[ "$DISPLAY" && "$(which Xdialog 2>&1 | grep -v "which: no")" ]]; then
	dialog="Xdialog"
else
	dialog="dialog"
fi

pth=`dirname "$1"`
cd $pth
# get rid of blanks in filenames
mv "$1" `echo $1 | tr ' ' '_'` 2>/dev/null
# name the output file (PDF, naturally)
newfile=`echo "$1" | sed "s/\.jpg/\.pdf/g"`
# get width and height
w=`identify -format "%w" $1`
h=`identify -format "%h" $1`
VALUE=`zenity --scale --text="Output Quality" --value="90" --min-value="50" --max-value="100"`
if [ "$w" = "1100" ]; then
	# Horizontal Layout
	convert $1 -page 1100x850 -quality $VALUE $newfile
elif [ "$h" = "1100"  ]; then
	# Vertical Layout
	convert $1 -page 850x1100 -quality $VALUE $newfile
else
	$dialog --title "Incorrect Size" --msgbox "\nThis utility is to convert full-page images to PDFs.\nSize -> 850x1100, 72DPI.\n" 0 0
fi
