#!/bin/sh # Copyright (C) 2007 Adalbert Prokop, adalbert.prokop(%)web.de # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Last change: 2007-07-29 #set -x #debug LOGODIR=with_logo LOGOIMG="$(mktemp)" LOGOMASK="$(mktemp)" LOGOFILE= OPACITY=0.5 LOGOSDIR=$HOME/homepage-src/logos function usage() { cat >&2 <&2 exit 1 fi while [ "$1" != "--" ]; do case "$1" in -l|--logo) LOGOFILE="$2" shift 2 ;; -x|--xsize) XSIZE="$2" shift 2 ;; -y|--ysize) YSIZE="$2" shift 2 ;; -t|--text) TEXT="$2" shift 2 ;; -o|--opacity) OPACITY="$2" shift 2 ;; -f|--force) FORCEOVERWRITING=1 shift ;; --c?00) LOGOFILE=$LOGOSDIR/familie-prokop_c-${1#--c}.png TEXT="(C) http://www.familie-prokop.de/" shift ;; --?00) LOGOFILE=$LOGOSDIR/familie-prokop-${1#--}.png TEXT="from http://www.familie-prokop.de/" shift ;; --mg?00) LOGOFILE=$LOGOSDIR/mg-${1#--mg}.png TEXT="http://www.mojageneracja.pl/6414902/" shift ;; *) echo "Unknown option $1. (You shouldn't be here!)" exit 1 ;; esac done shift # get rid of "--" if [ ! -f "$LOGOFILE" ]; then echo "You have to specify a logo file." usage exit 1 fi if [ -n "$XSIZE" -a -n "$YSIZE" ]; then RESIZECMD="pnmscale -xysize $XSIZE $YSIZE" elif [ -n "$XSIZE" ]; then RESIZECMD="pnmscale -xsize $XSIZE" elif [ -n "$YSIZE" ]; then RESIZECMD="pnmscale -ysize $YSIZE" else RESIZECMD=cat fi pngtopnm "$LOGOFILE" > "$LOGOIMG" RETVAL=$? if [ $RETVAL -ne 0 ]; then echo "Logofile cannot be read" >&2 exit 1 fi pngtopnm -alpha "$LOGOFILE" > "$LOGOMASK" if [ "$#" -gt 0 ]; then # we have some files to work on mkdir -p "$LOGODIR" for file in "$@"; do if [ ! -f "$file" ]; then echo "File $file does not exist. Skipping." continue fi echo -n "Inserting $LOGOFILE into $file... " if [ -f "$LOGODIR/$file" -a -z "$FORCEOVERWRITING" ]; then echo echo "$LOGODIR/$file exists, won't overwrite" >&2 continue fi djpeg "$file" | $RESIZECMD | pamcomp -xoff 1 -yoff -1 -opacity="$OPACITY" -valign=bottom -alpha "$LOGOMASK" "$LOGOIMG" | cjpeg -opt -pro > "$LOGODIR/$file" if [ -s "$LOGODIR/$file" ]; then jhead ${TEXT:+-cl "$TEXT"} -te "$file" "$LOGODIR/$file" > /dev/null touch -r "$file" "$LOGODIR/$file" else rm -f "$LOGODIR/$file" fi echo "done." done rmdir with_logo >& /dev/null else # we have no files. in this case we work as an PNM-Filter $RESIZECMD | pamcomp -xoff 1 -yoff -1 -opacity="$OPACITY" -valign=bottom -alpha "$LOGOMASK" "$LOGOIMG" fi rm -f "$LOGOIMG" "$LOGOMASK"