Create html From A Directory Of Images

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
venom
Posts: 4
Joined: 17 Jan 2009 03:14

Create html From A Directory Of Images

#1 Post by venom » 17 Jan 2009 03:57

I have a directory of hundreds of pictures in 10 picture sets.

I'm using this naming convention for each set of 10 pictures laid out exactly like this:
ModelName-Set-Name01.jpg, ModelName-Set-Name02.jpg etc.

I have html templates with the following variables for pictures and titles like this:
<b>Model_Name</b> ..... <a href="../images/Model_image01.jpg"><img src="../images/tnModel_image01.jpg"></a>

The objective is to have the script create multiple galleries from a predefined template and place them into a hard coded directory.

What i want to do is something like this:


Steps

1) Stop the script to select html template to use for this directory

2) The script grabs a list of pictures from a directory and saves as 'Image_list.txt'

3) The script strips numbers and '.jpg' from the end of each line of 'Image_list.txt'

4) The script removes duplicate names and save them as 'Model_Image.txt' source list

5) The script gets the first set of characters before the first '-' in 'Model_Image.txt' to create 'Model_Name.txt'

6) The script then defines variables from each line in the two souce lists

7) The script parses the html template and replaces the variables

8 ) The script saves new files in directory using 'Model_Image.txt' for the file names eg. 'Model_Image.html'

9) The script deletes 'Image_list.txt' and source lists


I understand how to do steps 2 and 9 but can't figure out the rest. Google is not helping

spam_killer
Posts: 12
Joined: 10 Oct 2008 04:50

That is easy

#2 Post by spam_killer » 20 Jan 2009 09:16

You can read all post here then you can figure it out and create the batch script for your own.

If you want someone to create a COMPLETE batch script for you, I think you must pay for it.

:roll:

am I wrong??

venom
Posts: 4
Joined: 17 Jan 2009 03:14

#3 Post by venom » 05 Feb 2009 09:31

True, to have someone do it for me , i should pay, That's not wht i want. I'm just getting into the command line and want to be pointed in thr right direction.

At any rate, here is what i have so far. Was not able to figure out how to do some of the steps with native tools but here goes:

:Gallery Creator start

REM SET /P variable=template Enter HTML Template

REM steps 2 - 5

REM CREATE FILE LIST
DIR /A /B /-P /O:GEN > Images.tmp

REM REMOVE JPEG NO
SED -e "s/.......$//" Images.tmp > Image_list.txt

REM JUNK FILE NAMES
SED "s/Image_l//" Image_list.txt > Image_list.tmp
SED "s/Ima//" Image_list.tmp > Image_list.txt

REM REMOVE DUPES
SED "$!N; /^\(.*\)\n\1$/!P; D" Image_list.txt > images.tmp
REM C:\usr\local\wbin\uniq.exe Image_list.txt > Images.tmp

REM REMOVE BLANK LINES - TABS AND SPACES
SED "/^[ \t]*$/d" images.tmp > image.tmp
REM JUST BLANK LINES
REM SED "/^$/d" images.tmp > image.tmp

REM CLEANUP
MOVE /Y image.tmp Model_Image.txt
DEL /Q images.tmp Image_list.tmp Image_list.txt

REM TRUNKATE AND CREATE NAME LIST
SED "s/-.*//" Model_Image.txt > Model_Name.txt

REM ### TO DO - ASSIGN VARIABLES, CHANGE TEXT IN TEMPLATES

:Gallery Creator end


The point is if a noob doesn't know what to look for on the forums, a nudge in the right direction is sometimes all they need. Teach a man to fish...

I'm sure moste here could write this in their sleep with pure windows tools. I don;t want anyone to just give me the script. I want to understand how it works. will keep on trying to figure it out and post here. Any input will be greatly appreciated. And of course, when it's completed, Any noob can have it for free

venom
Posts: 4
Joined: 17 Jan 2009 03:14

#4 Post by venom » 10 Feb 2009 11:03

The script is finished. It works perfectly. It makes galleries based on the image set name. Had to hack a bunch of scripts to get it going.

So to anyone that wants it, here it is. You'll need a couple of tools first.

GNU sed
google.com/ncr "replace.vbs" - should be the first result.
Fundoc Software "Search and replace" (sr32.exe)

You have to set environmental variables for sed and replace.vbs or it won't work. (%UNIX%\replace.vbs STEP #7 )

Before I post the script, my questions for the guru and gurus in training are:

1) how can the search and replace functions be done without external tools?
2) if native search and replace is too complicated, how can I use replace.vbs instead of sr32.exe in STEP #8 because it's much faster but for some reason, i couldn't pass variables to it properly there.
3) how can it be shortened. I had real problems when trying to work with the image lists in %temFilesdir% so i just left them. I'm sure there are other areas that can be tweaked.
4) what's wrong / right with the script?


And now the script.

To use it, all you need to do is:

1) drop it in a directory where you have hundreds/thousands of images named and numbered accordingly.
2) your html templates must use the naming convention <a href="path/Model_Image01.jpg"><img src=path/tnModel_Image01.jpg alt="Model_Name bla bla bla" /></a>
3) set your output paths in the script ( STEP #6 )
4) double click and wait. it pops a maximized explorer window to your new galleries in a dated folder named after your html template.


Code: Select all

@ECHO OFF
TITLE Building HTML for YOUR-TEMPLATE-NAME ***! DO NOT CLOSE THIS WINDOW !***
:STEP #1 --- create image list
DIR *.jpg /A /B /-P /O:GEN > Images.tmp
SED -e "s/.......$//" Images.tmp > Image_list.txt

:STEP #2 --- remove dupes
SED "$!N; /^\(.*\)\n\1$/!P; D" Image_list.txt > images.tmp

:STEP #3 --- remove blank lines : tabs and spaces
SED "/^[ \t]*$/d" images.tmp > image.tmp

:STEP #4 --- cleanup temp files
MOVE /Y image.tmp Model_Image.txt
DEL /Q images.tmp Image_list.tmp Image_list.txt

:STEP #5 --- trunkate and create name list
SED "s/-.*//" Model_Image.txt > Model_Name.tmp
SED "$!N; /^\(.*\)\n\1$/!P; D" Model_Name.tmp > Model_Name.txt

:STEP #6 --- SETUP VARIABLES
@SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /f "tokens=1,2,3,4 delims=/ " %%a IN ('date /t') DO (
  SET CreationDate=%%b-%%c-%%d
)
: !IMPORTANT --- set your template and output paths
SET template=S:\path\to\template\dir\YOUR-TEMPLATE-NAME.html
SET templateDir=S:\path\to\output\dir\%CreationDate%-YOUR-TEMPLATE-NAME
SET galldir=S:\path\to\output\dir
SET gallimage=Model_Image.txt
SET gallname=Model_Name.txt
SET temFilesdir=%galldir%\TEMP
IF NOT EXIST %templateDir% MKDIR %templateDir%
IF NOT EXIST %temFilesdir% MKDIR %temFilesdir%

:STEP #7 --- Build the galleries
FOR /f "skip=1 tokens=*" %%A IN (%gallimage%) DO (
  SET modimage=%%~A
  ECHO Building !modimage!
  COPY %template% %temFilesdir%\!modimage!.html
  CSCRIPT %UNIX%\replace.vbs "%temFilesdir%\!modimage!.html" "Model_Image" "!modimage!"
)

:STEP #8 --- Name the models
FOR /f "tokens=*" %%f IN (%gallname%) DO (
  ECHO Processing %%f^'s galleries
  START /W /D"P:\Search & Replace\" SR32.EXE /P"%temFilesdir%\%%f*.html" /SModel_Name /R%%f /U /Q
)

:STEP #9 --- Cleanup
ECHO Cleaning up...
XCOPY %temFilesdir%\*.html %templateDir%\ /Q
DEL /Q *.txt *.tmp
RMDIR /S /Q %temFilesdir%
START explorer.exe /e,%templateDir%
ENDLOCAL

joemaher1
Posts: 2
Joined: 11 Dec 2013 10:46

Re: Create html From A Directory Of Images

#5 Post by joemaher1 » 11 Dec 2013 11:47

Hi guys .
I have 30,000 photos which I renamed, each one manually. I want to put the names online with a link to each corresponding photo.
I can extract the names with a justname.bat script .(dir /b > filenames.txt)

I also found a batch script to extract thumbnails with a link to the photo when clicked on.
This method only makes my pc freeze as the thumbnails load. Also the thumbnails go horizontal and have no names

@echo off
if exist image_list.txt del image_list.txt

for /f "tokens=*" %%G in ('dir *.jpg /b') do (echo ^<a href="%%G"^>^<img src="%%G" width="100" height="50" ^/^>^<^/a^> >> image_list.txt)
if exist image_list.txt notepad image_list.txt

if not exist image_list.txt echo Sorry, no JPG images in here.
------------------------------------------------------------------------------
I want to extract the names stacked vertically numbered if possible with a link to the photos when clicked on by batch script. or any method.
The post I am replying to seems to be what I want but I am a blank when it comes to html and scripts etc,

Joe (Noob)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Create html From A Directory Of Images

#6 Post by foxidrive » 11 Dec 2013 19:27

You might like to try a program dedicated to creating HTML from file.
I've used this in the past and it worked well. See if you can find a copy - this version is free for a month.

Code: Select all

CD2HTML v5.0.0 beta by Falk Petro (May 2002)

CD2HTML is a very handy Win95/98/NT/Me/2000 program which
automatically creates clear and fully configurable HTML
pages out of directories and files. The collected information
can be used together with CD2HTMLs own script language to
create your own HTML templates. CD2HTML can create links,
thumbnails/icons of pictures (supports JPG, GIF, PNG, TIFF
and BMP) and files, extract information from MP3 files (file
information plus reading and writing the ID3 tag), descriptions
and if applicable, the index of files even within archive files
(supports internal Zip/UnZip/UnRAR).

Very useful for Internet/Intranet administrators and people
who want to index their CD's, because it's also possible to
print CD-covers and export them to *.EMF format (Enhanced
MetaFile) or copy them to the clipboard.

CD2HTML is Shareware and a license can be ordered for 20 EUR.
Before registering the program can be tested without any
qualification for one month. While testing all features will
be available.

Written by Falk Petro (1996-2002).

joemaher1
Posts: 2
Joined: 11 Dec 2013 10:46

Re: Create html From A Directory Of Images

#7 Post by joemaher1 » 12 Dec 2013 17:09

Spot on with that software. I tried the reg version ,worked for a while and just kept crashing. The free version works great and actually got what I wanted. .I also want to get rid of the .jpg
ext. and that is not a major drawback either if I cant. Just looks better without it so I will play around with it .

Thanks for your input

zpimp
Posts: 12
Joined: 14 Jun 2013 12:58

Re: Create html From A Directory Of Images

#8 Post by zpimp » 12 Dec 2013 23:27

done something like this, resizing with irfanview from commandline
i think is normal to freeze @ 30,000 images per page. it probably runs out of memory or something

include a javascript function with document write for each set, taking the name-of-set as argument

i once made a single html/js file to browse thousand of pictures from a wallpaper site, it opened next page of pictures in new window closing the one that was open (i could do this cause they were numbered one after another)

put up an example

Post Reply