Page 1 of 1
Specific Output Names when Using Convert
Posted: 2016-07-04T15:28:06-07:00
by CrazyHomelessGuy
I am splitting 3d stereoscopic images into 2 separate files. The code below works as I need it to but the output names for a test.jpg image are test-0.jpg and test-1.jpg. Is there an easy way to write the filenames as test-L.jpg and test-R.jpg? The L and R stand for Left and Right images for stereoscopic viewing.
Code: Select all
convert -crop 1x2@ +repage +adjoin %* *.jpg
Thanks,
Travis
Re: Specific Output Names when Using Convert
Posted: 2016-07-04T17:39:11-07:00
by fmw42
It is generally not a good idea to use wildcards for both input and output. You will have to write a script loop to use specific names.
Note proper IM 6 and 7 syntax is to read the input first, then the settings and operators, then the output.
Please, always provide your IM version and platform when asking questions, since syntax may differ.
See
viewtopic.php?f=1&t=9620
Re: Specific Output Names when Using Convert
Posted: 2016-07-05T07:57:00-07:00
by CrazyHomelessGuy
Thanks. I found an easy way to do it... In this case I will always have 0 and 1 so I can just use a Window's Batch Script rename to accomplish what I want.
Code: Select all
convert -crop 1x2@ +repage +adjoin %* *.jpg
ren *-0.jpg *-L.jpg
ren *-1.jpg *-R.jpg
Re: Specific Output Names when Using Convert
Posted: 2016-07-05T08:09:47-07:00
by CrazyHomelessGuy
fmw42 wrote:It is generally not a good idea to use wildcards for both input and output.
I'm a hack at best when it comes to writing scripts. I need to be able to drag and drop images onto the script with no additional input as others besides myself will be using this script. This is currently working well, not sure if that is a fluke or not.
Re: Specific Output Names when Using Convert
Posted: 2016-07-05T08:32:50-07:00
by snibgo
fmw42 wrote:It is generally not a good idea to use wildcards for both input and output.
I agree, but that's not happening here. In a Windows BAT script, "%*" is equivalent to bash "$*", expanding to the positional parameters of the script.
CrazyHomelessGuy wrote:... not sure if that is a fluke or not.
It is a fluke. You are using bad syntax (which just happens to work, for now). You should read files, process the images, then write them to files.
Re: Specific Output Names when Using Convert
Posted: 2016-07-05T10:51:41-07:00
by GeeMack
CrazyHomelessGuy wrote:I'm a hack at best when it comes to writing scripts. I need to be able to drag and drop images onto the script with no additional input as others besides myself will be using this script. This is currently working well, not sure if that is a fluke or not.
As
snibgo mentioned, if it's working, it's accidental and not by design. You might consider using proper form so if you upgrade your IM or run it on a different machine with a different version of IM it won't break the script. You can make a Windows script like this...
Code: Select all
@echo off
pushd "%~dp1"
convert "%~1" ^
-crop 1x2@ -write mpr:img -delete 0--1 ^
mpr:img[0] -write "%~n1-L.jpg" +delete ^
mpr:img[1] "%~n1-R.jpg"
popd
exit /b
... and name it something like "stereosplit.bat". Then drag and drop any image on it, or even on a shortcut to it. It will split the image into an upper half and a lower half. It will save them as JPG images in the folder where the image resides. It will name them with their original filename but ending with a "-L.jpg" or a "-R.jpg".
Re: Specific Output Names when Using Convert
Posted: 2016-07-05T17:12:10-07:00
by CrazyHomelessGuy
GeeMack wrote:CrazyHomelessGuy wrote:I'm a hack at best when it comes to writing scripts. I need to be able to drag and drop images onto the script with no additional input as others besides myself will be using this script. This is currently working well, not sure if that is a fluke or not.
As
snibgo mentioned, if it's working, it's accidental and not by design. You might consider using proper form so if you upgrade your IM or run it on a different machine with a different version of IM it won't break the script. You can make a Windows script like this...
Code: Select all
@echo off
pushd "%~dp1"
convert "%~1" ^
-crop 1x2@ -write mpr:img -delete 0--1 ^
mpr:img[0] -write "%~n1-L.jpg" +delete ^
mpr:img[1] "%~n1-R.jpg"
popd
exit /b
... and name it something like "stereosplit.bat". Then drag and drop any image on it, or even on a shortcut to it. It will split the image into an upper half and a lower half. It will save them as JPG images in the folder where the image resides. It will name them with their original filename but ending with a "-L.jpg" or a "-R.jpg".
Many thanks! This worked perfectly and is future proof.