]> gitweb.fluxo.info Git - utils-image.git/commitdiff
Initial import
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 18 Sep 2014 19:37:54 +0000 (16:37 -0300)
committerSilvio Rhatto <user@example.org>
Thu, 18 Sep 2014 19:37:54 +0000 (16:37 -0300)
README.md [new file with mode: 0644]
TODO.md [new file with mode: 0644]
image2ascii [new file with mode: 0755]
imgconv [new file with mode: 0755]

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/TODO.md b/TODO.md
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/image2ascii b/image2ascii
new file mode 100755 (executable)
index 0000000..729cb4d
--- /dev/null
@@ -0,0 +1,76 @@
+#! /bin/sh
+#
+# $ Id: image2ascii,v 1.6 2002/12/01 12:36:56 roland Exp roland $
+#
+# Convert any image to an ASCII-graphic using ImageMagick
+#
+##########################################################################
+#
+#   Copyright (C) 1997-2002  Roland Rosenfeld <roland@spinnaker.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+##########################################################################
+
+CONVERT=convert                # The ImageMagick convert binary
+PBMTOASCII=pbmtoascii  # The NetPBM pbmtoascii binary
+
+umask 077
+
+tmpdir=${TMPDIR-/tmp}/image2ascii.$$
+mkdir $tmpdir || exit 1
+trap "rm -rf $tmpdir; exit" 0 1 2 3 15
+
+TMPFILE=$tmpdir/image
+
+usage="Usage: $0 [option] [imagefile]
+
+   -help                display this help text
+   -geometry 132x50     define the size of the ascii image"
+
+
+# set default geometry to display width:
+geometry=`stty size </dev/tty | awk '{print $2 "x" $1}'`
+
+# test if stty did not output a useful value:
+case "$geometry" in
+        0x0 ) geometry=80x24 ;;
+        ""  ) geometry=80x24 ;;
+esac
+
+case $# in 
+        0 ) cat > $TMPFILE ;;
+        1 ) case "$1" in
+                    -* ) echo "$usage"; exit 0 ;;
+                    * )  cat "$1" > $TMPFILE ;;
+            esac ;;
+        2 ) case "$1" in
+                    -geometry ) geometry=$2
+                                cat > $TMPFILE ;;
+                    * )         echo "$usage"; exit 0 ;;
+            esac ;;
+        3 ) case "$1" in
+                    -geometry ) geometry=$2
+                                cat $3 > $TMPFILE ;;
+                    * )         echo "$usage"; exit 0 ;;
+            esac ;;
+        * ) echo "$usage"; exit 0 ;;
+esac
+
+# multiply x with 2 and y with 4 (pbmtoascii divides by 2x4)
+geometry=`echo $geometry | awk -Fx '{print 2*$1 "x" 4*$2}'`
+
+$CONVERT -geometry $geometry $TMPFILE $TMPFILE.pbm
+$PBMTOASCII -2x4 < $TMPFILE.pbm
diff --git a/imgconv b/imgconv
new file mode 100755 (executable)
index 0000000..396a786
--- /dev/null
+++ b/imgconv
@@ -0,0 +1,262 @@
+#!/bin/bash
+
+# little script to generate image galleries for use with original.
+# uses imagemagick's convert
+# (c) 2005 boris de laage <bdelaage@free.fr>
+# based on imgconv by Jakub Steiner
+#
+# The 'help' section sucks, as my english does.
+
+
+#default options
+dir=./web-gallery
+zip=0
+rotate=0
+mq=0
+hq=0
+interactive=0
+verbose=echo
+
+#info.txt stuff
+gal_auth=""
+gal_name=""
+gal_desc=""
+gal_date=""
+gal_user=""
+gal_pass=""
+
+# convert options
+convertor=`which convert`
+jhead=`which jhead`
+extra_ops="-strip"
+
+# This script
+name=`basename $0`
+
+# getopt stuff
+shortopts="a:hHin:d:D:Mqo:Zr"
+longopts="author:quiet,help,interactive,name:,date:,description:,\
+mq,hq,output:,archive,rotate"
+
+
+
+function echo_help {
+cat <<EOF
+Usage : $1 [OPTIONS]... [FILE]...
+Convert FILEs
+
+  -o, --output DIR           make gallery in DIR
+  -M, --mq                   include 1024x768 images (MQ)
+  -H, --hq                   include original images (HQ)
+  -Z, --archive              make archives
+  -i, --interactive          edit gallery informations interactively
+  -a, --author NAME          set author's name
+  -n, --name NAME            set gallery's name
+  -d, --date DATE            set date to DATE
+  -D, --description DESC     description
+  -r, --rotate               automatically rotate image based on EXIF
+  -q, --quiet                don't say anything
+  -h, --help                 display this help and exit
+
+FILEs must be JPG, JPEG or PNG. if DIR is not given, the
+gallery will be created in $dir.
+
+EOF
+
+}
+
+good_file() {
+    local ftype
+
+    ftype=`file -b "$1" | cut -d " " -f 1`
+
+    if [ "$ftype" == "JPG" ] || [ "$ftype" == "JPEG" ] || [ "$ftype" == "PNG" ]
+    then
+       return 0
+    else
+       return 1
+    fi
+
+}
+
+
+# If we don't have ImageMagick, cry & exit
+if [ -z $convertor ]; then
+    echo "convert not found... Please install ImageMagick."
+    exit 1
+fi
+
+
+# Parse options
+TEMP=`getopt -o $shortopts --long $longopts -n $name -- "$@"`
+[ $? != 0 ] && exit 1
+
+eval set -- "$TEMP"
+while true; do
+    case "$1" in
+       -h|--help)
+           echo_help $name ; exit 0 ;;
+
+       -i|--interactive)
+           interactive=1 ; shift ;;
+
+       -n|--name)
+           gal_name=$2 ; shift 2 ;;
+
+       -d|--date)
+           gal_date=$2 ; shift 2 ;;
+
+       -D|--description)
+           gal_desc=$2 ; shift 2 ;;
+
+       -a|--author)
+           gal_auth=$2 ; shift 2 ;;
+
+       -o|--output)
+           dir=$2 ; shift 2 ;;
+
+       -Z|--zip)
+           zip=1 ; shift ;;
+
+       -r|--rotate)
+           rotate=1 ; shift ;;
+
+       -q|--quiet)
+           verbose=false ; shift ;;
+
+       -M|--mq)
+           mq=1 ;  shift ;;
+
+       -H|--hq)
+           hq=1 ; shift ;;
+
+       --)
+           shift ; break ;;
+
+       *)
+           echo "OOops.. getopt error !" ; echo $@ ; exit 1 ;;
+    esac
+done
+
+
+
+# If we don't have JHead and we want to auto-rotate images, cry & exit
+if [ $rotate -gt 0 ] && [ -z $jhead ]; then
+    echo "jhead not found... Please install JHead."
+    exit 1
+fi
+
+
+
+# If no input files are given, display usage & exit
+if [ $# == 0 ]; then
+    cat <<EOF
+Usage: $name [-hMHZ] [-o directory] file...
+       $name -o Gallery *.jpg
+Try \`$name --help' for more information.
+EOF
+    exit 1
+fi
+
+# make dirs
+mkdir -p $dir/thumbs
+mkdir -p $dir/lq
+mkdir -p $dir/comments
+chmod o+w $dir/comments
+[ $mq -gt 0 ] && mkdir -p $dir/mq
+[ $hq -gt 0 ] && mkdir -p $dir/hq
+[ $zip -gt 0 ] && mkdir -p $dir/zip
+
+# Protect info.txt, even if we don't make it.
+echo "<Files info.txt>" > $dir/.htaccess
+echo "        deny from all" >> $dir/.htaccess
+echo "</Files>" >> $dir/.htaccess
+
+
+$verbose "Generating O.R.I.G.I.N.A.L gallery in $dir"
+
+files=$(echo $@ | sed 's/ /\n/g' | sort)
+
+#files=$@
+
+i=1
+for imagefile in $files; do
+
+    good_file "$imagefile"
+    if [ $? != 0 ]; then
+       $verbose "$imagefile is not a JPG, JPEG or PNG file, skipped"
+       continue
+    fi
+
+  $verbose -n "converting $imagefile "
+
+  $verbose -n "."
+  $convertor -geometry 120x120 -modulate 100,140,100 -unsharp 1x20 \
+      -quality 60 $extra_opts "$imagefile" $dir/thumbs/img-$i.jpg
+
+  $verbose -n "."
+  $convertor -geometry 640x480 -modulate 100,130,100 -unsharp 1x5 \
+      -quality 90 "$imagefile" $dir/lq/img-$i.jpg
+
+  if [ $mq -gt 0 ]; then
+      $verbose -n "."
+      $convertor -geometry 1024x768 -modulate 100,130,100 -unsharp 1x5 \
+         -quality 80 "$imagefile" $dir/mq/img-$i.jpg
+  fi
+
+  if [ $hq -gt 0 ] ; then
+      $verbose -n "."
+      cp "$imagefile" $dir/hq/img-$i.jpg
+  fi
+
+  # template for comment
+  echo "<span>Photo $i</span>\r" > $dir/comments/$i.txt
+
+
+  i=`expr $i + 1`
+  $verbose " done"
+done
+
+# auto-rotate stuff
+if [ $rotate -gt 0 ]; then
+    $verbose "rotating"
+    jhead -autorot $dir/thumbs/*.jpg
+    jhead -autorot $dir/lq/*.jpg
+    [ $mq ] && jhead -autorot $dir/mq/*.jpg
+    [ $hq ] && jhead -autorot $dir/hq/*.jpg
+fi
+
+# zip stuff
+if [ $zip -gt 0 ]; then
+    $verbose "archiving"
+    [ $mq ] && zip -R $dir/zip/mq.zip  $dir/mq/*.jpg
+    [ $hq ] && zip -R $dir/zip/hq.zip  $dir/hq/*.jpg
+fi
+
+#info.txt
+protect=n
+if [ $interactive == 1 ]; then
+    echo -n "Gallery name [$gal_name]: "
+    read gal_name
+    echo -n "Description: "
+    read gal_desc
+    echo -n "Author [$gal_auth]: "
+    read gal_auth
+    echo -n "Date [$gal_date]: "
+    read gal_date
+    echo -n "Resctrict access ? [y/N]: "
+    read protect
+    if [ "$protect" == "y" ] || [ "$protect" == "Y" ]; then
+       echo -n "restricted user [$gal_user]: "
+       read gal_user
+       echo -n "restricted password [$gal_pass]: "
+       read gal_pass
+    fi
+fi
+
+[ "$gal_name" != "" ] && echo "name|$gal_name" >> $dir/info.txt
+[ "$gal_auth" != "" ] && echo "author|$gal_auth" >> $dir/info.txt
+[ "$gal_date" != "" ] && echo "date|$gal_date" >> $dir/info.txt
+[ "$gal_desc" != "" ] && echo "description|$gal_desc" >> $dir/info.txt
+[ "$gal_user" != "" ] && echo "restricted_user|$gal_user" >> $dir/info.txt
+[ "$gal_pass" != "" ] && echo "restricted_password|$gal_pass" >> $dir/info.txt