How Can I Batch Adjoin Multiple Images From Two Folders?

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?".
Sibrah
Posts: 8
Joined: 2014-04-22T11:03:38-07:00
Authentication code: 6789

How Can I Batch Adjoin Multiple Images From Two Folders?

Post by Sibrah »

How can i batch adjoin series of Images from two different folders? The images are named like 0211100001, 0211100002, 0211100003, and so on for one group in folder A and Images in folder B carry same names as those in folder A. I need to combine corresponding images carrying same name across the two folders so that original content of both images are displayed side-by-side.
I am looking for a a GUI tool or script that can batch it for me by looping through all file with similar names and joining them to a form a single image displaying content from original Images side-by-side. Corresponding files from both folders
don't have same dimension. I like to think of it as involving a one-to-one name-based mapping of many images from two different folders.
Last edited by Sibrah on 2014-04-23T06:21:23-07:00, edited 2 times in total.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: How Can I Batch Adjoin Multiple Images From Two Folder?

Post by dlemstra »

What is your operating system?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Sibrah
Posts: 8
Joined: 2014-04-22T11:03:38-07:00
Authentication code: 6789

Re: How Can I Batch Adjoin Multiple Images From Two Folder?

Post by Sibrah »

dlemstra, Operating system is Windows7. If i have a script or solution for other windows OS, then i will be willing to consider a brand new OS installation. Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How Can I Batch Adjoin Multiple Images From Two Folder?

Post by snibgo »

It could be something like this:

Code: Select all

set FOLDER_A=\blah\blah
set FOLDER_B=\another\blah
set FOLDER_OUT=\out_blah

for %%F in (%FOLDER_A%\a*.png) do (
  if exist %FOLDER_B%\%%~nxF %IM%convert %%F %FOLDER_B%\%%~nxF +append %FOLDER_OUT%\%%~nxF
)
Tested in Windows 8.1, but probably fine for Windows 7, Windows XP, etc.
snibgo's IM pages: im.snibgo.com
Sibrah
Posts: 8
Joined: 2014-04-22T11:03:38-07:00
Authentication code: 6789

Re: How Can I Batch Adjoin Multiple Images From Two Folder?

Post by Sibrah »

snibgo, I tried your script but didn't get no results.I changed four things -
(1). The Folder for Folder A
(2). The folder for Folder B
(3).The Output Folder and
(4). The file extension .png to .jpeg and didn't get a result.
I am suspecting the commands -enjoin, all my search effort so far points to the -enjoin keyword. I hardly understand the syntax, though i have a strong feeling i can do what i want with little modification.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How Can I Batch Adjoin Multiple Images From Two Folders?

Post by snibgo »

What messages do you get?

I searched for "a*.png". Change that as you need, for example "*.jpg" for "*".

"-enjoin" isn't an ImageMagick keyword. Where did you find it?
snibgo's IM pages: im.snibgo.com
Sibrah
Posts: 8
Joined: 2014-04-22T11:03:38-07:00
Authentication code: 6789

Re: How Can I Batch Adjoin Multiple Images From Two Folders?

Post by Sibrah »

i got no messages after executing the said script in ImageMagick dir from command prompt. I must confess i am lost here. From which environment did you run the script? Please help a ImageMagick/Graphics newbie. i really need this solution.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How Can I Batch Adjoin Multiple Images From Two Folders?

Post by snibgo »

I provided a Windows BAT script, to be put in a file and run. If you want to type it at the prompt, change each double percent %% to single percent %.
snibgo's IM pages: im.snibgo.com
Sibrah
Posts: 8
Joined: 2014-04-22T11:03:38-07:00
Authentication code: 6789

Re: How Can I Batch Adjoin Multiple Images From Two Folders?

Post by Sibrah »

snibgo wrote:I provided a Windows BAT script, to be put in a file and run. If you want to type it at the prompt, change each double percent %% to single percent %.
Did it that way, Still no luck. Thanks for the effort so far, i was expecting a simple script that i can easily pinpoint where to substitute my Images folders directories, output directory and image name patterns but it seems i can't work with your script or maybe i am not ImageMagick ready. All the same, Thanks alot for the wonderful try.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How Can I Batch Adjoin Multiple Images From Two Folders?

Post by fmw42 »

Take it one step at a time. What is your version of IM? Have you renamed the Imagemagick convert.exe to say imconvert, so it does not interfere with the Windows convert

Try a simple operation with one image from each folder (assuming jpg format). Copy and past this into your Command Window

Code: Select all

imconvert path2folderA\image1.jpg path2folderB\image1.jpg +append path2folderC\image1.jpg
where folderC must already exist and folderA and folderB have your two jpg images and the path is the full path from the disk (presumably C:). Use suffix .png, if your input images are png.

Does this work? If not, what kind of error message do you get.

Note I am not a Windows user, so any Windows user should feel free to correct any errors I have made in the above.
Sibrah
Posts: 8
Joined: 2014-04-22T11:03:38-07:00
Authentication code: 6789

Re: How Can I Batch Adjoin Multiple Images From Two Folders?

Post by Sibrah »

FMW42, i tried ur code and got an error message like:
this unable to open image [image dir/image.jpg]
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How Can I Batch Adjoin Multiple Images From Two Folders?

Post by Bonzo »

Always post your full command as well as it could have a simple syntax error which could be the problem.

If this is the path to your input image: image dir/image.jpg then the space between image and dir could be the problem. Try using this instead "image dir/image.jpg"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How Can I Batch Adjoin Multiple Images From Two Folders?

Post by fmw42 »

Sibrah wrote:FMW42, i tried ur code and got an error message like:
this unable to open image [image dir/image.jpg]
I assumed you were on windows and thus I believe you should be using backslashes and not forward slashes. I am not a windows user, so someone else should correct my syntax.

As Bonzo said, it is best to provide you exact command line to be sure there are no other typos.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How Can I Batch Adjoin Multiple Images From Two Folders?

Post by snibgo »

On Windows, IM accepts forward slashes / as well as back slashes \. I think it is better practice to use the usual Windows convention of backslashes.

Certainly, best to show us the exact command (and exact error message).

Also try very simple commands like:

Code: Select all

convert -version
convert rose: r.png
convert r.png r.jpg
What does "convert -version" say?
snibgo's IM pages: im.snibgo.com
Sibrah
Posts: 8
Joined: 2014-04-22T11:03:38-07:00
Authentication code: 6789

Re: How Can I Batch Adjoin Multiple Images From Two Folders?

Post by Sibrah »

I was able to run this code successfully:

Code: Select all

imconvert 0220100001.jpg 0220100001[].jpg +append result.jpg
I placed the pictures 0220100001.jpg and 0220100001[].jpg into the ImageMagick directory and it generated a result.jpg file. i am trying to figure out how to advance and represent my file names properly in snibgo script. My file are named like 0220100001, 0220100002, 0220100003 and so on in both folders so that 0220100001.jpg in folders A gets joined to 0220100001.jpg in folder B, however i still haven't figured out how to related that part with the command prompt script.

The part below is the portion of the code i am finding difficult to figure out

Code: Select all

for %%F in (%FOLDER_A%\a*.png) do (
  if exist %FOLDER_B%\%%~nxF %IM%convert %%F %FOLDER_B%\%%~nxF +append %FOLDER_OUT%\%%~nxF
Last edited by Sibrah on 2014-04-28T10:43:52-07:00, edited 3 times in total.
Post Reply