|
Title | HTMLImageWithThumb |
File Name | HTMLImageWithThumb.txt |
Description | Put links to files with thumbnails to paste into web-page, to the clipboard |
Author | Vochomurka |
Parameters | ("%L", "%T") |
Plugins Called | file, vec, ini, clip |
Icon | |
Version | 1.0 |
Updated on | 16.09.2005 |
local fh = file.open(arg(1), "r") local Str, Counter, Temp, ThumbSuffix, AddBefore, AddAfter, ThumbSubDir local INIfile = "path\HTMLImageWithThumb.ini" local BigImage, i SetString Quote " if(fh > 0) do for(not(file.eof(fh))) Str = file.readstring(fh) if(Str != 0) Counter = Counter + 1 endfor else messagebox("ok error", "File not opened", "FILE plugin error") quit endif v = vec.create(Counter) if(v == 0) do messagebox("ok error", "Vector not created", "VEC plugin error") quit endif if(ini.check_exists(INIfile, "Configuration", "ImagePath") != 3) do ImagePath = "" else ImagePath = ini.get(INIfile, "Configuration", "ImagePath") endif if(ini.check_exists(INIfile, "Configuration", "ThumbSuffix") != 3) do ThumbSuffix = "_t" else ThumbSuffix = ini.get(INIfile, "Configuration", "ThumbSuffix") endif if(ini.check_exists(INIfile, "Configuration", "AddBefore") != 3) do AddBefore = "" else AddBefore = ini.get(INIfile, "Configuration", "AddBefore") endif if(ini.check_exists(INIfile, "Configuration", "AddAfter") != 3) do AddAfter = "" else AddAfter = ini.get(INIfile, "Configuration", "AddAfter") endif if(ini.check_exists(INIfile, "Configuration", "ThumbSubDir") != 3) do ThumbSubDir = "" else ThumbSubDir = ini.get(INIfile, "Configuration", "ThumbSubDir") endif if(ImagePath == "%T") do ImagePath = arg(2) local Len = length(ImagePath) local Char local Slash = -1 if(ini.check_exists(INIfile, "Configuration", "PathDepth") != 3) do Temp = "Key 'PathDepth' does not exist in section 'Configuration' of file '" Temp = Temp ++ INIfile ++ "'" messagebox ("ok error", Temp, "INI plugin error #1") quit all endif local Depth = ini.get(INIfile, "Configuration", "PathDepth") for(local i = Len; i > 0; i = i - 1) Char = select(ImagePath, i, i) if(Char == "\") do Slash = Slash + 1 if(Slash == Depth) do ImagePath = select(ImagePath, i + 1, Len) break endif endif endfor ImagePath = replacechars(ImagePath, "\/") endif local SmallImage file.restart(fh) for(i = 0; i < Counter; i = i + 1) BigImage = file.name(file.readstring(fh)) SmallImage = BigImage ++ ThumbSuffix ++ ".jpg" if(ImagePath != "") do BigImage = ImagePath ++ BigImage endif v[i] = "<a href=" ++ Quote ++ BigImage ++ ".jpg" ++ Quote ++ "><img SRC=" if(ThumbSubDir != "") do v[i] = v[i] ++ Quote ++ ImagePath ++ ThumbSubDir ++ "/" endif v[i] = AddBefore ++ v[i] ++ SmallImage ++ Quote ++ "></a>" ++ AddAfter endfor file.close(fh) Str = vec.makelines(v) clip.set(Str) vec.destroy(v) vec.unload
This script could be useful for people who edit web pages with links to files (usually jpg-format pictures) with thumbnails. As a rule, they are copied to a separate directory. Therefore, there are 3 paths to:
The third path is either child of the second or equal to it.
Script settings are stored in the ini-file with the following keys:
[Configuration]
ThumbSubDir=Thumbs
;Name of child dir with thumbnails.
;If thumbnails are in the same dir as main images,
;set equal to "" or type ; before key
ImagePath=%T
;if %Ò, then path to main images is taken from opposite panel
;Otherwise set equal to "" or type ; before key
PathDepth=2
;Valid only if ImagePath=%T.
;Sets path depth to thumbnails relative to current dir
ThumbSuffix=_t
;String to add after thumbnail name
AddBefore=""
;String before link
AddAfter=<p>
;String after link
Let's consider an example. Configuration is stored in the HTMLImageWithThumb.ini and explained above. Web page is in the current directory (say, left panel), containing subdirectory Galleries. The latter contains some galleries named Vasia, Masha, etc.
Configuration key ImagePath=%T means that in the opposite (right) panel we have to open the Galleries\Vasia path. The PathDepth=2 key indicates that the depth level, counting from Galleries\Vasia to the current path, is equal to 2.
In the current (left) panel we open the Galleries\Vasia directory, where main images are stored. Thumbnails to them are in Galleries\Vasia\Thumbs.
In the left panel we select some images, for example
Vasia1.jpg
Vasia2.jpg
Vasia3.jpg
Corresponding thumbnails are in Galleries\Vasia\Thumbs and are named as
Vasia1_t.jpg
Vasia2_t.jpg
Vasia3_t.jpg
Now everything is ready to run the script. Then we go to our editor and execute the "Paste" command. The result is:
<a href="Galleries/Vasia/Vasia1.jpg"><img SRC="Galleries/Vasia/Thumbs/Vasia1_t.jpg"></a><p>
<a href="Galleries/Vasia/Vasia2.jpg"><img SRC="Galleries/Vasia/Thumbs/Vasia2_t.jpg"></a><p>
<a href="Galleries/Vasia/Vasia3.jpg"><img SRC="Galleries/Vasia/Thumbs/Vasia3_t.jpg"></a><p>
That's it. Save it, open it in your browser, and enjoy.
Main Page | Total Commander | PowerPro |