diff options
Diffstat (limited to 'convert')
-rw-r--r-- | convert/contrib/Original_Script.scpt | bin | 0 -> 20608 bytes | |||
-rw-r--r-- | convert/contrib/imgconv.rb | 94 | ||||
-rw-r--r-- | convert/contrib/web-gallery | 105 | ||||
-rwxr-xr-x | convert/contrib/webgallery-zenity.pl | 160 | ||||
-rwxr-xr-x | convert/contrib/webgallery.pl | 154 | ||||
-rw-r--r-- | convert/gdk-pixbuf-convert/Makefile | 44 | ||||
-rw-r--r-- | convert/gdk-pixbuf-convert/gdk-pixbuf-convert.c | 226 | ||||
-rwxr-xr-x | convert/imgconv | 238 |
8 files changed, 1021 insertions, 0 deletions
diff --git a/convert/contrib/Original_Script.scpt b/convert/contrib/Original_Script.scpt Binary files differnew file mode 100644 index 0000000..5ff3bd5 --- /dev/null +++ b/convert/contrib/Original_Script.scpt diff --git a/convert/contrib/imgconv.rb b/convert/contrib/imgconv.rb new file mode 100644 index 0000000..676ef42 --- /dev/null +++ b/convert/contrib/imgconv.rb @@ -0,0 +1,94 @@ +#!/usr/bin/ruby + +require 'fileutils' + +if ARGV.size < 2 + puts "Usage: #$0 source_images gallery_name" + exit 1 +end + +class Gallery + + CONF = {} + CONF[:thumbs] = { :target => 'thumbs', :geom => '120x120', :quality => '60' } + CONF[:lq] = { :target => 'lq', :geom => '640x480', :quality => '90' } + CONF[:mq] = { :target => 'mq', :geom => '800x600', :quality => '80' } + + def initialize(source_dir = '.', gallery = 'web-gallery') + @source_dir = source_dir + @gallery = gallery + end + + def setup_dirs + %w(thumbs lq mq hq zip comments).each do |dir| + target = File.join(@gallery, dir) + + if File.exists? target + warn "Skipping creation of, #{target}, already exists." + next + end + + FileUtils.mkdir_p target + end + end + + def setup_access + ht = File.join(@gallery, ".htaccess") + + open(ht, 'w') do |fp| + fp.puts "<Files info.txt>" + fp.puts " deny from all" + fp.puts "</Files>" + end + end + + def create_comment(num) + comment_file = File.join(@gallery, 'comments', "#{num}.txt") + + open(comment_file, 'w') do |fp| + fp.puts "<span>image #{num}</span>" + end + end + + def convert_image(conf, src, num) + target = File.join(@gallery, conf[:target], "img-#{num}.jpg") + + cmd = "convert -geometry #{conf[:geom]} -unsharp 1x5 " + cmd += "-quality #{conf[:quality]} #{src} #{target}" + + system cmd + end + + def build_zip_files + puts "Building zip files." + system("zip -R #@gallery/zip/mq.zip #@gallery/mq/*.jpg"); + system("zip -R #@gallery/zip/hq.zip #@gallery/hq/*.jpg"); + end + + def create + setup_dirs + setup_access + + num = 1 + + Dir["#@source_dir/*.jpg"].sort.each do |src| + puts "Working on: #{src}" + + FileUtils.cp(src, File.join(@gallery, 'hq', "img-#{num}.jpg")) + + convert_image(CONF[:thumbs], src, num) + convert_image(CONF[:lq], src, num) + convert_image(CONF[:mq], src, num) + + create_comment(num) + + num += 1 + end + + build_zip_files + end +end + +gal = Gallery.new ARGV[0], ARGV[1] +gal.create + diff --git a/convert/contrib/web-gallery b/convert/contrib/web-gallery new file mode 100644 index 0000000..952f8fe --- /dev/null +++ b/convert/contrib/web-gallery @@ -0,0 +1,105 @@ +#!/bin/bash + +# Nautilus script to generate image galleries for use with original +# uses Gnome's zenity for user dialogs +# uses ImageMagick's convert +# (c) 2005 boris de laage <bdelaage@free.fr> +# based on imgconv bu Jakub Steiner + +set -e + +name=`basename $0` + +# convert options +convertor=`which convert` +extra_ops="-strip" + +#default options +dir=./web-gallery + +files=$(echo $@ | sed 's/ /\n/g' | sort) +numfiles=$# + +if [ -z $convertor ]; then + zenity --title $name --error --error-text "convert not found !" + exit 1 +fi + +if [ $numfiles == 0 ]; then + zenity --title $name --error --error-text "No input files !" + exit 1 +fi + +#progressbar stuff +steps=5 +increment=`expr 100 / \( $numfiles \* $steps \) ` +progress=0 + + +mkdir -p $dir/thumbs +mkdir -p $dir/lq +mkdir -p $dir/mq +mkdir -p $dir/hq +mkdir -p $dir/zip +mkdir -p $dir/comments +chmod o+w $dir/comments + +echo "<Files info.txt>" > $dir/.htaccess +echo " deny from all" >> $dir/.htaccess +echo "</Files>" >> $dir/.htaccess + + +i=1 + +for imagefile in $files + do + process="converting $imagefile" + + # Thumbnail + echo "#$process : thumbnail" + $convertor -geometry 120x120 -modulate 100,140,100 -unsharp 1x20 \ + -quality 60 $extra_opts $imagefile $dir/thumbs/img-$i.jpg + progress=`expr $progress + $increment` + echo $progress + + # LQ + echo "#$process : lq" + $convertor -geometry 640x480 -modulate 100,130,100 -unsharp 1x5 \ + -quality 90 $imagefile $dir/lq/img-$i.jpg + progress=`expr $progress + $increment` + echo $progress + + # MQ + echo "#$process : mq" + $convertor -geometry 1024x768 -modulate 100,130,100 -unsharp 1x5 \ + -quality 80 $imagefile $dir/mq/img-$i.jpg + progress=`expr $progress + $increment` + echo $progress + + # HQ + echo "#$process : hq" + cp $imagefile $dir/hq/img-$i.jpg + progress=`expr $progress + $increment` + echo $progress + + # Comments + echo "#$process : comments" + # template for comment + echo "<span>Photo $i</span>
" > $dir/comments/$i.txt + progress=`expr $progress + $increment` + echo $progress + + i=`expr $i + 1` + +done | zenity --progress --title="Scaling images, please wait..." --auto-close + + +( + echo "1" + echo "#Making archives" + zip -R $dir/zip/mq.zip web-gallery/mq/*.jpg + zip -R $dir/zip/hq.zip web-gallery/hq/*.jpg + echo "100" +) | zenity --progress --pulsate --auto-close --title="Zipping images" + +zenity --title $name --info --info-text "Your <b>O.R.I.G.I.N.A.L</b> gallery is ready." diff --git a/convert/contrib/webgallery-zenity.pl b/convert/contrib/webgallery-zenity.pl new file mode 100755 index 0000000..7f06826 --- /dev/null +++ b/convert/contrib/webgallery-zenity.pl @@ -0,0 +1,160 @@ +#!/usr/bin/perl -w + +# little script to generate image galleries for use with original PHP backend +# uses Gnome's zenity for user dialogs +# uses gdk-pixbuf-convert if available, otherwise convert (from ImageMagick) +# (c) 2003-2004 Jakub 'jimmac' Steiner, (c) 2003-2004 Colin Marquardt +# based on webgallery.pl by Tuomas Kuosmanen + +use strict; +use warnings; +use FileHandle; + +my $num_of_args = scalar @ARGV; + +if (!@ARGV or ($num_of_args == 0)) { + exec("zenity --error --title \"\" --text \"No args\n\nYou have to select images to work on.\""); + exit; +} + +my $GdkPixbufConvert = "gdk-pixbuf-convert"; +my $Convert = "convert"; +my $dir = "web-gallery"; + + +# try to find a scaler program +my $scaler; +$scaler = `which $GdkPixbufConvert`; +if ($scaler eq "") { + $scaler = `which $Convert`; +} +if ($scaler eq "") { + exec("zenity --error --title \"\" --text \"No scaling program\n\nYou need to have '$GdkPixbufConvert' or '$Convert' available.\""); + exit; +} +chomp $scaler; + +my @args = sort(@ARGV); +my $NumOfIncrements = 5; # 5 increments per file (as we are + # expecting to create 5 files for each + # image) +my $increment = 100 / ($num_of_args * $NumOfIncrements); +my $progress=0; +my $reply=""; + +sub make_dirs { + my $ErrMsg; + unless (-d "$dir") { + mkdir("./$dir") or + $ErrMsg .= "Could not create './$dir'!\n"; + } + unless (-d "$dir/thumbs") { + mkdir("./$dir/thumbs") or + $ErrMsg .= "Could not create './$dir/thumbs'!\n"; + } + unless (-d "$dir/lq") { + mkdir("./$dir/lq") or + $ErrMsg .= "Could not create './$dir/lq'!\n"; + } + unless (-d "$dir/mq") { + mkdir("./$dir/mq") or + $ErrMsg .= "Could not create './$dir/mq'!\n"; + } + unless (-d "$dir/hq") { + mkdir("./$dir/hq") or + $ErrMsg .= "Could not create './$dir/hq'!\n"; + } + unless (-d "$dir/comments") { + mkdir("./$dir/comments") or + $ErrMsg .= "Could not create './$dir/comments'!\n"; + } + unless (-d "$dir/zip") { + mkdir("./$dir/zip") or + $ErrMsg .= "Could not create './$dir/zip'!\n"; + } + if ($ErrMsg ne "") { + exec("zenity --error --title \"Giving Up\" --text \"Fatal Error\n\n$ErrMsg\""); + die "Errors occurred:\n$ErrMsg"; + } +} +make_dirs(); + +# ------------------------------------------------------------------------ +open(PROGRESS,"| zenity --progress --auto-close --title=\"\" \\ + --text=\"Scaling images, please wait\""); +PROGRESS->autoflush(1); + +my $i=1; +my $SetDirDate = 0; +foreach my $arg (@args) { + if (-d $arg) { # argument is a directory, skip it + $progress += ($increment * $NumOfIncrements); + print PROGRESS "$progress\n"; + next; + } + my $FileType = `file "$arg"`; + unless ($FileType =~ /image data/i) { # check for valid file type + # maybe check for JPEG and PNG explicitly? + #print $FileType; + $progress += ($increment * $NumOfIncrements); + print PROGRESS "$progress\n"; + next; + } + if ($SetDirDate == 0) { # we are looking at the first image + $SetDirDate = (stat $arg)[9]; # get mtime + if ($SetDirDate > 0) { + # (can also return -1 if strange mtime, don't use this + # time stamp then) + # set mtime of gallery directory to the one of the first + # image file: + $reply .= `touch -r "$arg" $dir`; + print "Setting mtime of $dir to $SetDirDate\n"; + } else { + # give it another try the next time around: + $SetDirDate = 0; + } + } + # thumbnails + $reply .= `$scaler -geometry 120x120 -quality 60 "$arg" $dir/thumbs/img-$i\.jpg 2>&1`; + $progress += $increment; + print PROGRESS "$progress\n"; + # LQ size + $reply .= `$scaler -geometry 640x480 -quality 75 "$arg" $dir/lq/img-$i\.jpg 2>&1`; + $progress += $increment; + print PROGRESS "$progress\n"; + # MQ size + $reply .= `$scaler -geometry 800x600 -quality 75 "$arg" $dir/mq/img-$i\.jpg 2>&1`; + $progress += $increment; + print PROGRESS "$progress\n"; + # HQ size (just copy the original) + $reply .= `cp "$arg" $dir/hq/img-$i\.jpg 2>&1`; + $progress += $increment; + print PROGRESS "$progress\n"; + # comment + open(COMM, ">$dir/comments/$i\.txt"); + print(COMM "<span>image $i</span>\n"); + close(COMM); + $progress += $increment; + print PROGRESS "$progress\n"; + $i++; + + # an error occurred: + if ($reply ne "") { + print PROGRESS "100\n"; + close(PROGRESS); + exec("zenity --error --title \"\" --text \"Fatal Error\n\n$reply\""); + die("Error while scaling"); + } +} +print PROGRESS "100\n"; +close(PROGRESS); + +# ------------------------------------------------------------------------ +open(PROGRESS, "| zenity --progress --pulsate --auto-close \\ +--title \"\" --text \"Zipping images\""); +PROGRESS->autoflush(1); +print PROGRESS "1"; +system("zip -R $dir/zip/mq.zip $dir/mq/*.jpg"); +system("zip -R $dir/zip/hq.zip $dir/hq/*.jpg"); +print PROGRESS "100\n"; +close(PROGRESS); diff --git a/convert/contrib/webgallery.pl b/convert/contrib/webgallery.pl new file mode 100755 index 0000000..d8a7ce7 --- /dev/null +++ b/convert/contrib/webgallery.pl @@ -0,0 +1,154 @@ +#!/usr/bin/perl -w +# +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# # +# Web Gallery script for Nautilus - Depends on "original" web backend # +# for displaying the gallery. # +# # +# Written in perl because I suck more with sh scripting. # +# Also needs gnome-utils for gdialog. # +# # +# Hacked together by Tuomas Kuosmanen <tigert@ximian.com> # +# Tweaked to use NetPBM by Jakub Steiner <jimmac@ximian.com> # +# Released under the GPL license. # +# # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +die "No files to convert" unless @ARGV; + +use Gtk; +init Gtk; + +@files = sort(@ARGV); + +my $dir = "web-gallery"; + +sub make_dirs { + + unless (-d "$dir") { + mkdir("./$dir") or die "Aargh.\n"; + } + unless (-d "$dir/thumbs") { + mkdir("./$dir/thumbs") or die "Aargh.\n"; + } + unless (-d "$dir/lq") { + mkdir("./$dir/lq") or die "Aargh.\n"; + } + unless (-d "$dir/mq") { + mkdir("./$dir/mq") or die "Aargh.\n"; + } + unless (-d "$dir/hq") { + mkdir("./$dir/hq") or die "Aargh.\n"; + } + unless (-d "$dir/comments") { + mkdir("./$dir/comments") or die "Aargh.\n"; + } +} + +sub make_gallery_fake { + my $foo = shift; + print ("PARAM: $foo\n"); + sleep 1; +} + + +$w = new Gtk::Window; +$label = new Gtk::Label(' Web Gallery generation in progress... '); +$pbar = new Gtk::ProgressBar; +$vb = new Gtk::VBox(0, 0); +$b = new Gtk::Button('Cancel'); +$w->add($vb); +$vb->add($label); +$vb->add($pbar); +$vb->add($b); + +$b->signal_connect('clicked', sub {Gtk->exit(0)}); +$w->signal_connect('destroy', sub {Gtk->exit(0)}); + +$w->show_all(); +$i = 0; +$pbar->update($i); + +@files = sort(@ARGV); +$num_of_files = scalar @files; +$increment = 1 / ( 5 * $num_of_files ); +$i = 1; +$progress = 0; + +make_dirs(); +#read nautilus metafile if available +open(METAXML, "./.nautilus-metafile.xml") or print("no metafile"); +@meta_xml = <METAXML>; +close(METAXML); + + +foreach $file (@files) { + + $pbar->update($progress); + $pbar->set_show_text(1); + $pbar->set_format_string("$i of $num_of_files"); + $progress += $increment; + while (Gtk->events_pending) { + Gtk->main_iteration; + } + + # do the stuff, collect error messages to a variable. + #$reply=`convert -geometry 120x120 -colors 64 -dither $file $dir/thumbs/img-$i\.png 2>&1`; + $reply=`convert -geometry 120x120 $file $dir/thumbs/img-$i\.jpg 2>&1`; + #$reply =`jpegtopnm $file | pnmscale -xysize 120 120 | ppmquant -floyd 16 | pnmtopng -interlace -compression 9 > $dir/thumbs/img-$i\.png 2>&1`; + + $pbar->update($progress); + $progress += $increment; + while (Gtk->events_pending) { + Gtk->main_iteration; + } + + $reply = $reply . `convert -geometry 640x640 $file $dir/lq/img-$i.jpg 2>&1`; + #$reply = $reply . `jpegtopnm $file | pnmscale -xysize 640 640 | ppmtojpeg --quality 80 --progressive > $dir/lq/img-$i.jpg 2>&1`; + + $pbar->update($progress); + $progress += $increment; + while (Gtk->events_pending) { + Gtk->main_iteration; + } + + $reply = $reply . `convert -geometry 800x800 $file $dir/mq/img-$i.jpg 2>&1`; + #$reply = $reply . `jpegtopnm $file | pnmscale -xysize 800 800 | ppmtojpeg --quality 80 --progressive > $dir/mq/img-$i.jpg 2>&1`; + + $pbar->update($progress); + $progress += $increment; + while (Gtk->events_pending) { + Gtk->main_iteration; + } + + $reply = $reply . `cp $file $dir/hq/img-$i.jpg 2>&1`; + + $pbar->update($progress); + $progress += $increment; + while (Gtk->events_pending) { + Gtk->main_iteration; + } + + # comment + open (COMM, ">$dir/comments/$i\.txt"); + print(COMM "<span>image $i: </span>\n"); + #check for comments in the metafile + #maybe using a proper XML parser would make sense in future + foreach $radek (@meta_xml) { + chomp($radek); + if ($radek =~ m/.*name="([^"]*)".*annotation="([^"]*).*"/) { + if ($1 eq $file) { + print(COMM "<span>$2</span>\n"); + } + } + } + close(COMM); + + $i++; + + # print possible error messages + if ($reply ne "") { + print("There was an error message: $reply\n"); + } +} + diff --git a/convert/gdk-pixbuf-convert/Makefile b/convert/gdk-pixbuf-convert/Makefile new file mode 100644 index 0000000..e350747 --- /dev/null +++ b/convert/gdk-pixbuf-convert/Makefile @@ -0,0 +1,44 @@ +PREFIX = /usr/local + +GTKCFLAGS = `pkg-config --cflags gtk+-2.0` +GTKLDFLAGS += `pkg-config --libs gtk+-2.0` +GDKPIXBUFCFLAGS = `pkg-config --cflags gdk-pixbuf-2.0` +GDKPIXBUFLDFLAGS += `pkg-config --libs gdk-pixbuf-2.0` + +CPPFLAGS = $(GTKCFLAGS) -D_GNU_SOURCE +ifeq ($(DEBUG),yes) +CFLAGS += -O2 -g +LDFLAGS = -g #-lefence +else +CFLAGS += -Os -fomit-frame-pointer +endif +CFLAGS += -Wall +CPPFLAGS += -DPACKAGE=\"$(PACKAGE)\" -DPREFIX=\"$(PREFIX)\" -DPACKAGE_LOCALE_DIR=\"$(PREFIX)/share/locale\" +CFLAGS += -MD + +MEMBERS = gdk-pixbuf-convert +LIB_MEMBERS = + +OBJS = $(patsubst %,%.o,$(MEMBERS)) +SOURCES = $(patsubst %,%.c,$(MEMBERS) $(LIB_MEMBERS)) +LIB_OBJS = $(patsubst %,%.o,$(LIB_MEMBERS)) +LIB_SOURCES = $(patsubst %,%.c,$(LIB_MEMBERS)) + +DEPS = $(patsubst %,%.d,$(MEMBERS) $(LIB_MEMBERS)) + + +all: gdk-pixbuf-convert + +gdk-pixbuf-convert: $(OBJS) + $(CC) -o $@ $^ $(GDKPIXBUFCFLAGS) $(GDKPIXBUFLDFLAGS) $(LDFLAGS) -L. + +clean: + rm -f $(MEMBERS) $(OBJS) $(DEPS) + +install: all + mkdir -p $(PREFIX)/bin + install -s $(MEMBERS) $(PREFIX)/bin/ + +uninstall: + $(RM) $(PREFIX)/bin/$(MEMBERS) + diff --git a/convert/gdk-pixbuf-convert/gdk-pixbuf-convert.c b/convert/gdk-pixbuf-convert/gdk-pixbuf-convert.c new file mode 100644 index 0000000..2bdbeca --- /dev/null +++ b/convert/gdk-pixbuf-convert/gdk-pixbuf-convert.c @@ -0,0 +1,226 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ + +/* + * gdk-pixbuf-convert.c gdk pixbuf replacement for convert geometry commands + * + * Copyright (C) 2003 Ximian Inc. + * + * Author: Larry Ewing <lewing@ximian.com> + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ + +/* + * build with + * gcc `pkg-config --cflags gdk-pixbuf-2.0` gdk-pixbuf-convert.c -o gdk-pixbuf-convert `pkg-config --libs gdk-pixbuf-2.0` + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <gdk-pixbuf/gdk-pixbuf.h> +#include <glib-object.h> + +#define d(x) x + +typedef enum { + SAVE_JPG, + SAVE_PNG +} OutputType; + +GdkPixbuf * +scale (GdkPixbuf *src, char *geom) +{ + GdkPixbuf *dest = NULL; + char *s, *e; + guint w; + guint h; + guint src_w, dest_w; + guint src_h, dest_h; + double scale_w = 1.0; + double scale_h = 1.0; + gboolean force = FALSE; + + src_w = gdk_pixbuf_get_width (src); + src_h = gdk_pixbuf_get_height (src); + + /* d(printf ("%d %d ", src_w, src_h);) */ + + s = e = geom; + + w = strtol (s, &e, 10); + /* d(printf ("%d ", w);) */ + if (e != s) { + scale_w = w / (double)src_w; + } else { + w = 100; + } + + + if (*e == 'x') + e++; + else + return NULL; + + s = e; + + h = strtol (s, &e, 10); + /* d(printf ("%d ", h);) */ + if (e != s) { + scale_h = h / (double)src_h; + } else { + h = 100; + } + + if (*e == '%') { + scale_h = h / 100.0; + scale_w = w / 100.0; + e++; + } + + /* d(printf ("%f %f\n", scale_w, scale_h);) */ + + while (*e) { + switch (*e) { + case '!': + force = TRUE; + break; + case '>': + if (scale_w >= 1.0 && scale_h >= 1.0) + scale_w = scale_h = 1.0; + break; + case '<': + if (scale_w < 1.0 || scale_h <= 1.0) + scale_w = scale_h = 1.0; + break; + default: + break; + } + e++; + } + + if (!force) { + /* Keep aspect ratio */ + scale_w = scale_h = MIN (scale_h, scale_w); + } + + dest_w = (int)(src_w * scale_w + 0.5); + dest_h = (int)(src_h * scale_h + 0.5); + + /* printf ("%dx%d\n", dest_w, dest_h); */ + + /* dest = gdk_pixbuf_scale_simple (src, dest_w, dest_h, GDK_INTERP_BILINEAR);*/ + dest = gdk_pixbuf_scale_simple (src, dest_w, dest_h, GDK_INTERP_HYPER); + + return dest; +} + +OutputType +get_filetype (char *filename) +{ + gint len = strlen (filename); + + if (len > 4 && g_ascii_strncasecmp (filename + len - 4, ".png", 4)== 0) + return SAVE_PNG; + else + return SAVE_JPG; +} + +int +convert (char *geom, char *quality, char *sfile, char *dfile) +{ + GdkPixbuf *src; + GdkPixbuf *dest; + GError *error = NULL; + + src = gdk_pixbuf_new_from_file (sfile, &error); + + if (!src) { + fprintf (stderr, "Unable to open input file"); + return 1; + } + + if (geom) { + dest = scale (src, geom); + } else { + dest = src; + g_object_ref (dest); + } + + if (!dest) + return 1; + + unlink (dfile); + if (get_filetype (dfile) == SAVE_JPG) + gdk_pixbuf_save (dest, dfile, "jpeg", &error, + "quality", quality, NULL); + else + gdk_pixbuf_save (dest, dfile, "png", &error, NULL); + + g_object_unref (src); + g_object_unref (dest); + + if (error) { + return 1; + } + + return 0; +} + +int +main (int argc, char **argv) +{ + char *dfile; + char *sfile; + char *geom = NULL; + char *quality = "100"; + + g_type_init (); + + if (argc > 4) { + int i = 1; + if (!g_ascii_strcasecmp (argv[i], "-geometry")) { + i++; + geom = argv[i++]; + if (argc < 5) + goto usage; + } + if (!g_ascii_strcasecmp (argv[i], "-quality")) { + i++; + quality = argv[i++]; + if (argc < 7) + goto usage; + if ((atoi(quality) < 0) || (atoi(quality) > 100)) { + g_print ("Value for '-quality' must be in range 0-100!\n"); + goto usage; + } + } + sfile = argv[i++]; + dfile = argv[i++]; + } else { + goto usage; + } + + return convert (geom, quality, sfile, dfile); + + usage: + g_print ("Usage:\n"); + g_print (" gdk-pixbuf-convert -geometry <X>x<Y> [-quality <0-100>] <input> <output>\n"); + g_print ("\n"); + g_print ("Example:\n"); + g_print (" gdk-pixbuf-convert -geometry 120x120 -quality 75 foo.jpg bar.jpg\n"); + exit (2); +} diff --git a/convert/imgconv b/convert/imgconv new file mode 100755 index 0000000..854b664 --- /dev/null +++ b/convert/imgconv @@ -0,0 +1,238 @@ +#!/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 +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` +extra_ops="-strip" + +# This script +name=`basename $0` + +# getopt stuff +shortopts="a:hHin:d:D:Mqo:Z" +longopts="author:quiet,help,interactive,name:,date:,description:,\ +mq,hq,output:,archive" + + + +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 + -q, --quiet don't say anything + -h, --help display this help and exit + +FILEs must be 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" == "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 ;; + + -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 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 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>
" > $dir/comments/$i.txt + + + i=`expr $i + 1` + $verbose " done" +done + +# zip stuff +if [ $zip -gt 0 ]; then + $verbose "archiving" + [ $mq ] && zip -R $dir/zip/mq.zip web-gallery/mq/*.jpg + [ $hq ] && zip -R $dir/zip/hq.zip web-gallery/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 |