#!/bin/bash
#
# version 1.1
# $1 is passed filename of PNG
# 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
mv "$1" `echo $1 | tr ' ' '_' | tr A-Z a-z` 2>/dev/null
newfile=`echo "$1" | sed "s/\.png/\.pdf/g"`

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" = "3300"  ]; then
	# Vertical Layout
#	convert $1 -page 850x1100 -quality $VALUE $newfile
	convert $1 -alpha off -density 300 -set units PixelsPerInch -density 300 $newfile
else
	$dialog --title "Incorrect Size" --msgbox "\nThis utility is to convert full-page images to PDFs.\nSize -> 850x1100, 72DPI.\n" 0 0
fi

