FolderMontage

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

FolderMontage

Post by klownboy » 26 Nov 2014 18:59

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 1068 times
Folder_montage2.PNG
Folder_montage2.PNG (1.03 MiB) Viewed 1068 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 02 Dec 2014 14:50, edited 1 time in total.

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

Re: FolderMontage

Post by jdev21 » 01 Dec 2014 20:14

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: 2741
Joined: 28 Feb 2012 19:27

Re: FolderMontage

Post by klownboy » 01 Dec 2014 21:08

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

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

Re: FolderMontage

Post by jdev21 » 01 Dec 2014 22:34

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: 2741
Joined: 28 Feb 2012 19:27

Re: FolderMontage

Post by klownboy » 02 Dec 2014 01:23

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.

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

Re: FolderMontage

Post by PeterH » 02 Dec 2014 10:33

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: 2741
Joined: 28 Feb 2012 19:27

Re: FolderMontage

Post by klownboy » 02 Dec 2014 14:30

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.

Post Reply