Page 1 of 1
Passing many draw points from the command line
Posted: 2018-03-18T13:23:10-07:00
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
Re: Passing many draw points from the command line
Posted: 2018-03-18T13:36:14-07:00
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
Re: Passing many draw points from the command line
Posted: 2018-03-18T13:51:18-07:00
by pneumatic
Thanks!
Re: Passing many draw points from the command line
Posted: 2018-03-18T14:33:13-07:00
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:
Re: Passing many draw points from the command line
Posted: 2018-03-18T14:53:50-07:00
by fmw42
That is correct.
Re: Passing many draw points from the command line
Posted: 2018-04-10T03:55:29-07:00
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:
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
Re: Passing many draw points from the command line
Posted: 2018-04-10T06:56:38-07:00
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.
Re: Passing many draw points from the command line
Posted: 2018-04-10T09:44:05-07:00
by fmw42
I recommend just using +write.
Also you can use +write for the last image if you replace the final +delete with null:
Re: Passing many draw points from the command line
Posted: 2018-04-10T20:32:32-07:00
by pneumatic
Brilliant, thank you.