Get one layer from Imagemagick
Get one layer from Imagemagick
Hi!
Quite new to Switch but have created a Switch/imagemagick flow that works fine, but with photoshop files i would like to add a couple of characters in my imagemagick command but i can't figure out how.
My IM command looks like this:
"%1" -resize [Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"]x[Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"] -sharpen 3 "%2"
In imagemagick there is a option to extract one layer only from photoshop images, like this "convert <filename>.psd[0]" ...
But how do i add the brackets and number to my IM command in Switch?
"%1[0]" -resize [Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"]x[Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"] -sharpen 3 "%2"
gives me an error "unknown variable"
Any help would be much appreciated!
Quite new to Switch but have created a Switch/imagemagick flow that works fine, but with photoshop files i would like to add a couple of characters in my imagemagick command but i can't figure out how.
My IM command looks like this:
"%1" -resize [Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"]x[Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"] -sharpen 3 "%2"
In imagemagick there is a option to extract one layer only from photoshop images, like this "convert <filename>.psd[0]" ...
But how do i add the brackets and number to my IM command in Switch?
"%1[0]" -resize [Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"]x[Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"] -sharpen 3 "%2"
gives me an error "unknown variable"
Any help would be much appreciated!
- JimmyHartington
- Advanced member
- Posts: 320
- Joined: Tue Mar 22, 2011 7:38 am
Re: Get one layer from Imagemagick
I have not tried, but may you need to escape the brackets with \.
Try with this:
"%1\[0\]" -resize [Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"]x[Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"] -sharpen 3 "%2"
Try with this:
"%1\[0\]" -resize [Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"]x[Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"] -sharpen 3 "%2"
Re: Get one layer from Imagemagick
Thanks for the suggestion "%1\[0\]" didn't work, neither did "%1\[0]\" or "\%1[0]\"
- JimmyHartington
- Advanced member
- Posts: 320
- Joined: Tue Mar 22, 2011 7:38 am
Re: Get one layer from Imagemagick
That is because anything between [] is considered to be a variable in a single-line text with variables and [0] is not a valid Switch variable.
My advice when working with more complex commands in the context of "Execute command" is to put everything in a batch file/shell script. In "Command or path" you select the bat/sh file and in "Arguments" you specify a list of, well, arguments for the bat/sh:
"%1" "%2" [SomeSwitchVariable1] [SomeSwitchVariable2] etc.
In a Windows batch file you use %1, %2, %3, ... following the order of the arguments as you specified them in "Arguments" and place them in the right place in the command, e.g.
"C:\Program Files\ImageMagick-6.9.2-Q16\convert.exe" %1[0] --resize %3X%4 %2 (do not use double quotes)
In a Mac shell script it would look like:
#!/bin/bash
/usr/local/bin/convert "$1" -resize $3X$4 "$2" (note that here double quotes are required for paths to avoid problems with spaces and that the arguments are prefixed with a $ sign and not a % sign)
You must also not forget to make the .sh file executable: chmod +x pathToShellScript
My advice when working with more complex commands in the context of "Execute command" is to put everything in a batch file/shell script. In "Command or path" you select the bat/sh file and in "Arguments" you specify a list of, well, arguments for the bat/sh:
"%1" "%2" [SomeSwitchVariable1] [SomeSwitchVariable2] etc.
In a Windows batch file you use %1, %2, %3, ... following the order of the arguments as you specified them in "Arguments" and place them in the right place in the command, e.g.
"C:\Program Files\ImageMagick-6.9.2-Q16\convert.exe" %1[0] --resize %3X%4 %2 (do not use double quotes)
In a Mac shell script it would look like:
#!/bin/bash
/usr/local/bin/convert "$1" -resize $3X$4 "$2" (note that here double quotes are required for paths to avoid problems with spaces and that the arguments are prefixed with a $ sign and not a % sign)
You must also not forget to make the .sh file executable: chmod +x pathToShellScript
Re: Get one layer from Imagemagick
And there is an app for that It let you create the shell script or bat file with Switch variables.freddyp wrote: ↑Wed May 17, 2023 10:05 am That is because anything between [] is considered to be a variable in a single-line text with variables and [0] is not a valid Switch variable.
My advice when working with more complex commands in the context of "Execute command" is to put everything in a batch file/shell script. In "Command or path" you select the bat/sh file and in "Arguments" you specify a list of, well, arguments for the bat/sh:
"%1" "%2" [SomeSwitchVariable1] [SomeSwitchVariable2] etc.
In a Windows batch file you use %1, %2, %3, ... following the order of the arguments as you specified them in "Arguments" and place them in the right place in the command, e.g.
"C:\Program Files\ImageMagick-6.9.2-Q16\convert.exe" %1[0] --resize %3X%4 %2 (do not use double quotes)
In a Mac shell script it would look like:
#!/bin/bash
/usr/local/bin/convert "$1" -resize $3X$4 "$2" (note that here double quotes are required for paths to avoid problems with spaces and that the arguments are prefixed with a $ sign and not a % sign)
You must also not forget to make the .sh file executable: chmod +x pathToShellScript
https://www.enfocus.com/en/appstore/pro ... and-friend
- magnussandstrom
- Advanced member
- Posts: 381
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Get one layer from Imagemagick
But will it really work with that app, Jan? You still need to insert [1] into the command some how.jan_suhr wrote: ↑Tue May 23, 2023 5:20 pm
And there is an app for that It let you create the shell script or bat file with Switch variables.
https://www.enfocus.com/en/appstore/pro ... and-friend
Re: Get one layer from Imagemagick
Thank's for your input. I have created a .bat file containing this code, named Resize_psd.batfreddyp wrote: ↑Wed May 17, 2023 10:05 am That is because anything between [] is considered to be a variable in a single-line text with variables and [0] is not a valid Switch variable.
My advice when working with more complex commands in the context of "Execute command" is to put everything in a batch file/shell script. In "Command or path" you select the bat/sh file and in "Arguments" you specify a list of, well, arguments for the bat/sh:
"%1" "%2" [SomeSwitchVariable1] [SomeSwitchVariable2] etc.
In a Windows batch file you use %1, %2, %3, ... following the order of the arguments as you specified them in "Arguments" and place them in the right place in the command, e.g.
"C:\Program Files\ImageMagick-6.9.2-Q16\convert.exe" %1[0] --resize %3X%4 %2 (do not use double quotes)
In a Mac shell script it would look like:
#!/bin/bash
/usr/local/bin/convert "$1" -resize $3X$4 "$2" (note that here double quotes are required for paths to avoid problems with spaces and that the arguments are prefixed with a $ sign and not a % sign)
You must also not forget to make the .sh file executable: chmod +x pathToShellScript
C:/Program Files/ImageMagick-7.1.1-Q16-HDRI/magick.exe %1[0] -resize %2x%3 -sharpen 3 %4.tif
In my Execute Command i have entered the following
Command: C:/Program Files/ImageMagick-7.1.1-Q16-HDRI/MGG_Scripts/Resize_psd.bat
Arguments: "%1" "[Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"]" "[Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"]" "%2"
With a sample job the arguments looks fine and i have also tried without "" on my size values but it doesn't make any difference. But i don't get any output file from Image Magick.
If i try to alter my bat file to this magick.exe C:\Users\Admin\Desktop\Test-2560x1440.psd[0] -resize 1700x1700 -sharpen 3 Test.tif and executes it from the command prompt it works just fine. So i changed my Switch bat file to magick.exe %1[0] -resize %2x%3 -sharpen 3 %4.tif but neither did that do any difference.
Edit:
Also tried to use my Switch bat file from the command prompt and it works fine, but not from Switch.
- magnussandstrom
- Advanced member
- Posts: 381
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Get one layer from Imagemagick
My guess is that this approach will not populate %1 %2 %3 %4 with any information, since the Resize_ps.bat is a static file and will just be executed 'as is'.Fredrik wrote: ↑Wed May 24, 2023 1:37 pmThank's for your input. I have created a .bat file containing this code, named Resize_psd.batfreddyp wrote: ↑Wed May 17, 2023 10:05 am That is because anything between [] is considered to be a variable in a single-line text with variables and [0] is not a valid Switch variable.
My advice when working with more complex commands in the context of "Execute command" is to put everything in a batch file/shell script. In "Command or path" you select the bat/sh file and in "Arguments" you specify a list of, well, arguments for the bat/sh:
"%1" "%2" [SomeSwitchVariable1] [SomeSwitchVariable2] etc.
In a Windows batch file you use %1, %2, %3, ... following the order of the arguments as you specified them in "Arguments" and place them in the right place in the command, e.g.
"C:\Program Files\ImageMagick-6.9.2-Q16\convert.exe" %1[0] --resize %3X%4 %2 (do not use double quotes)
In a Mac shell script it would look like:
#!/bin/bash
/usr/local/bin/convert "$1" -resize $3X$4 "$2" (note that here double quotes are required for paths to avoid problems with spaces and that the arguments are prefixed with a $ sign and not a % sign)
You must also not forget to make the .sh file executable: chmod +x pathToShellScript
C:/Program Files/ImageMagick-7.1.1-Q16-HDRI/magick.exe %1[0] -resize %2x%3 -sharpen 3 %4.tif
In my Execute Command i have entered the following
Command: C:/Program Files/ImageMagick-7.1.1-Q16-HDRI/MGG_Scripts/Resize_psd.bat
Arguments: "%1" "[Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"]" "[Job.PrivateData:Key="[Job.Hierarchy:Index="3"]mm"]" "%2"
With a sample job the arguments looks fine and i have also tried without "" on my size values but it doesn't make any difference. But i don't get any output file from Image Magick.
If i try to alter my bat file to this magick.exe C:\Users\Admin\Desktop\Test-2560x1440.psd[0] -resize 1700x1700 -sharpen 3 Test.tif and executes it from the command prompt it works just fine. So i changed my Switch bat file to magick.exe %1[0] -resize %2x%3 -sharpen 3 %4.tif but neither did that do any difference.
Edit:
Also tried to use my Switch bat file from the command prompt and it works fine, but not from Switch.
Re: Get one layer from Imagemagick
Perhaps you are correct, i don't get any more error messages in Switch than that the expected output file doesn't exists. Is this an issue with Switch then? Because if i try to activate the bat file from the command prompt with the variables it works just fine.magnussandstrom wrote: ↑Wed May 24, 2023 3:34 pm My guess is that this approach will not populate %1 %2 %3 %4 with any information, since the Resize_ps.bat is a static file and will just be executed 'as is'.
Bat file contains.
magick.exe %1[0] -resize %2 -sharpen 3 %3
Command.
C:\Users\Admin\Desktop>Resize_psd_Test.bat C:\Users\Admin\Desktop\Test-2560x1440.psd 1700x1700 Test.tif
This works and creates a 1700 px tif image in the same location since i don't point at another one in my command.
Re: Get one layer from Imagemagick
This works for me with the BAT-file created with the app "ExecuteCommand friend"
This is my BAT-file, you can add more variables if you want.
Flow looks like this since we have to save the BAT-file for execute command to pick it up. It will be over written with the next job.
Fredrik, you can email me if you need more help with it.
jan.suhr@colorconsult.se
This is my BAT-file, you can add more variables if you want.
Code: Select all
set filename=%1
set output=%2
"C:\Program Files\ImageMagick-7.0.11-Q16-HDRI\convert.exe" %filename%[1] -resize [Job.PrivateData:Key="size"]x[Job.PrivateData:Key="size"] -sharpen 3 %output%
Fredrik, you can email me if you need more help with it.
jan.suhr@colorconsult.se
Re: Get one layer from Imagemagick
Hi Jan!
How does your execute command look like? Command or path and arguments?
I create a bat file with Execute Command Friend and it looks like this and i think it is correct.
set filename=%1
set output=%2
C:/Program Files/ImageMagick-7.1.1-Q16-HDRI/magick.exe C:/Users/Admin/Roaming/Enfocus/Switch Server/PropertySets/12/PSD_Files/%filename%[0] -resize 1772x1772 -sharpen 3 %output%
The bat file is saved as input filename .bat and placed in a temp folder, the psd file is also placed in a temp folder. When picked up by switch i run a execute command where i try to use the bat file, maybe this is not the correct way?
How does your execute command look like? Command or path and arguments?
I create a bat file with Execute Command Friend and it looks like this and i think it is correct.
set filename=%1
set output=%2
C:/Program Files/ImageMagick-7.1.1-Q16-HDRI/magick.exe C:/Users/Admin/Roaming/Enfocus/Switch Server/PropertySets/12/PSD_Files/%filename%[0] -resize 1772x1772 -sharpen 3 %output%
The bat file is saved as input filename .bat and placed in a temp folder, the psd file is also placed in a temp folder. When picked up by switch i run a execute command where i try to use the bat file, maybe this is not the correct way?
- Attachments
-
- Skärmavbild 2023-06-01 kl. 13.05.09.png (41.05 KiB) Viewed 47967 times
-
- Skärmavbild 2023-06-01 kl. 13.05.49.png (20.58 KiB) Viewed 47967 times
-
- Skärmavbild 2023-06-01 kl. 13.06.13.png (135.9 KiB) Viewed 47967 times
Re: Get one layer from Imagemagick
Here is the settings.
The %1 variable that Execute command uses is the full path to the incoming file. So you just set it up as in the attached screen shot and it will work for you.
The %1 variable that Execute command uses is the full path to the incoming file. So you just set it up as in the attached screen shot and it will work for you.
Re: Get one layer from Imagemagick
Thanks! It works now, but i was afraid there would be an issue if multiple users uses this flow at the same time since we are overwriting the same .bat file and when testing this by putting two images in the flow with different sizes they both came out with the same size. So there is an issue with this.
I will try to go back to my first set up where every job gets it's own bat file.
I will try to go back to my first set up where every job gets it's own bat file.
- JimmyHartington
- Advanced member
- Posts: 320
- Joined: Tue Mar 22, 2011 7:38 am
Re: Get one layer from Imagemagick
You could set a private data key to the unique prefix.
Save the bat file as the private data unique prefix.
And run the command with private data unique prefix.
Just remember to set the private data before splitting the flow.
Save the bat file as the private data unique prefix.
And run the command with private data unique prefix.
Just remember to set the private data before splitting the flow.