Author Topic: Easy to use scripts for a very nice looking pop up picture show.  (Read 2016 times)

DrDOS

  • Guest
These two scripts combine to let you make a popup, click to close full screen thumbnail picture show.  The first is a shell script, name it .create and put it in your Home directory. You will need to enable show hidden files to do it, as it will normally be hidden. The second on is just some javascript that needs to be copied into the thumbnail pages to make the popup windows, and make them work properly and presntably. Rename it .myscript.txt and also put it in your home folder.  Note the dot (period) in front of each filename.
Code: [Select]
#!/bin/sh
IFS=$'\t\n'
mkdir New
cp *.jpg New
cd New
cnt=100
for i in ./*.jpg; do
let cnt=cnt+1
mv $i $3$cnt.jpg
done
montage -adjoin -border 1 -geometry $1 -background '#000' -tile $2 *.jpg $4.html
mogrify -transparent '#000' *.gif
sleep 2
sed -i '/<\/title>/r '$HOME'/.myscript.txt' *.html
sed -i '1,$s/<body>/<body bgcolor=\"#000\">/g' *html
sed -i "1,\$s/href=\"/href=\"#\" onClick=\"javascript:newwin(\'/g" *.html
sed -i "1,\$s/jpg\"/jpg\')\;\"/g" *.html
rm *.shtml
exit

# Open a terminal in the working directory.
# Usage: bash $HOME/.create "width of thumbnail images" "columns and rows" "file name of images" "file name of thumbnail pages"
# Example bash $HOME/.create 200 5x4 Lake_visit Vacation
# Enclose the text in double quotes if there are any spaces

Code: [Select]
<script>
function newwin(URL){var mywin=open('','','scrollbars=0, menubar=0');mywin.document.write("<html><head><title>Click image to close.</title><style>body {background-color:#000;color:#fff;width:800px;margin:auto}table{width:100%;height:100%}td{text-align:center;vertical-align:middle}img{border:2px solid #ffffff}</style><\/head><body bgcolor='#000' onClick='self.close();'><center><h3><\/h3><table><tbody><tr><td><img src='"+URL+"'><\/td><\/tr><\/tbody><\/table><p><\/p><\/center><\/body><\/html>");mywin.document.close();}
</script>
 

To use them, just open a terminal in the folder with your pictures and enter:

bash $HOME/.create 160 6x5 our_trip grandma_visit

to make an album in which the individual thumbnails are 160px wide, in a 6 by 5 array, the pictures are named "our_trip101.jpg, etc.  and the HTML pages are named "grandma_visit.html". If you have more than 30 pictures in this example more HTML pages will be made and they will automatically be named in consecutive order.

Right now this only works with files of the .jpg extension, not .JPG or .jpeg. The pictures are copied to a new folder named New and all the operations are performed in that folder, so your originals are not touched. You can rename the folder and do anything you like with it, such as upload it to the web. It uses HTML maps so it only has only thumbnail .gif per HTML page.

It takes about a day to write scripts like this, mostly depending on the debugging involved. If you have any good ideas for scripts you would like to see, let me know and I'll try to write it for you.
« Last Edit: June 12, 2009, 07:56:42 PM by DrDOS »

Offline Gagarin Gambit

  • Full Member
  • ***
  • Posts: 190
  • Space technology
Re: Easy to use scripts for a very nice looking pop up picture show.
« Reply #1 on: June 13, 2009, 06:11:43 AM »
That's an interesting idea. And I hadn't thought that javascript and html pages can be used this way.

There's something I wonder if it's possible. Can a script be used to have an application launch instead of a screen saver? This should probably be combined with a daemon, just like you can have timed scripts with cron. Or it can be created only as a screensaver and thus is more complicated? I already know some javascript and I intend to learn python in the future, and this is one of the things I'd like to try then.
Linux. Space technology.

DrDOS

  • Guest
Re: Easy to use scripts for a very nice looking pop up picture show.
« Reply #2 on: June 13, 2009, 09:07:32 AM »
That's an interesting idea. And I hadn't thought that javascript and html pages can be used this way.

There's something I wonder if it's possible. Can a script be used to have an application launch instead of a screen saver? This should probably be combined with a daemon, just like you can have timed scripts with cron. Or it can be created only as a screensaver and thus is more complicated? I already know some javascript and I intend to learn python in the future, and this is one of the things I'd like to try then.
You can certainly do these kinds of things. But the problem is that the malware writers do them all the time to try to get some bad stuff on people's computers. So the browser makers have at least made  it so that you have to have permission to make any changes involving the file system or running applications.

In this script the shell, bash, just uses sed, the Stream Editor, to write the Javascript to an existing web page, it doesn't interact with the Javascript in any way. It is possible to pass arguments from Javascript to the shell but Firefox will throw up a warning and ask if you want to give permission for this to happen. It turns out that the permission appears to be global, not based on any identification of the requester, so it looks like a possible weakness to me. I've actually done this, and it works very well, but I was reluctant to publish the results because of the security hole it seemed to open.

By the way, I started out with the intention of writing a script for a popup show where the page fits the images, not full screen like this one, but I haven't worked out the way to get Javascript to cooperate with the shell. For that kind of show the Javascript is needed to generate all the image size information while the Imagemagick parts generate the image map information. The script I've posted here will work with many pictures in a folder and generate as many HTML pages as needed. Just as a test I tried it with neary 360 pictures and it made 15 thumbnail pages. It took about ten minutes to do it, but still a lot less time that doing it by copy and paste.

PS: Just to make a liar out of myself I wrote a version that makes a popup that fits the image instead of full screen. The major difference is that it uses one big javascript file, .js, to hold all the image data and links for the several pages used. However you could easily copy and paste all the data into the individual pages and eliminate the .js file itself.

PPS: It turns out to be very easy to integrate these kind of scripts with Lightbox, so you could automagically generate your own Lightbox shows from pictures on your hard drive, or from pictures found on the web by using it in conjunction with the ImageDownloader Firefox add on.
« Last Edit: June 15, 2009, 08:50:01 AM by DrDOS »