[juneau-lug] webify jpeg script
- From: James Zuelow <e5z8652@xxxxxxxxxx>
- To: juneau-lug@xxxxxxxxxxxxx
- Date: Wed, 12 Mar 2008 16:37:20 -0800
I have a small script I use to resize jpeg images and put them into html
wrappers with comments. I am in tweak mode, so version 0.4 of the script
will feature a big warning telling the user that jpeg images in the current
directory will be permanently resized (I chattr +i all of my images, but
other users might be upset when they reduce all of their photos to 800x600),
allow user entered comments for the index page (currently I just edit it with
vi after running the script) and user entered alternate text for images
(currently it just uses the image name as alternate text).
I thought it would be a good idea to also make the script a bit more portable.
As I am a KDE fanboy, it is set up for KDE only. Since my bandwidth isn't so
hot, I don't want to pull Gnome down for testing.
So questions for the group:
1) How would one determine whether you are running KDE or Gnome from a bash
script running in an xterm? Since a user could have both installed, checking
for files wouldn't work, and you can start KDE from gdm and Gnome from kdm,
so checking which is running won't work either. I suppose checking for a
running instance of kdesktop or kdeinit would work for KDE, as long as the
user only has one session open. But I can have multiple sessions open with
different GUIs and I only want to know which environment the script is being
run in.
2) What is a Gnome equivalent to this line:
kstart --type Tool display ${newimage} 2> /dev/null
kstart is part of KDE. /usr/bin/display is part of imagemagick. What kstart
is doing is pulling up display in tool mode, so that it does not grab focus
from the xterm window. The user is expected to enter comments about the
photos, and I didn't like having to click on the xterm when the script pulled
up a viewer. Output from display goes to /dev/null to keep it from echoing
stuff to the xterm the script is running in. The user should just need to
type a comment, hit enter, and the photo will change to the next one while
the script waits for the user to input text for the new photo. Very quick
and easy.
Does Gnome have a similar tool or syntax that can open display without giving
it focus with the mouse and keyboard? (Please test any possible solutions --
the KDE manpages all refer to a "--nograb" option for starting apps in KDE
that allegedly prevents the newly opened app from grabbing focus. But it
never seemed to work that way. I always needed to click back onto the xterm
window, taking my hands off of the keyboard.)
Anyhow, here is the current 0.3 version. Yes, I know it isn't the most
elegant solution. I tend to brute force my scripts.
----------------------------------------------------------------------------------------------------------
beware of lines wrapping if you copy & paste. Each line begins with
whitespace.
----------------------------------------------------------------------------------------------------------
#!/bin/bash
#################################################
# webify.sh 0.3
# simply puts an html wrapper around jpegs that
# will be resized to 800x600 (or 600x800) with
# mogrify and displayed with display.
# Depends on ImageMagick and KDE.
# this version does not link to external websites
# but could be modified to do so.
# James Zuelow // Juneau Linux User's Group
# Camp Mike Spann, Afghanistan August 31 2007
# v0.3 September 12 2007
################################################
nojpeg(){
echo " No jpegs found!"
exit
}
echo " Ensure your photos are jpegs, and that their orientation is
correct."
echo " Your photos will be ordered however the ls command orders them."
echo " To escape the script, just hit enter when prompted for a base
image name."
echo " ---"
echo "Checking for jpeg files. Script will exit if none found."
ls . | grep -i .jpg &> /dev/null || nojpeg
(( i = 101 ))
(( j = 101 ))
(( k = 0 ))
(( l = 0 ))
echo -n "Enter base image name: "
read basename
if [ -z "${basename}" ]
then
echo "Quitting"
exit
fi
for oldimage in `ls . | grep -i .jpg`
do
mv ${oldimage} ${basename}-${i}.jpg
(( i++ ))
done
(( m = i - 1 ))
echo -n " Sizing images:"
for sizetarget in `ls *.jpg`
do
mogrify -resize @480000 ${sizetarget}
echo -n "."
done
echo -e "\nDone resizing."
echo "<HTML><HEAD>" > index.html
echo "<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html\">" >> index.html
echo "<TITLE>${basename} index</TITLE>" >> index.html
echo "<!webify.sh 0.3 James Zuelow // Juneau Linux Users Group Aug-Sep 07 //
MeS Afghanistan></HEAD>" >> index.html
echo "<BODY bgcolor=\"#000000\" text=\"#ffff99\">" >> index.html
echo "<CENTER>" >> index.html
echo "<A HREF=\"${basename}-101.html\">Start Show</A>" >> index.html
echo "</CENTER></BODY></HTML>" >> index.html
for newimage in `ls *.jpg`
do
prv=""
nxt=""
echo "<HTML><HEAD>" > ${basename}-${j}.html
echo "<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html\">" >>
${basename}-${j}.html
echo "<TITLE>${basename} ${j}</TITLE>" >> ${basename}-${j}.html
echo "<!webify.sh 0.3 James Zuelow // Juneau Linux Users Group Aug-Sep
07 // MeS Afghanistan></HEAD>" >> ${basename}-${j}.html
echo "<BODY bgcolor=\"#000000\" text=\"#ffff99\">" >>
${basename}-${j}.html
echo "<CENTER>" >> ${basename}-${j}.html
if [ $j -ne 101 ]
then
(( k = j - 1 ))
prv="<A HREF=\"${basename}-${k}.html\">Previous</A>"
fi
if [ $j -lt $m ]
then
(( l = j + 1 ))
nxt="<A HREF=\"${basename}-${l}.html\">Next</A>"
fi
echo "<P>${prv} ${nxt}</P>" >> ${basename}-${j}.html
echo "<IMG SRC=\"${newimage}\" ALT=\"${newimage}\">" >>
${basename}-${j}.html
kstart --type Tool display ${newimage} 2> /dev/null
echo -n "Enter comment for ${newimage}: "
read comment
echo "<P>${comment}</P>" >> ${basename}-${j}.html
echo "<BR><BR><BR><HR WIDTH=\"50%\"><CITE>James Zuelow 2007</CITE><HR
WIDTH=\"25%\">" >> ${basename}-${j}.html
echo "</BODY></HTML>" >> ${basename}-${j}.html
killall display &> /dev/null
(( j++ ))
done
------------------------------------
The Juneau Linux Users Group -- http://www.juneau-lug.org
This is the Juneau-LUG mailing list.
To unsubscribe, send an e-mail to juneau-lug-request@xxxxxxxxxxxxx with the
word unsubscribe in the subject header.
- Follow-Ups:
- [juneau-lug] Re: webify jpeg script
- From: Jamie
Other related posts:
- » [juneau-lug] webify jpeg script
- » [juneau-lug] Re: webify jpeg script
- » [juneau-lug] Re: webify jpeg script
- [juneau-lug] Re: webify jpeg script
- From: Jamie