Page 1 of 1
How to join images in a 2x2 grid using "convert"
Posted: 2017-05-30T10:48:03-07:00
by T2ioTD
Hi All
I am using this batch script extensively to collates images side by side:
SETLOCAL EnableDelayedExpansion
SET IMCONV="%PROGRAMFILES%\ImageMagick-7.0.4-Q16\Convert"
SET COUNT=0
setlocal ENABLEDELAYEDEXPANSION
FOR /R %%T IN (*.jpg) DO (
SET /A COUNT=!COUNT!+1
REN %%T A!COUNT!.jpg
)
:EOF
@echo off
set count=0
for %%x in (*.jpg) do set /a count+=1
set /a demi=%count% / 2
FOR /L %%x IN (1,2,%count%) DO (
set /a y = %%x + 1
%IMCONV% A%%x.jpg A!y!.jpg +append B%%x.jpg
)
endlocal
However I would like to collate also images in a grid of 2x2, and I do not know how.
PS. another mini problem in my script is that is it is unable to renumber correctly images if they start with a digit, but this may be for another time..
Re: How to join images in a 2x2 grid using "convert"
Posted: 2017-05-30T11:08:26-07:00
by snibgo
A convert command to append 4 images in a 2x2 grid is (Windows BAT syntax):
Code: Select all
convert ^
( a.jpg b.jpg +append ) ^
( c.jpg d.jpg +append ) ^
-append ^
out.jpg
When inside a "for (...)" loop, you need to escape the parentheses or quote them:
Code: Select all
convert ^
^( a.jpg b.jpg +append ^) ^
^( c.jpg d.jpg +append ^) ^
-append ^
out.jpg
Re: How to join images in a 2x2 grid using "convert"
Posted: 2017-05-30T11:46:50-07:00
by T2ioTD
Snibgo, Inspired by your answer, and trying to incorporate it in my humble program, I manage no better than:
SETLOCAL EnableDelayedExpansion
SET IMCONV="%PROGRAMFILES%\ImageMagick-7.0.4-Q16\Convert"
SET COUNT=0
setlocal ENABLEDELAYEDEXPANSION
FOR /R %%T IN (*.jpg) DO (
SET /A COUNT=!COUNT!+1
REN %%T A!COUNT!.jpg
)
:EOF
@echo off
set count=0
for %%x in (*.jpg) do set /a count+=1
set /a demi=%count% / 2
FOR /L %%x IN (1,4,%count%) DO (
set /a y = %%x + 1
set /a w = %%x + 2
set /a z = %%x + 3
%IMCONV% A%%x.jpg A!y!.jpg +append
A!w!.jpg A!x!.jpg +append
B%%x.jpg +append
)
endlocal
However it is making an error... Could you help me please?
Re: How to join images in a 2x2 grid using "convert"
Posted: 2017-05-30T12:33:04-07:00
by snibgo
Your convert command is very different to mine.
Re: How to join images in a 2x2 grid using "convert"
Posted: 2017-05-30T12:45:03-07:00
by T2ioTD
The fact that I renamed Convert into IMCONV in the line: SET IMCONV="%PROGRAMFILES%\ImageMagick-7.0.4-Q16\Convert"
was been advised by IM itself so that there will be no conflict with Windows System own Convert operation...
Please disregard this line and provide your own lines of codes as you would normally do...
Re: How to join images in a 2x2 grid using "convert"
Posted: 2017-05-30T12:54:32-07:00
by snibgo
What error message do you get? Some errors are obvious:
Your convert has 5 inputs and no output.
You have three "+append" instead of two "+append and one "-append"
You have no parentheses.
Most importantly, you have no line continuation characters.
Re: How to join images in a 2x2 grid using "convert"
Posted: 2017-05-30T12:55:02-07:00
by T2ioTD
Success! Based on Snibgo help, I managed the successful:
SETLOCAL EnableDelayedExpansion
SET IMCONV="%PROGRAMFILES%\ImageMagick-7.0.4-Q16\Convert"
SET COUNT=0
setlocal ENABLEDELAYEDEXPANSION
FOR /R %%T IN (*.jpg) DO (
SET /A COUNT=!COUNT!+1
REN %%T A!COUNT!.jpg
)
:EOF
set count=0
for %%x in (*.jpg) do set /a count+=1
FOR /L %%x IN (1,4,%count%) DO (
set /a y = %%x + 1
set /a w = %%x + 2
set /a z = %%x + 3
%IMCONV% ^
^( A%%x.jpg A!y!.jpg +append ^) ^
^( A!w!.jpg A!z!.jpg +append ^) ^
-append ^
B%%x.jpg
)
endlocal