Convert - Mogrify - Append - Same Filename | Windows IM7.0.8

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
TD4IM
Posts: 5
Joined: 2019-10-16T01:55:58-07:00
Authentication code: 1152

Convert - Mogrify - Append - Same Filename | Windows IM7.0.8

Post by TD4IM »

Hello, this forum is the last resort for my problem, I can't figure it myself after hours of trials and errors. I feel compleatly drained and broke.
Platform - Windows
ImageMagick v7.0.8

Simple task:

We have "test" folder inside ImageMagick portable version with separate png images all named "year-month-day-hour-minute-###-tags"

year-month-day-hour-minute - when I renamed it
### - 001-002-003 etc
tags - each page may contain additional hand made tags for earsier search

My goal to +append all images in "test" folder is specific manner 2+1 4+3 6+5 etc (I figured that 1+2 3+4 5+6 etc will work too with +swap or -reverse) the huge problem is I can't figure out how to make outputs named the same as source files. Mogrify for 2 images with all possible combitations just replaced files at best without image merge

Code: Select all

mogrify *001*.png *002*.png +swap +append
and using convert I don't know how to force it to name output files by source names. Any help appreciated.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert - Mogrify - Append - Same Filename | Windows IM7.0.8

Post by snibgo »

For IM v7, I suggest you use "magick".
TD4IM wrote:...images all named "year-month-day-hour-minute-###-tags"
I suppose an example filename would be 2019-10-16-13-46-003-dogs-people.png". Is that correct? If not, please give some samples.

Do all the files with the same date/time have the same tags, so they differ just by the 3-digit number? Or could you have two files with the same date/time and 3-digit number, differing just by tags?
TD4IM wrote:... the huge problem is I can't figure out how to make outputs named the same as source files.
But each output file is made from two input files. The output can't have the same name as both input files. Please give examples.

In general, you will be looping through input files. You might need two nested loops: the outermost loops through all the *-001-* files, the innermost loops through the numbered files. In that script, you would set a variable that contains each output filename. You would then run "magick" with two inputs and one output.
snibgo's IM pages: im.snibgo.com
TD4IM
Posts: 5
Joined: 2019-10-16T01:55:58-07:00
Authentication code: 1152

Re: Convert - Mogrify - Append - Same Filename | Windows IM7.0.8

Post by TD4IM »

Thank you for your answer. All filenames have different digit numbers, date and time always the same for batch convert, tags may vary or there can be none at all.

Example:
2019-10-16-13-46-001-dogs-people.png
2019-10-16-13-46-002-dogs-people.png
2019-10-16-13-46-003-cats.png
2019-10-16-13-46-004-cats.png
2019-10-16-13-46-006.png
2019-10-16-13-46-007.png
2019-10-16-13-46-008-people-cats.png
2019-10-16-13-46-009-people-cats.png
Then how to name output file taking just one input in consideration (first or second doesn't matter, they will have identical tags).

Example:
input 1 - 2019-10-16-13-46-001-dogs-people.png
input 2 2019-10-16-13-46-002-dogs-people.png
output 2019-10-16-13-46-001-dogs-people.png or 2019-10-16-13-46-002-dogs-people.png
ideal output 2019-10-16-13-46-001-002-dogs-people.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert - Mogrify - Append - Same Filename | Windows IM7.0.8

Post by snibgo »

The question is really about scripting, not ImageMagick. This is an ImageMagick forum, not a scripting forum. But I'm feeling generous. Windows BAT syntax:

Code: Select all

for %%Z in (*-001-*.png) do (
  echo %%Z

  for /F "tokens=1-5 delims=-." %%A in ("%%Z") do set PREFIX=%%A-%%B-%%C-%%D-%%E-

  echo PREFIX=!PREFIX!

  for %%Y in (!PREFIX!*.png) do (
    for /F "tokens=6 delims=-." %%A in ("%%Y") do set NUMBER=%%A

    set /A REMD=!NUMBER:~-1! %% 2

    echo NUMBER=!NUMBER!  REMD=!REMD!

    if !REMD!==0 (
      set OUTFILE=!PREVFILE!
      magick %%Y !PREVFILE! +append outdir\!OUTFILE!
    )
    set PREVFILE=%%Y

  )

)
snibgo's IM pages: im.snibgo.com
TD4IM
Posts: 5
Joined: 2019-10-16T01:55:58-07:00
Authentication code: 1152

Re: Convert - Mogrify - Append - Same Filename | Windows IM7.0.8

Post by TD4IM »

It didn't work (window intantly closes) and looks so complex, that I even don't know where to fix what. I don't need elegant script solution it's above my mental capabilities, if possible some basic simple output command to transfer original filename of first file in memory to output file
convert *001*.png *002*.png +swap +append %t.png
if not, then I'm just out of luck to bring this endevor to any fruition without heavy artillery. Anyway, thank you.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert - Mogrify - Append - Same Filename | Windows IM7.0.8

Post by fmw42 »

Sorry, I am not a Windows user and do not know what the asterisk mean. But with simple filenames you can do:

Code: Select all

convert 001.png -set filename:fn "%t" 002.png +swap +append "%[filename:fn].png"
see https://imagemagick.org/Usage/basics/#set
TD4IM
Posts: 5
Joined: 2019-10-16T01:55:58-07:00
Authentication code: 1152

Re: Convert - Mogrify - Append - Same Filename | Windows IM7.0.8

Post by TD4IM »

First of all, thank you fmw42, for cooperation.
What I have tried recently to no avail:

https://www.imagemagick.org/Usage/files/#save_escapes
https://www.imagemagick.org/discourse-s ... hp?t=18272
https://stackoverflow.com/questions/999 ... -same-name
https://www.imagemagick.org/script/comm ... 7tj5d6#set
https://www.imagemagick.org/discourse-s ... hp?t=17149
(and many others I didn’t bookmark)

Now I think I know why nothing works – wrong/outdated syntax. Like looking for a black cat in a wormhole I never used ImageMagic before, so have no reference for any working syntax.

Code: Select all

Convert 001.png -set filename:fn "%t" 002.png +swap +append "%[filename:fn].png" – instant close no output
magick 001.png -set filename:fn "%t" 002.png +swap +append "%[filename:fn].png" – instant close no output
magick 001.png -set filename:fn %t 002.png +swap +append %[filename:fn].png – instant close no output
magick 001.png -set filename:fn %t 002.png +swap +append "%[filename:fn].png" – instant close no output
magick 001.png -set filename:fn %%t 002.png +swap +append %%[filename:fn].png - (without extension) %[filename zero bytes output
magick 001.png -set filename:fn %%t 002.png +swap +append %[filename:fn].png – normally merged fn].png output
magick 001.png -set filename:fn "%%t" 002.png +swap +append "%%[filename:fn].png" - (without extension) %[filename zero bytes output
magick 001.png -set filename:fn '%%t' 002.png +swap +append '%%[filename:fn].png' - (without extension) ‘%[filename zero bytes output
magick 001.png -set filename:fn %%t 002.png +swap +append %filename:fn.png - normally merged fn.png output
No happy end here, without PRO user/developer with Windows who can tell proper syntax it’s a maze with no map.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert - Mogrify - Append - Same Filename | Windows IM7.0.8

Post by fmw42 »

These commands work for me. Try them and let us know.

Create named images from Imagemagick internal images.

Code: Select all

magick logo: logo.png
magick rose: rose.png

Code: Select all

magick logo.png -set filename:fn "%t" rose: +append "%[filename:fn]_x1.png"

Code: Select all

magick rose: logo.png -set filename:fn "%t" +swap +append "%[filename:fn]_x2.png"
I added the _x1 and _x2 so as not to write over the logo.png input

This will not work because it swaps the image that has the filename to the second position in the command line. That is why in the above _x2 command I swapped the images in the command and then use +swap.

Code: Select all

magick logo.png -set filename:fn "%t" rose: +swap +append "%[filename:fn]_x3.png"
TD4IM
Posts: 5
Joined: 2019-10-16T01:55:58-07:00
Authentication code: 1152

Re: Convert - Mogrify - Append - Same Filename | Windows IM7.0.8

Post by TD4IM »

Code: Select all

magick logo: logo.png - created output logo.png
magick rose: rose.png - created output rose.png
Then I hit block of the road, but somehow achieved not a bad end.

Code: Select all

magick logo.png -set filename:fn "%t" rose: +append "%[filename:fn]_x1.png" – just instantly closed
I added, “pause” to see what the hell. Error:

Code: Select all

magick: MissingArgument `-set' at CLI arg 2 @ fatal/magick-cli.c/ProcessCommandOptions/447
This is definitely problem on my end I thought, installed ImageMagick-7.0.8-68-Q16-x64-dll (until then I was using same portable version), nope problem still exists, .bat .cmd were throwing the error string. Then I opened CMD directly in the folder where program resides BAM

Code: Select all

magick logo.png -set filename:fn "%t" rose: +append "%[filename:fn]_x1.png" – merged logo_x1.png has been created
Land ahoy! Here we go. In .cmd file

Code: Select all

magick rose: logo.png -set filename:fn "%t" +swap +append "%[filename:fn]_x2.png" - magick: MissingArgument `-set' at CLI arg 3 @ fatal/magick-cli.c/ProcessCommandOptions/447
CMD opened in folder or cd to folder

Code: Select all

magick rose: logo.png -set filename:fn "%t" +swap +append "%[filename:fn]_x2.png" – merged logo_x2.png has been created
In .cmd file

Code: Select all

magick logo.png -set filename:fn "%t" rose: +swap +append "%[filename:fn]_x3.png" - magick: MissingArgument `-set' at CLI arg 2 @ fatal/magick-cli.c/ProcessCommandOptions/447
CMD opened in folder or cd to folder

Code: Select all

magick logo.png -set filename:fn "%t" rose: +swap +append "%[filename:fn]_x3.png" - %[filename zero bytes output
This works in my case:

Code: Select all

magick test\*001*.png test\*002*.png -set filename:fn "%t" +swap +append "merged\%[filename:fn].png"
Not sure what the problem with .cmd/.bat behavior, but directly opened console solved everything. Thank you, fmw42, for your time and help.
Post Reply