User Tools

Site Tools


cbds.sh

cbds.sh

This simple script creates a .cbds file from a given directory of images to be used with Comic Book DS. Needs zip, convert and bash.

#!/bin/bash
 
TO="/tmp/cbdsbuild" # temporary dir will be deleted!
 
usage="SYNOPSIS:
 
    $0 [OPTIONS] <inputdir> <ouputfile>
 
OPTIONS:
 
    -h          print this help and exit
    -m          Manga style right-to-left reading
    -t <title>  Sets the comic title
    -a <author> Sets the comic author
    -c <credit> Set an additonal credit line
 
USAGE:
 
    Call the script with an directory of image files. They need to be
    sorted in the correct order. The output file should have an .cbds
    extension.
";
 
ltr=1;
title=""
author=""
credit=""
 
#parse options
while getopts ":hmt:a:c:" Option
do
    case $Option in
        h) echo "$usage"
           exit ;;
        m) ltr=0 ;;
        t) title=$OPTARG;;
        a) author=$OPTARG;;
        c) credit=$OPTARG;;
    esac
done
shift $(($OPTIND - 1))
 
FROM=$1
OUT=$2
 
if [ ! -d "$FROM" ]; then
    echo "$usage"
    exit
fi
 
if [ -z "$OUT" ]; then
    echo "$usage"
    exit
fi
 
if [ -z "$title" ]; then
    title=`basename "$TO"`
fi
 
# clear and create tempdir:
rm -rf $TO
mkdir -p $TO
 
# create needed dirs
mkdir -p $TO/IMAGE
mkdir -p $TO/NAME
mkdir -p $TO/SMALL_N
mkdir -p $TO/SMALL_R
mkdir -p $TO/THMB_N
mkdir -p $TO/THMB_R
 
# convert images
num=0
for img in `ls -1 $FROM/*.{jpg,gif,png,jpeg,bmp}`
do
    num=$((num + 1))
 
    img=`basename "$img"`
 
    convert -scale "700x1400>" "$FROM/$img" "$TO/IMAGE/$num.jpg"
    convert -scale 256x192 "$FROM/$img" "$TO/SMALL_N/$num.jpg"
    convert -rotate 90 -scale 256x192 "$FROM/$img" "$TO/SMALL_R/$num.jpg"
    convert -scale 62x46 "$FROM/$img" "$TO/THMB_N/$num.jpg"
    convert -rotate 90 -scale 62x46 "$FROM/$img" "$TO/THMB_R/$num.jpg"
    echo "$img" > "$TO/NAME/$num.txt"
    echo $num $img;
done
 
echo "; ComicBookDS ini file
CbCredits1 = $title
CbCredits2 = $author
CbCredits3 = $credit
LeftToRight = $ltr
NbPages = $num
Version = 200
iHeight = 1400
iQuality = 90
iSize = 860000
iWidth = 700
oHeight = 192
oQuality = 90
oSize = 0
oWidth = 256
thHeight = 46
thQuality = 90
thSize = 0
thWidth = 62
" > $TO/ComicBookDS_book.ini
 
(cd $TO && zip -r - *) > $OUT
 
# clear tempdir:
rm -rf $TO
cbds.sh.txt · Last modified: 2010/11/11 18:46 by 92.195.13.77