ImageMagick & XYplorer

Discuss and share scripts and script files...
highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: ImageMagick & XYplorer

Post by highend »

%winsysdir% used as follows works fine...
Yeah, because on a 64 bit OS the redirection system will be used (because XY is only 32 bit).
On script execution problems, are you talking about the situation where a user is not running with elevated rights?
No.

Open a powershell:
get-executionpolicy

If the output is "Unrestricted" everything's fine. If not ... policies are ... not really complicated but can cause issues.
Are scripts signed; if not are they local, do they need to be unblocked because they were downloaded (the security zone is stored inside the Alternate Data Stream of a file if it wasn't disabled via a registry entry / group policy), etc.

E.g. on a fresh x64 Win 7 VM:
get-executionpolicy
Restricted

In such environments you can't execute the powershell script without lifting the policy. Even accounts with administrator privileges are affected.
One of my scripts helped you out? Please donate via Paypal

Filehero
Posts: 2645
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: ImageMagick & XYplorer

Post by Filehero »

highend wrote: E.g. on a fresh x64 Win 7 VM:
get-executionpolicy
Restricted
AFAIK, that's the default policy on a fresh windows 7 upwards or a "virgin" powershell.

I always set it to RemoteSigned once

Code: Select all

Set-ExecutionPolicy RemoteSigned
which seems to provide sufficient protection for scripts-from-the-outer-space.

Btw, powershell is cool and mighty - it pipes real objects by default!


Cheers,
Filehero

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

Re: ImageMagick & XYplorer

Post by klownboy »

Thanks Filehero, I found that my laptop policy was set as "restricted" whereas my desktop was set as "unrestricted", both Windows 7 X64. Probably because I built my desktop and purchased the laptop. I was using

Code: Select all

set-executionpolicy unrestricted -scope process -force
and it works fine from within Powershell, but I'm having issues getting it to work on my laptop from my XY script. I know the script itself works fine since it worked on the desktop. I'll have to wait 'til I get back home. I'm currently babysitting. :D ...just got back from "Munchkin Park".
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: ImageMagick & XYplorer

Post by highend »

The problem isn't your pc but if you want to execute a policy lifting command on a different one (and if the user of it wants that, too) :)

So you should at least check if get-executionpolicy returns something that is undesired (runret works) and then ask the user if he wants to change the policy (don't forget, you need an elevated powershell to be able to do that)...
One of my scripts helped you out? Please donate via Paypal

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

Re: ImageMagick & XYplorer

Post by klownboy »

highend wrote:The problem isn't your pc but if you want to execute a policy lifting command on a different one (and if the user of it wants that, too
Thanks highend. Well you're right, but I first have to be able to get it working properly on my 3 computers before I attempt to do it in a script which affects others.

Yes, runret does works great for checking the policy.

Code: Select all

text runret("%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe get-executionpolicy"), 320, 400, "PS Execution Policy",,;
I finally realized I was changing the policy only for the local session and had to use "-scope CurrentUser" (in PS run as administrator) to change it such that it would work outside that particular session via an XY script.

I certainly don't want to have to prompt users every time they want to change their wallpaper...kind of lame when there are a many other way to change wallpaper including the right click context menu. So if it comes to that I'm not going to bother.

In any case, I did get it working on my laptop though it's centered not stretched proportionally like it is on the desktop with the same parameters.

Thanks Filehero for the "remotesigned" tip.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47

Re: ImageMagick & XYplorer

Post by nerdweed »

klownboy wrote: It doesn't need a conversion to BMP either.
Are you on Windows 8. I think only Windows 8 and later are able to display jpg wallpapers. BTW, can you please post the heredoc you use for creating the PS script. I couldn't find an example of any PS script to use jpg as wallpapers.

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: ImageMagick & XYplorer

Post by highend »

Win 7 supports .jpg for wallpapers as well.

Just put the contents of the ps script from (http://stackoverflow.com/questions/1972 ... ows-7?rq=1) into a heredoc but ofc you have to change the line

Code: Select all

[Wallpaper.Setter]::SetWallpaper('D:\wp1.bmp')
to the variable name of the picture and yes, .jpg works...
One of my scripts helped you out? Please donate via Paypal

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

Re: ImageMagick & XYplorer

Post by klownboy »

Hi nerdweed, you can also substitute <curitem> for the wallpaper name or variable such it changes the wallpaper to the currently selected image file like this.

Code: Select all

[Wallpaper.Setter]::SetWallpaper('<curitem>')
The only issue I'm still having is why on one Windows 7 machine I get the wallpaper proportionally stretched/sized down to fit the screen and on my laptop(also Win 7 x64) it's just centered and blown up in original size. Changing the Wallpaper style doesn't seem to do anything at least on the laptop. What's weird is the WallpaperStyle is "0" in the Registry on both computers

Code: Select all

HKEY_CURRENT_USER\Control Panel\Desktop
If you still need the XY script let me know.

Edit: My laptop is now displaying wallpapers proportionally stretched (for those huge mega-pixel camera photos). Changing the WallpaperStyle to "2" in the Registry fixed it. The desktop was on "0" but it displayed wallpaper correctly (stretched proportionally). Maybe when set by graphics programs like Irfanview or ImageEye that setting is bypassed and the system uses what it was set at previously by the program.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

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

Re: ImageMagick & XYplorer

Post by klownboy »

Highend, nerdweed and anyone else interested in PowerShell script to change wallpaper. I may have found a better compromise as far as running PowerShell in a script where the user has the execution policy set as undefined or restricted. There's a parameter which allows for temporary bypass of the setting just to run the single script file but does not change the machine or user policy. Actually changing the user's execution policy can be a pain in the *ss since you need admin rights to do that. See the last line. It seems to be working fine on machines that I've set to "Restricted".

Code: Select all

 $PS = <<<HEREDOC
Add-Type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Wallpaper
{
   public class Setter {
      public const int SetDesktopWallpaper = 20;
      public const int UpdateIniFile = 0x01;
      public const int SendWinIniChange = 0x02;
      [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
      private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
      public static void SetWallpaper ( string path) {
         SystemParametersInfo( SetDesktopWallpaper, 2, path, UpdateIniFile | SendWinIniChange );
         RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
         key.Close();
      }
   }
}
"@

[Wallpaper.Setter]::SetWallpaper('<curitem>')
HEREDOC;
  writefile("<xyscripts>\tempPS.ps1", $PS);
  run ("%winsysdir%\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -File ""<xyscripts>\tempPS.ps1"""), ,2,0;
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13327
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: ImageMagick & XYplorer

Post by highend »

Great to hear that you don't need to change the policy permanently :)
One of my scripts helped you out? Please donate via Paypal

Filehero
Posts: 2645
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: ImageMagick & XYplorer

Post by Filehero »

Holy moses Ken,

PS with C# - cool solution. :appl:


Cheers,
Filehero

stanmarsh
Posts: 85
Joined: 10 Mar 2009 07:43

Re: ImageMagick & XYplorer

Post by stanmarsh »

totmad1 thank you for the very useful ImageMagick script! :biggrin: im using the portable binary and its working perfectly!

totmad1
Posts: 131
Joined: 24 Jun 2013 12:37

Re: ImageMagick & XYplorer

Post by totmad1 »

@ stanmarsh sorry for late reply haven't been well and missed your post. So a belated thanks for comments.

Opened a book I had scanned a few years ago and thought i'd tidy it up.
Produced this script to trim from either side of image by percentage.

Code: Select all

"trim Left or Right w input|%Porta%\ImageMagick-6_8_9-0\images\wand.ico : _ imm B2";
             $SelectedItems = get("SelectedItemsPathNames", "|");
            $num = input("Enter in %", "i.e. 23 (=23%trim right)  ( -23 =23%trim left)", "23");
               $num =($num /100);
   foreach($Item, $SelectedItems, "|") { 
                $base = getpathcomponent($Item, "base",);
		$w1 = property("ImageX", $Item);
		$w12 = $w1 * $num;
	if ($num <= 0) {
	$cut = "West";
	$w12 =abs($w12);
	}
	else {
            $cut = "East";
             }
            $wh = $w12 . "x0"; 
         $cmdline = <<<CMD_LINE
cmd /c $p_convert $Item -gravity $cut -chop $wh  ""$base""_%d.jpg

CMD_LINE;
         $cmdline = Replace($cmdline, "<crlf>", ' ');
         Run($cmdline, , 0, 0);
            }  msg "All Done";

you will also have to replace this next line

Code: Select all

"ImageMagick   >>--->|%Porta%\ImageMagick-6_8_9-0\images\wand.ico :  imm ME"  Load("*","_ imm MD;-;_ imm A;_ imm B;_ imm B2;_ imm C;_ imm C1;_ imm D;_ imm E;_ imm F;_ imm G;_ imm H;_ imm I;_ imm J;_ imm K;_ imm L;_ imm M;_ imm N;_ imm O;_ imm O1;_ imm P;_ imm P1;_ imm P2;_ imm Q;_ imm Q1;_ imm R;_ imm S;_ imm S1;_ imm S2;_ imm S3;_ imm T;_ imm U;_ imm V;_ imm W;_ imm X;_ imm Y;_ imm Z;") ;
p.s. the "23" was the percent I required.
totmad1 (totally mad one)

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

Re: ImageMagick & XYplorer

Post by klownboy »

Hi totmad1, I must say, you've got a darn good handle on the myriad of touchy IM parameters. :) :appl: IM's a powerful program though.

I did have problems though running your recently added change for percentage trim - left and right. Stepping through it didn't tell me much other than the fact that there was no output (i.e., new image created). I can't remember now if it was solely due to filenames with spaces. I changed the variable, $base such that it included the whole name (calling it $name), instead of just the $base and adding the extension in the command line. Of course the "_%trim.jpg" part can be changed to anything you want. I also added quotes for $Item and $name and it seems to work fine - one pair of quotes worked since you used Heredoc.
$name = getpathcomponent($Item, "base",) . "_%trim.jpg";
$cmdline = cmd /c $p_convert "$Item" -gravity $cut -chop $wh "$name"
Thanks,
Ken
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

totmad1
Posts: 131
Joined: 24 Jun 2013 12:37

Re: ImageMagick & XYplorer

Post by totmad1 »

@ klownboy(Ken) Thanks for comments. What came to mind was the saying "More than one way to skin a cat".
I used _%d to add a numeral while I was testing. I wanted to show how easy to construct straight from documentation
into a script in XY.

Here's my latest. The first two scriptlets are results of coloring icons. The third was suggested recently.
You need to add montage.exe to the "_Initialize" at the beginning. I used a temp PaperFolder to select images.
The scriptlet gets the path to create a folder.jpg from the first selected pic.

Code: Select all

//submenu
"ImageMagic submenu 2 _»---|<xydata>\icons\xy-menu.ico :  imm2 ME"  Load("*","_ imm2 MD;-;_ imm2 A;_ imm2 B;_ imm2 C;_ imm2 D;_ imm2 E;_ imm2 F;_ imm2 G;_ imm2 H;_ imm2 I;_ imm2 J;_ imm2 K;_ imm2 L;_ imm2 M;_ imm2 N;_ imm2 O;_ imm2 P;_ imm2 Q;_ imm2 R;_ imm2 S;_ imm2 T;_ imm2 U;_ imm2 V;_ imm2 W;_ imm2 X;_ imm2 Y;_ imm2 Z;") ;
"<- BACK |: imm2 |1 : _ imm2 MD"   Load("*");
"ColoR gamma 0.1-16 |<xydata>\icons\xy-script.ico : _ imm2 A";
                    $Clor = input("Enter the gamma 0.1-16" ,"(0.1,0.5,0)" ,"(0.1,0.5,0)");
                    run ("cmd /c $p_convert <curitem>  -gamma $Clor gma_$Clor.ico");

"Color Name or HEX input |<xydata>\icons\xy-script.ico : _ imm2 B";
              $Clor = input("Enter the Color Name" , ,"LightPink1");
                    run ("cmd /c $p_convert <curitem>  +level-colors ,$Clor Fldr_$Clor.ico");
"montage|%Porta%\ImageMagick-6_8_9-0\images\wand.ico : _ imm2 C";
              $SelectedItems = get("SelectedItemsPathNames", "<crlf>");
              $path =  getpathcomponent(gettoken($SelectedItems, 1, "<crlf>"), "path"); 
         $cmdline = <<<CMD_LINE
cmd /c $p_montage  -define jpeg:size=200x200 '*.jpg[32x32]' -strip
 -geometry 32x32+5+5 -frame 4 $SelectedItems folder.gif
 $p_convert folder.gif  $path\folder.jpg

CMD_LINE;
         $cmdline = Replace($cmdline, "<crlf>", ' ');
         Run($cmdline, , 0, 0);
            }  msg "All Done";
       //  attrstamp("h",,"$path\folder.jpg") ;
"  Generate Image Index Sheet  (Current Folder)  |:refresh : _ imm2 D";  
 if( exists("<curpath>\folder.jpg")==1){delete 0, 0, "<curpath>\folder.jpg";}
              set $list;
             $SelectedItems = get("SelectedItemsPathNames", "<crlf>"); 
             foreach($item, $SelectedItems, <crlf>){
             $list = $list"$item"<crlf>;}
         $cmdline = <<<CMD_LINE
cmd /c $montage $list -geometry "250x180+1+1" -tile 5x "<curpath>\folder.jpg"

CMD_LINE;
         $cmdline = Replace($cmdline, "<crlf>", ' ');
         Run($cmdline, , 0, 0);
            }  msg "All Done";
"  Generate Image Index Sheet  (Current Folder and ALL Subs)  |:refresh : _ imm2 E";  
         $parentDir=<curpath>;  $images="";
       $subDirs=folderreport("dirs", r, $parentDir, r);
       $subDirs= $parentDir<crlf>$subDirs;
       foreach($sub, $subDirs, <crlf>){
               $i="";
             if($sub==""){break 1;}
             if( exists("$sub\folder.jpg")==1){delete 0, 0, "$sub\folder.jpg";}
         $allFiles = folderreport("files", "r", $sub, , , "<crlf>");
            foreach($item, $allFiles, <crlf>){
            $a= getpathcomponent($item, "ext");
           if($a == "bmp" OR $a=="jpg" OR $a=="jpeg" OR $a=="png"){
                   $i++;
                   $images=$images "$item"<crlf>;
                   $b= gettoken($allFiles, "count", "<crlf>", , );
                } 
                if($i==15 OR $i==$b)  { break 1;}
                   }
        $cmdline = <<<CMD_LINE
cmd /c $montage $images -geometry "400x300+1+1" -background gray -tile 5x3 "$sub\folder.jpg"

CMD_LINE;
         $cmdline = Replace($cmdline, "<crlf>", ' ');
         Run($cmdline, , 0, 0);
               $images="";
               }
              msg "All Done";
"hide image  |<xyicons>\showhide.ico : _ imm2 F";
          $a= popupmenu("Current Folder;c|-|Current Folder and ALL Subs;s");
          if( $a=="s"){#311;}
          selfilter "folder.jpg";
          $SelectedItems = get("SelectedItemsPathNames", "|");
   foreach($Item, $SelectedItems, "|") {
      attrstamp("h", , "$Item");
      }
/*
"07imm2  |<xydata>\icons\xy-script.ico : _ imm2 G";   open notepad ;
"08imm2  |<xydata>\icons\xy-script.ico : _ imm2 H";   open notepad ;
"09imm2  |<xydata>\icons\xy-script.ico : _ imm2 I";   open notepad ;
"10imm2  |<xydata>\icons\xy-script.ico : _ imm2 J";   open notepad ;
"11imm2  |<xydata>\icons\xy-script.ico : _ imm2 K";   open notepad ;
"12imm2  |<xydata>\icons\xy-script.ico : _ imm2 L";   open notepad ;
"13imm2  |<xydata>\icons\xy-script.ico : _ imm2 M";   open notepad ;
"14imm2  |<xydata>\icons\xy-script.ico : _ imm2 N";   open notepad ;
"15imm2  |<xydata>\icons\xy-script.ico : _ imm2 O";   open notepad ;
"16imm2  |<xydata>\icons\xy-script.ico : _ imm2 P";   open notepad ;
"17imm2  |<xydata>\icons\xy-script.ico : _ imm2 Q";   open notepad ;
"18imm2  |<xydata>\icons\xy-script.ico : _ imm2 R";   open notepad ;
"19imm2  |<xydata>\icons\xy-script.ico : _ imm2 S";   open notepad ;
"20imm2  |<xydata>\icons\xy-script.ico : _ imm2 T";   open notepad ;
"21imm2  |<xydata>\icons\xy-script.ico : _ imm2 U";   open notepad ;
"22imm2  |<xydata>\icons\xy-script.ico : _ imm2 V";   open notepad ;
"23imm2  |<xydata>\icons\xy-script.ico : _ imm2 W";   open notepad ;
"24imm2  |<xydata>\icons\xy-script.ico : _ imm2 X";   open notepad ;
"25imm2  |<xydata>\icons\xy-script.ico : _ imm2 Y";   open notepad ;
"26imm2  |<xydata>\icons\xy-script.ico : _ imm2 Z";   open notepad ;
//submenu
*/

I was impressed by the param in montage -tile .
Edited 22/11/2014
added last 3 scriptlets Note:msg All Done does not relate to end of production you should hear a sound when fully complete.
hide images can then be run to hide folder.jpg
totmad1 (totally mad one)

Post Reply