Passing many draw points from the command line

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
pneumatic
Posts: 9
Joined: 2017-08-25T21:35:10-07:00
Authentication code: 1151

Passing many draw points from the command line

Post by pneumatic »

Hello

I would like to generate a 256x256 .png file in which I can discretely set the colour of each pixel in the image. Is there a way to pass in these tens of thousands of -draw points from the command line, without having to call the command line once for each and every pixel I want to draw? I imagine this would have to involve a text file containing the values to be written, otherwise the shell might reach its character limit or something.

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

Re: Passing many draw points from the command line

Post by fmw42 »

See txt: at https://www.imagemagick.org/Usage/files/#txt or sparse-color: at https://www.imagemagick.org/Usage/files/#sparse-color. Create a text file in one of these formats and use that as input to convert.

convert @textfile.txt result.png
pneumatic
Posts: 9
Joined: 2017-08-25T21:35:10-07:00
Authentication code: 1151

Re: Passing many draw points from the command line

Post by pneumatic »

Thanks!
pneumatic
Posts: 9
Joined: 2017-08-25T21:35:10-07:00
Authentication code: 1151

Re: Passing many draw points from the command line

Post by pneumatic »

It's quite easy to use :)

Code: Select all

convert -background black txt:input.txt -filter point -resize 64x64! output.png
input.txt wrote: # ImageMagick pixel enumeration: 2,2,255,rgb
0,0: (255,255,255)
1,0: (0,0,0)
0,1: (0,0,0)
1,1: (255,255,255)
Result:

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

Re: Passing many draw points from the command line

Post by fmw42 »

That is correct.
pneumatic
Posts: 9
Joined: 2017-08-25T21:35:10-07:00
Authentication code: 1151

Re: Passing many draw points from the command line

Post by pneumatic »

Hello again

So it turns out I need to generate multiple image files, and it seems some antivirus software doesn't like it when I call convert.exe multiple times in succession, where it will block some of the instances of convert.exe and in some cases freeze my calling application as well.

Is it possible to get around this issue by sending multiple input text files to convert.exe in one command line argument, so that I only have to run convert.exe once to generate all my image files?

eg. something like

Code: Select all

convert txt:input1.txt output1.png , txt:input2.txt output2.png , txt:input3.txt output3.png ... etc.
It seems like the answer is no based on:
https://www.imagemagick.org/script/command-line-processing.php#anatomy wrote: The ImageMagick command-line consists of
one or more required input filenames.
zero or one output image filenames
But I just need to make sure before I spend the next few weeks rewriting that entire section of my program to avoid the issue with antivirus programs.

Thanks
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Passing many draw points from the command line

Post by GeeMack »

pneumatic wrote: 2018-04-10T03:55:29-07:00Is it possible to get around this issue by sending multiple input text files to convert.exe in one command line argument, so that I only have to run convert.exe once to generate all my image files?

Code: Select all

convert txt:input1.txt output1.png , txt:input2.txt output2.png , txt:input3.txt output3.png ... etc.
There are a couple common methods to read in multiple image files, modify them in particular ways, then output the results as several files. These examples should help you get started...

Code: Select all

convert txt:input1.txt txt:input2.txt txt:input3.txt -resize 64x64! output%03d.png
That reads in all the specified TXT files, runs whatever operations on them, then outputs the results as separate files named like "output001.png", "output002,png", "output003.png", ... etc.

Code: Select all

convert txt:input1.txt -resize 64x64! -write first.png +delete txt:input2.txt -resize 48x48! -write second.png +delete ...
That reads in one TXT file, runs some operations on it, writes the output "first.png", deletes it from the current IM command, reads in another TXT file, modifies it, writes "second.png", deletes it from the current running IM command, and continues. Don't use "-write ..." for writing the last image in the command since IM assumes the last filename will be an output image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Passing many draw points from the command line

Post by fmw42 »

I recommend just using +write.

Also you can use +write for the last image if you replace the final +delete with null:
pneumatic
Posts: 9
Joined: 2017-08-25T21:35:10-07:00
Authentication code: 1151

Re: Passing many draw points from the command line

Post by pneumatic »

Brilliant, thank you.
Post Reply