Desqueeze Anamorphic Photos
Bash script to desqueeze photos taken with an anamorphic lens, requires ImageMagick to be installed. Arguments are image to scale and the horizontal scaling factor (usually 1.33) Usage: imgwiden.sh image.jpg 1.33
#!/bin/bash
echo -e "\n\tIMGWIDEN\n\tAnamorphic photo utility\n"
# Check filename argument
if [ "$1" ]; then
echo "Input file: $1"
else
echo -e "\nMissing input file.\n\n\tUsage: imgwiden filename horizontalScaleFactor\n\n\teg. imgwiden photo.jpg 1.33\n"
exit
fi
# Check scale factor argument
if [ "$2" ]; then
echo "Horizontal scale factor: $2"
else
echo -e "\nMissing scale factor.\n\n\tUsage: imgwiden filename horizontalScaleFactor\n\n\teg. imgwiden photo.jpg 1.33\n"
exit
fi
# Check ImageMagick Identify is available
if ! command -v identify &> /dev/null
then
echo -e "'identify' could not be found, make sure you have ImageMagick fully installed\n"
exit
fi
# Read image dimensions
ident="$(identify $1)"
imgDimens="$(cut -d' ' -f3 <<<"$ident")"
echo -e "Image dimensions: $imgDimens"
width="$(cut -d'x' -f1 <<<"$imgDimens")"
height="$(cut -d'x' -f2 <<<"$imgDimens")"
echo -e "Width:\t\t$width"
# Calculate target width
scaledWidth=$(echo $width \* $2 | bc -l)
echo -e "Scaled width:\t$scaledWidth"
# Check ImageMagick Identify is available
if ! command -v convert &> /dev/null
then
echo -e "'convert' could not be found, make sure you have ImageMagick fully installed\n"
exit
fi
# Stretch image using ImageMagick
filename="${1%.*}"
extension="${1##*.}"
outputFilename="${filename}_x${2}.$extension"
echo -e "Output filename: $outputFilename"
`convert $1 -resize ${scaledWidth}x${height}\! $outputFilename`
# MacOS only, open in Preview
open $outputFilename