Page 1 of 1
Compose: Overlay over multiple coordinates w/o loop [Solved]
Posted: 2018-12-31T11:00:25-07:00
by coloring
How can I overlay
Small.png over
Large.png at multiple coordinates without a loop?
I am currently looping this command (+0+0 is replaced with different coordinates every iteration):
Code: Select all
convert.exe Large.png Small.png -geometry +0+0 -compose over -composite Large.png
Could I "-geometry" accept a multi-line variable like the one below?
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2018-12-31T11:30:10-07:00
by fmw42
How about this:
Code: Select all
convert.exe Large.png Small.png ^
( -clone 1 -set page +0+0 ) ^
( -clone 1 -set page +11+22 ) ^
( -clone 1 -set page +33+44 ) ^
( -clone 1 -set page +44+0 ) ^
( -clone 1 -set page +0+99 ) ^
-delete 1 ^
-flatten Large.png
or
Code: Select all
convert.exe Large.png ( Small.png -write mpr:img +delete ) ^
( mpr:img -set page +0+0 ) ^
( mpr:img -set page +11+22 ) ^
( mpr:img -set page +33+44 ) ^
( mpr:img -set page +44+0 ) ^
( mpr:img -set page +0+99 ) ^
-flatten Large.png
see
https://imagemagick.org/Usage/layers/
There are various ways to do multiple image composites, but there is nothing like what you desire for -geometry
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2018-12-31T11:57:23-07:00
by coloring
Thanks! What what if the number of coordinates is not fixed? Can I provide a text file with a list of coordinates? The
Pins in a Map example is close, but I am running plain Windows.
If not, perhaps I could use a loop to generate the command text, and then execute the result. The idea is to avoid executing IM more than once.
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2018-12-31T12:19:54-07:00
by fmw42
As far as I know, then only way is to write a script loop that will read your file and loop over doing a -composite or -flatten.
If the number of composites is not too many (that you exceed your OS limit of characters in a line), you can write a loop to create the single command. I do that often in my unix bash scripting.
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2018-12-31T13:45:36-07:00
by coloring
In Windows, with the maximum length of the command string being limited to 8191 characters and "
( -clone 1 -set page +NNNN+NNNN ) " taking up 34 characters -- assuming no shorter forms exist --, the number of coordinates that can fit in a single line is at least 238.
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2018-12-31T13:50:29-07:00
by fmw42
So is 238 acceptable?
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2018-12-31T14:04:20-07:00
by coloring
80% of the time, yes. I will add a loop to execute IM for every group of 238 coordinates to overcome this limitation. Does that mean there are no shortcuts for -clone and -set page? How come spaces inside the brackets are necessary?
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2018-12-31T14:25:37-07:00
by snibgo
If your command is too long for the shell, write it to a file
without the executable name or shell escapes, and run it as a magick script:
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2018-12-31T15:36:32-07:00
by fmw42
How come spaces inside the brackets are necessary?
That is just the way Imagemagick must be parsed.
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2019-01-02T13:11:01-07:00
by coloring
snibgo wrote: ↑2018-12-31T14:25:37-07:00
If your command is too long for the shell, write it to a file
without the executable name or shell escapes, and run it as a magick script:
A godsend! Aren't
compare.exe, composite.exe, conjure.exe, convert.exe, identify.exe, magick.exe, mogrify.exe, montage.exe, and stream.exe the exact same file, though?
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2019-01-02T13:28:22-07:00
by snibgo
I don't know what you mean. As far as I know, "-script" works with v7 magick, and no other IM program.
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2019-01-02T13:30:27-07:00
by fmw42
Aren't compare.exe, composite.exe, conjure.exe, convert.exe, identify.exe, magick.exe, mogrify.exe, montage.exe, and stream.exe the exact same file, though?
No each is different. In IM 7, they must be called by prefacing the names with magick, except for convert, which is simply replaced by magick.
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2019-01-02T13:46:01-07:00
by coloring
Okay. It just seemed odd that they are all the same size (18,945 KB).
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2019-01-02T14:10:30-07:00
by coloring
Something is wrong. Here is my version:
Code: Select all
C:> magick.exe --version
Version: ImageMagick 7.0.8-16 Q16 x64 2018-12-10 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC HDRI
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr
lzma openexr pangocairo png ps raw rsvg tiff webp xml zlib
Content of myscript.txt:
Code: Select all
img\Large.png img\Small.png ( -clone 1 -set page +0+0 ) -delete 1 -flatten img\Output.png
I am calling myscript.txt in the command line (cmd.exe):
Code: Select all
C:>magick.exe -script myscript.txt
Result:
Code: Select all
magick.exe: UnableToOpenBlob 'imgLarge.png': No such file or directory @ error/blob.c/OpenBlob/3490.
Apparently, it does not like the backslash character (\) for some reason.
I replaced the backslashes with normal slashes in myscript.txt:
Code: Select all
img/Large.png img/Small.png ( -clone 1 -set page +0+0 ) -delete 1 -flatten img/Output.png
After calling magick.exe as before, this is the result:
Code: Select all
magick.exe: UnableToOpenBlob 'img/Output.png': No such file or directory @ error
/blob.c/OpenBlob/3490.
Does the output file have to exist for some reason? I tried creating such a file, but IM just fails silently in that case. The lines below behave as expected when executed directly in the command line:
Code: Select all
convert.exe img\Large.png img\Small.png ( -clone 1 -set page +0+0 ) -delete 1 -flatten img\Output.png
convert.exe img/Large.png img/Small.png ( -clone 1 -set page +0+0 ) -delete 1 -flatten img/Output.png
EDIT: According to https://stackoverflow.com/questions/50876200/, I needed to add -write to fix the Output issue:
Code: Select all
img/Large.png img/Small.png ( -clone 1 -set page +0+0 ) -delete 1 -flatten -write img/Output.png
The backslashes are still a problem, though.
Re: Compose: Overlay over multiple coordinates w/o loop
Posted: 2019-01-02T14:20:47-07:00
by snibgo
In Windows, use forward-slashes, or simply cd to the directory first.
For the output, use "-write", eg "-write img/Output.png".