Specific Output Names when Using Convert

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
CrazyHomelessGuy
Posts: 4
Joined: 2016-07-04T15:22:17-07:00
Authentication code: 1151
Location: San Francisco

Specific Output Names when Using Convert

Post 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
Windows7
IM 7.0.2-0 Q16
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Specific Output Names when Using Convert

Post 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
CrazyHomelessGuy
Posts: 4
Joined: 2016-07-04T15:22:17-07:00
Authentication code: 1151
Location: San Francisco

Re: Specific Output Names when Using Convert

Post 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
Last edited by CrazyHomelessGuy on 2016-07-05T08:10:44-07:00, edited 1 time in total.
Windows7
IM 7.0.2-0 Q16
CrazyHomelessGuy
Posts: 4
Joined: 2016-07-04T15:22:17-07:00
Authentication code: 1151
Location: San Francisco

Re: Specific Output Names when Using Convert

Post 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.
Windows7
IM 7.0.2-0 Q16
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Specific Output Names when Using Convert

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Specific Output Names when Using Convert

Post 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".
CrazyHomelessGuy
Posts: 4
Joined: 2016-07-04T15:22:17-07:00
Authentication code: 1151
Location: San Francisco

Re: Specific Output Names when Using Convert

Post 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.
Windows7
IM 7.0.2-0 Q16
Post Reply