Montage & Zoom-to-Fill folder thumbnails

Discuss and share scripts and script files...
Post Reply
klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Montage & Zoom-to-Fill folder thumbnails

Post by klownboy »

Based on updates made more recently over here in this thread viewtopic.php?f=5&t=23829, I figured I might as well update this old script for generating folder thumbnails. Hopefully it's more all-around useful for generating folder thumbs. It will generate single pic thumbs or montage thumbnails. You can't piece together images using XY or DOS alone so the montage menu items use ImageMagick and IrfanView (see the comment notes in the beginning of the script for download info).

To obtain views as shown in the pics, your main or parent folder that display the folder subs (e.g., D:\Wallpaper or F:\Photos must be in a square thumbnail size like 240x 240 or 300x300). In my case, I have my main or parent folder as 240x240 [thumbnail size #3] with including subfolders not checked in FVS and my sub folders under it have a different size like 240x135 [thumbnail size #2]. So your saved FVSs would reflect D:\Wallpaper\ with 240x240 and another for D:\Wallpaper\* for sub folders of the 240x135 size. Of course you could also have both the main and subs all the same like 240x240 with a single FVS of D:\Wallpaper\ with including subfolders checked in FVS.

This script will create a folder thumbnails of the following types:

1) Zoom-to-Fill view using a single image - see PIC 1
Pre-select an image in current folder
Random image in current folder
Random image in current and sub folders
2) Montage of 4 random images Image Magick - see PIC 2
Zoom-to-Fill view in current folder
Polaroid view in current folder
Zoom-to-Fill view current folder and subs
3) Zoom-to-Fill Montage of 4 images using IrfanView - see PIC 3
Random images in current folder
Random images in current folder and subs
Pre-select 4 image in current folder
Folder Thumbnails.jpg
Folder Thumbnails.jpg (118.35 KiB) Viewed 1913 times
PIC 1 Single pic folder thumb.png
PIC 1 Single pic folder thumb.png (581.48 KiB) Viewed 1913 times
PIC 2 Polaroid montage 4 pics.jpg
PIC 2 Polaroid montage 4 pics.jpg (223.61 KiB) Viewed 1913 times
PIC 3 Montage folder thumbnail 4 pis.png
PIC 3 Montage folder thumbnail 4 pis.png (591.31 KiB) Viewed 1913 times
Montage & Zoom-to-Fill folder thumbnails.xys
(12.92 KiB) Downloaded 99 times
If you try it and have any issues, please let me know so I can correct them. Thanks.

*****************************************************************************************
*** Old version ***
Here's another script for creating a folder montage. I've called it FolderMontage. Jdev21 created a nice version here http://www.xyplorer.com/xyfc/viewtopic. ... 62#p114057 and totmad1 also created one here http://www.xyplorer.com/xyfc/viewtopic. ... 36#p114036 At least 5 years ago serendipity created the "original" one here using Irfanview here http://www.xyplorer.com/xyfc/viewtopic. ... thumbnails. Thank you to all three of you and I hope you don't mind me posting this version. I was going to post in on serendipity's old script thread but since the tread was so old and the scripts quite a bit different, I decided to start a new thread.
The script uses ImageMagick to create the montage. So to use it you will need IM installed (there is a portable version) see comment in script. This script will develop the montage (see pics) as follows:
1) It use IM's montage.exe polariod affect for the montage...obviously with little work you can change this.
2) The number of pics in the montage will be based on the number of pics in the folder. If >= 16, it will create a montage of 16 pictures, if between 9 and 15 it will have 9 pics in the montage and with < 9 it will use 4 pictures.
3) The pictures will be randomized
4) The folder name is obtained and will be included in the title of the FolderMontage.
5) As with some of the other versions it will hide the folder.jpg file. There's a menu option to unhide it.
6) It does not create a bat file to run montage.exe, but it does create a filelist.txt to feed to montage.exe. I found that using the text file as jdev21 did, avoids some issues with spaces in file names among other issues.
7) It uses a non-modal timed message to tell you what happening and flashes the reduced size verison of the montage when complete - for each folder. It's fluff but the status message wouldn't stay on the screen long enough to be of value and I didn't want the user to have to hit enter to acknowledge the message. It usesPowerShell. If you experience any issues with this, you can simply comment out the code lines, Sub "_TIMED_MESSAGE";
#8) I used a 4x4 tile only because I'm using SQUARE 240x240 thumbnails thumbs to display in a large square-full extent/aspect ratio of the thumb. If using a "240x180" thumb size, for $tile I'd use for a "5x4"/"4x3"/"3x2" and adjust $count to 20/12/6.
Folder_Montage1.PNG
Folder_Montage1.PNG (319.87 KiB) Viewed 3749 times
Folder_montage2.PNG
Folder_montage2.PNG (1.03 MiB) Viewed 3749 times
Thanks to TheQwerty for the randomize method I used on the image pictures and to highend for the regexreplace code I used in lieu of using a foreach loop.

Code: Select all

"_Initialize";
      global $parentDir, $montage_exe;
	  $montage_exe = "D:\Graphics\ImageMagick\montage.exe";    // montage.exe is part of the ImageMagick package (free) which can be obtained at http://www.imagemagick.org/script/binary-releases.php#windows
	  $parentDir = "<curpath>";                                // Look for Windows binary packages on left side. You can download the no install package where no registry entries are made 
      if(substr("$parentDir", -1) == ":") {$parentDir = "$parentDir" . "\";}

"  Generate Folder Montage (Current Folder)  |:viewthumbs";
      global $parentDir, $montage_exe;
	 if(exists("$parentDir\folder.jpg")) {
	   attrstamp("h", 4, "$parentDir\folder.jpg");
	   delete 0, 0, "$parentDir\folder.jpg";}
	     $image_list = formatlist(folderreport("files", "r", "<curpath>", , , "<crlf>"), "f", "<crlf>", "*.jpeg<crlf>*.jpg<crlf>*.bmp<crlf>*.png");  
         $image_list = regexreplace($image_list, "^(.*\\)(.*?$)", "'$2'");   // Thanks highend
	     $i = gettoken("$image_list", "count", "<crlf>");
	       if ($i >= "16") {
	         $count = 16; $geometry = 450x450; $tile = "4X4"}    // I used a 4x4 tile only because I'm using a SQUARE 240x240 thumbnails thumbs to display in a lg square-full extent/aspect ratio of the thumb 
	       elseif (($i >= "9") AND ($i < "16")) {                // If using a "240x180" thumb size, for $tile I'd use for a "5x4"/"4x3"/"3x2" and adjust $count to 20/12/6..  
	         $count = 9; $geometry = 550x550; $tile = "3X3"}
		   elseif (($i >= "4") AND ($i < "9")) {
	         $count = 4; $geometry = 720x720; $tile = "2x2"}
	       elseif ($i < "9") {end 1, "This Folder [$parentDir] does not contain enough image files to make a proper folder montage.";}
	  
      $random_images = GetToken(formatlist($image_list, 'x', "<crlf>"), $count, "<crlf>",, 1);     //randomize the no of images "$count" in $image_list Thanks TheQwerty
	  writefile("filelist.txt", $random_images);
      $folder_name = quote(getpathcomponent($parentDir, "component", -1));
	   Sub "_TIMED_MESSAGE";          // if you have an issue or do not want the message comment out this line. The non-modal timed message does not delay the script execution.  
      run "cmd /c $montage_exe @filelist.txt -geometry $geometry-1-1 -auto-orient +polaroid -background grey70 -tile $tile -font Tahoma -pointsize 26 -title $folder_name folder.jpg", , 2,0;
	    delete 0, 0, "$parentDir\filelist.txt";
       sub "_ViewPic";
       attrstamp("h", 1, "$parentDir\folder.jpg");   //if you'd rather not hide the folder montage comment out this line
	 
"-"
"  Generate Folder Montage (Current Folder and ALL Subs)  |:refresh";
      global $parentDir, $montage_exe, $ea_path;
    if(strlen($parentDir) < 4) {$root_warning = 1;}
       if($root_warning == "1") {end confirm("You are in the root directory.  Are you sure you want to create folder thumbnails for the entire drive?") == 0, "Good choice, bye!";}
     $paths = "$parentDir" . "<crlf>" . (folderreport("dirs", "r", $parentDir, "r", , "<crlf>"));
     foreach ($ea_path, $paths, "<crlf>") {
	    if($ea_path == "") {continue;}
		goto "$ea_path";   // experienced issues using a path with filelist.txt within the montage cmd line, so moving into each folder
	    if(exists("$ea_path\folder.jpg")) {
	      attrstamp("h", 4, "$ea_path\folder.jpg");
	      delete 0, 0, "$ea_path\folder.jpg"; }
		$image_list = formatlist(folderreport("files", "r", "$ea_path", , , "<crlf>"), "f", "<crlf>", "*.jpeg<crlf>*.jpg<crlf>*.bmp<crlf>*.png");  
        $image_list = regexreplace($image_list, "^(.*\\)(.*?$)", "'$2'");   // Thanks highend
	    $i = gettoken("$image_list", "count", "<crlf>");
	       if ($i >= "16") {
	         $count = 16; $geometry = 450x450; $tile = "4X4"}
	       elseif (($i >= "9") AND ($i < "16")) {
	         $count = 9; $geometry = 550x550; $tile = "3X3"}
		   elseif (($i >= "4") AND ($i < "9")) {
	         $count = 4; $geometry = 750x750; $tile = "2x2"}
	       elseif ($i < "9") {end true, "This Folder [$ea_path] does not contain enough image files to make a proper folder montage.";}
		
	    $random_images = GetToken(formatlist($image_list, 'x', "<crlf>"), $count, "<crlf>",, 1);
		writefile("$ea_path\filelist.txt", $random_images);
       $folder_name = quote(getpathcomponent($parentDir, "component", -1));
	    Sub "_TIMED_MESSAGE";      // if you have an issue or do not want the message comment out this line.  The non-modal timed message does not delay the script execution.      run "cmd /c $montage_exe @filelist.txt -geometry $geometry+1+1 -auto-orient +polaroid -background grey80 -tile $tile -font Tahoma -pointsize 26 -title $folder_name folder.jpg", , 2,0;
	      delete 0, 0, "$ea_path\filelist.txt";
         sub "_ViewPic";
         attrstamp("h", 1, "$ea_path\folder.jpg");      //if you'd rather not hide the folder montage comment out this line
     }
	goto $parentDir;
"-"
"  Remove Hidden Attribute from folder.jpg (Current Folder)  |:nuke";
	  attrstamp("h", 4, "<curpath>\folder.jpg");

"_TIMED_MESSAGE";
    global $parentDir, $ea_path;
	if (substr(gettoken(caller("caption"), 1, ")", "t"), -4) == "Subs") {$montage_folder = $ea_path; }
	else {$montage_folder = $parentDir; } 
  
  $t_msg = "Creating folder montage for [$montage_folder]...Please be patient...it could take a minute or three literally and substantial CPU power. The montage will flash on the screen when complete (for each folder).";
  $waitSec = 10;
  $PS = <<<HEREDOC
$WshShell = New-Object -Com Wscript.Shell
$WshShell.Popup("$t_msg", $waitSec, "Folder Montage", 4096)
HEREDOC;
  writefile("<xyscripts>\tempPS1.ps1", $PS);
  run ("%winsysdir%\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -File ""<xyscripts>\tempPS1.ps1"""), ,0,0;

"_ViewPic";
    global $parentDir, $ea_path;
	if (gettokenindex("Subs)", caller("caption"), " ", "c") == "1") {$montage_folder = $ea_path; }
	else {$montage_folder = $parentDir; } 
  makecoffee "$montage_folder\folder.jpg",1,1, 600, 600;
  wait 2000; makecoffee "";

"_Terminate";
   delete 0, 0, "<xyscripts>\tempPS1.ps1";

If you try it please let me know if you have any issues. Thanks again to jdev21, totmad1, serendipity, highend, and TheQwerty.
Ken
Last edited by klownboy on 27 Jan 2022 17:41, edited 5 times in total.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

jdev21
Posts: 45
Joined: 08 Oct 2014 22:13

Re: FolderMontage

Post by jdev21 »

Nice work! This is much better than the script I created.

I hope you don't mind - I'm in the process of using your script in conjunction with MovieThumbnailer (http://moviethumbnail.sourceforge.net/) to create index sheets for video files as well. Right now I have it working to create a 2x2 sheet per video and then use those picture-sheets with your script to create a video contact sheet for the folder of videos (hopefully thats not too confusing).

If anyone is interested, I will post the final result when it is finished.

BTW, you probably don't need to define the path for montage as the installer should automatically include it in the system path for Windows users. I'm able to simply use the command montage rather than the full path from any folder.

What is the reason for this line to replace spaces?

Code: Select all

 $folder_name = getpathcomponent($parentDir, "component", -1); $folder_name = replace($folder_name, " " , " ");  //Replacing a normal space " " with hard space " " alt 255 on Numpad

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: FolderMontage

Post by klownboy »

Thanks jdev21. I'm definitely interested in any new add-ons or developments.

As far as the need to replaces normal spaces with what I called a hard space, was I was having much difficulty getting any name to appear properly if it had spaces in the name (i.e., only the first part before the space appeared). So, I figured I'd give that a try and it ended up working. There probably is a more efficient way or elegant to do it, but no matter what I tried for quoting, I'd never get the full folder name when it had spaces. If you figure a better way please let me know. ImageMagick is a great program but can be finicky getting it to work properly with XYplorer.

You are right about the path also but I was worried that if someone like me didn't have the path added (it is an option during installation) it might not work for them.

Thanks again,
Ken
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

jdev21
Posts: 45
Joined: 08 Oct 2014 22:13

Re: FolderMontage

Post by jdev21 »

That makes sense. I haven't run into that problem with filenames yet but will take note in case I do.
Does that same spacing problem still occur even when the file is wrapped in quotes?

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: FolderMontage

Post by klownboy »

I'm quite sure I had tried wrapping the folder name in single and double quotes and even triple quoted """$folder_name""" with no success, but who knows, maybe there was some other issue going on. I had issues with the image filenames as well. That's when I decided to generate the filelist.txt in XY scripting as you had using the command line. I was initially hoping to avoid using filelist.txt.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

PeterH
Posts: 2776
Joined: 21 Nov 2005 20:39
Location: Germany

Re: FolderMontage

Post by PeterH »

OK: if I see it right, in the construct:
run "cmd /c $montage_exe @filelist.txt -geometry $geometry+1+1 -auto-orient +polaroid -background grey80 -tile $tile -font Tahoma -pointsize 26 -title $folder_name folder.jpg", , 2,0;
$folder_name really should be quoted. So either:
run "cmd /c $montage_exe @filelist.txt -geometry $geometry+1+1 -auto-orient +polaroid -background grey80 -tile $tile -font Tahoma -pointsize 26 -title ""$folder_name"" folder.jpg", , 2,0;
(must double quotes inside quotes, but never tripple :-) ), or:
$folder_name = quote(getpathcomponent($ea_path, "component", -1));
to contain the quotes inside the variable string.

If this doesn't work it should be a problem of the program interpreting it's operands...


Edit: for tripple: this appears only if the inner quotes are directly connected to the outer quotes, as:
$a = "Value ""$b""";
W7(x64) SP1 German
( +WXP SP3 )

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: FolderMontage

Post by klownboy »

Thanks PeterH, I tested both of your examples, using "quote" and using the ""double quotes"" and both worked. I know I had tried single and double quoting, but there must have been some other problem in why it didn't work since it does now. I'll have to start remembering to take advantage of using SC quote to contain the quotes inside the variable string.

I'll update the script above. I may also do some additional experimenting using quote or double quotes on the actual image filelist. I resorted to using creating a filelist.txt of the images only because I was having difficulty running "montage.exe" on a list of images. The filelist.txt works fine provided each image is single quoted with a return after each file. Thanks again.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Montage & Zoom-to-Fill folder thumbnails

Post by klownboy »

Based on updates made more recently here in this thread viewtopic.php?f=5&t=23829, I made an update to this old script. Please refer to the first post.

Edit: Oops, I posted pictures and forgot to post the script itself. It's there now.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Post Reply