Last active
December 18, 2015 21:29
-
-
Save funasoul/5847553 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# | |
# mpo2gif: Convert MPO file to animation GIF file. | |
# | |
# Author: Akira Funahashi <[email protected]> | |
# Requirement: exiftool (sudo port install p5-image-exiftool) | |
# ImageMagick (sudo port install ImageMagick) | |
# Usage: ./mpo2gif.sh file.mpo [output.gif] | |
# | |
# Reference: | |
# 1. http://www.cipa.jp/english/hyoujunka/kikaku/pdf/DC-007_E.pdf | |
# 2. http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=16275 | |
# This is the filename of your exiftool. | |
# Change this depending on your environment. | |
exiftool=exiftool-5.12 | |
# To correctly concatinate *.jpg files to animation GIF file. | |
setopt NUMERIC_GLOB_SORT | |
if [ "$1" = "" ]; then | |
echo "Usage: $0 file.mpo [output.gif]" | |
exit 1 | |
else | |
head=$1:r | |
numimg=`$exiftool $1 | grep 'Number Of Images' | awk '{print $5}'` | |
(( tenpercent=$numimg / 10 )) | |
# first image | |
$exiftool -q -trailer:all= $1 -o ${head}-1.jpg | |
# second to end | |
echo "Extracting $numimg images." | |
foreach i ({2..$numimg}) | |
if [ "$tenpercent" != "0" ]; then | |
(( mod=$i % $tenpercent )) | |
if [ "$mod" = "0" ]; then | |
echo -n "." | |
fi | |
fi | |
$exiftool $1 -q -mpimage$i -b > ${head}-$i.jpg | |
end | |
if [ "$tenpercent" != "0" ]; then | |
echo "" | |
fi | |
if [ "$2" != "" ]; then | |
outfile=$2 | |
else | |
outfile=${head}.gif | |
fi | |
echo "Converting $1 to ${outfile}." | |
convert ${head}-*.jpg $outfile | |
echo "Removing temporal JPEG files." | |
rm ${head}-*.jpg | |
echo "Done." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment