scripting / processing multiple images

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
00bins
Posts: 10
Joined: 2019-04-18T15:11:07-07:00
Authentication code: 1152

scripting / processing multiple images

Post by 00bins »

Hi

I have 1000's of images to convert. I already posted about this here (viewtopic.php?f=2&t=35870#p165168), and then found that im has a -script option. I can't seem to find much help on that, nor even search for that term in this forum.

I've experimented with a script file and it doesn't do what I expect.

output from --version is this
Version: ImageMagick 7.0.8-40 Q16 x64 2019-04-13 http://www.imagemagick.org

invoking magick like this

Code: Select all

magick.exe -script test.txt
with test.txt containing this

Code: Select all

-read c:/dev/projects/game/data/ui/ui/bgWood.bmp -resize 1024x1024! -type truecolor -write c:/dev/projects/game/tmp/pc/ui/ui/bgWood.bmp
-read c:/dev/projects/game/data/ui/ui/Black.bmp -resize 128x128! -type truecolor -write c:/dev/projects/trunk//tmp/pc/ui/ui/Black.bmp
results in 2 files called
Black-0.bmp
Black-1.bmp

Black-0 contains the texture from bgWood.bmp
Black-1 contains the texture from Black.bmp

does anyone know what the right way to convert multiple images is please, and does anyone have any examples of using the -script option?

thanks
Rob
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: scripting / processing multiple images

Post by snibgo »

00bins wrote:... with test.txt containing this ...
On the other thread, I showed a script with "+delete" after each file. If you don't have that, the second "-write" will write two files, the third "-write" will write three files, and so on.

A v7 script file can contain any IM options except for "-script" (so scripts can't call other scripts). The script doesn't return processing to the command line, so it should be the final operation on the command line. The script is interpreted by IM, not by the shell (bash, Windows or whatever), so don't use shell rules for line continuation or escaping characters.

I have examples of "-script" on Filling holes and other pages.
snibgo's IM pages: im.snibgo.com
00bins
Posts: 10
Joined: 2019-04-18T15:11:07-07:00
Authentication code: 1152

Re: scripting / processing multiple images

Post by 00bins »

Thanks

I'm afk but intrigued to know which file +delete will delete - I don't want to delete either my source file nor the file I've written after the resize operation

cheers
Rob
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: scripting / processing multiple images

Post by snibgo »

IM works on lists of images in memory. Each read adds an image to the list. "+delete" removes the last image from the end of the image. (When there is only one image, this leaves the list empty.) It doesn't delete files. See http://www.imagemagick.org/script/comma ... php#delete
snibgo's IM pages: im.snibgo.com
00bins
Posts: 10
Joined: 2019-04-18T15:11:07-07:00
Authentication code: 1152

Re: scripting / processing multiple images

Post by 00bins »

ok I just got back and tried it and no files were deleted as you say.

I suppose now I should generate both my @list and a -script list and see which is faster

thanks for all the help

Rob
00bins
Posts: 10
Joined: 2019-04-18T15:11:07-07:00
Authentication code: 1152

Re: scripting / processing multiple images

Post by 00bins »

right then I'm back to needing my @list.txt method unless I'm doing something wrong.

My modified code that reads list.txt and feeds each line as argc,argv to magick (convert) takes 22 secs on windows to process 1300 files.

using -script has so far nearly nuked my machine, running out of swap, causing chrome to die and my desktop to go blank. And it still didn't finish processing the files.

Each line is of the form

Code: Select all

Black.bmp -resize 128x128! -type truecolor c:/dev/projects/trunk/game/tmp/pc/ui/ui/Black.bmp +delete
is there anything I'm doing wrong here that would cause im to use loads of memory?

Thanks
Rob
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: scripting / processing multiple images

Post by snibgo »

You have removed the keyword "-write", so IM will read those files instead of writing them. Again, you are building the image list.
snibgo's IM pages: im.snibgo.com
00bins
Posts: 10
Joined: 2019-04-18T15:11:07-07:00
Authentication code: 1152

Re: scripting / processing multiple images

Post by 00bins »

you sir have the patience of a saint - I'd just munged my original @ file and forgotten the -write part.

It did at least complete this time but took about 5 mins - so still doesn't help when there are 1000's of files.

thanks again
Rob
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: scripting / processing multiple images

Post by fmw42 »

For IM 7 scripting, the only information I have is from Anthony's notes. See https://www.imagemagick.org/Usage/bugs/ ... ipting.txt
00bins
Posts: 10
Joined: 2019-04-18T15:11:07-07:00
Authentication code: 1152

Re: scripting / processing multiple images

Post by 00bins »

thanks for that link.

I think I'll probably tidy up my code (e.g. make it handle spaces in filenames, quoting etc..) and see if I can propose it as a patch/pull request. It's not like full on scripting but it does address some of the perf issues that the doc you linked mentions, and which are also mentioned elsewhere.

thanks again
Rob
Post Reply