Gimp-Forum.net
Automate adding text into a PNG - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Older Gimp versions (2.8, 2.6....) (https://www.gimp-forum.net/Forum-Older-Gimp-versions-2-8-2-6)
+--- Thread: Automate adding text into a PNG (/Thread-Automate-adding-text-into-a-PNG)



Automate adding text into a PNG - Joe_Wulf - 10-27-2022

Hello,

I've been tasked to take over a linux-based project.  In that there are two PNG images, and their (source?) XCF files.  Available GIMP version on linux host is 2.08.
There is specific text that must be replaced into these PNG images as the development works towards the next version of the whole project.
Historically the PNG modifications have been done manually.  I'm looking to automate the task, and preferably with BASH (but I can make adjustments).
I have lots of linux SysAdmin, installation, automation and troubleshooting experience.  Until this project I haven't ever used GIMP; I've simply absorbed the existing task.

The process today is to manually copy "PNG1_20220814.xcf" to "PNG1_20221026.xcf" and copy "PNG2_20220814.xcf" to "PNG2_20221026.xcf".
Next I run "gimp PNG1_20221026.xcf"; and manually edit an existing text box (I then do the same thing with PNG2, but its text is in a different place, though the same content).
I use the TEXT tool (block letter "A"), highlight the date/time text and replace it, then I do the same for the verson number.
I then save the new XCF as is, and then Export the image to the same name as a PNG.  This is done for both images; manually.

PNG1/PNG2 text (standard/normal horizontal text):
         Title Line of what it is (unchanging)
         Date and time of the current version in this format:  "20221026@1922"
         New overall version number, in this format:   "MAJ.min.sml".............. examples: MAJ="218" . min="076" . sml="002"

The 'box' this text is in is transparent, the text is some dark shade of Blue for one, and Red for the other.  All of the text is bolded, and using font "Sans 18 px"

I don't know GIMP well enough to know how to describe digitally WHERE these text boxes are, just that I see them when GIMP opens each one up.


I could easily 'delete' the text box, and save a generic image without it, then use that as the source MASTER image forever.
Next, with a simple bash script, I would easily have the correct date/time stamp and proper version number information automatically available from other parts of the project.
I am seeking assistance in how to automate using GIMP, via Linux, in a strictly scripted fashion to automatically open the MASTER image, insert a new text box with the correct 3 lines of information at the specified coordinates, and then simply export the completed image as a PNG with a newly chosen name (as identified in the copy operation earlier).

I believe with some insight into how to automate inserting a 3 line transparent text box, say 20 pixels down from the top edge and 20 pixels in from the left edge, that I could finangle the process to place the text box in the right location with some iterative testing and logical guesswork.  And as long as the insight is also provide on how to open PNG1, do the right text insert for it, then PNG2 and do the right text insert for it, and could save each PNG.... then I'd be much more efficient.

I have done searches throughout out google and youtube, as well as searches against these forums without finding any answer that matched up to what I'm doing.

Thak you, and I appreciate your help.

R,
-Joe Wulf


RE: Automate adding text into a PNG - rich2005 - 10-27-2022

I am no script writer, I am sure there will be one along soon.  
To put this in the scripts section or the 'old Gimp' section ? That is the question. I think old Gimp since there might be limitations.

First, Using Gimp 2.8 but what version of Linux? it can make a difference for the next suggestion.

For a bash script the utility ImageMagick (IM) http://www.imagemagick.org might be more appropriate. There will be a version in your linux repo, probably version 6  If you can get the static compiled version 'magick' working then that is version 7 and gives more options.

Next your .xcf file. Gimp 2.8 is different to Gimp 2.10 If multiple layers then it needs flattening. That can be a problem with IM6 but not IM7.

Quote:...snip...Next, with a simple bash script, I would easily have the correct date/time stamp and proper version number information automatically available from other parts of the project.
I am seeking assistance in how to automate using GIMP, via Linux, in a strictly scripted fashion to automatically open the MASTER image, insert a new text box with the correct 3 lines of information at the specified coordinates, and then simply export the completed image as a PNG with a newly chosen name (as identified in the copy operation earlier)....snip...

As a example what might go in a bash file.

Code:
magick(or convert)  some.xcf -flatten temp.miff
magick(or convert)  temp.miff  -fill white -undercolor '#00770080' -gravity South -pointsize 40 -annotate +0+5 @text.txt newfile.png

and that renders the contents of text.txt at a particular place on newfile.png  IM6 uses convert in place of IM7 magick command.  miff is IM own format, you could use any other supported format.

The IM forum https://github.com/ImageMagick/ImageMagick/discussions is always a good place to ask questions.


RE: Automate adding text into a PNG - Joe_Wulf - 10-27-2022

Rich,

My Linux system is RHEL7.9, fully/lastest patched and kept updated.
I will explore the IMAGEMAGICK 'option', likely just need to yum install it.

I'm ok with 'flattening' the image, which is a concept I only barely understand.
I believe as long as the image is displayed and correctly updated----who cares what other damage is done to it along the way.
(but if I should care about something there, please advise).

I'll look at the rest of what you stated here soon, short on time at the moment.
I'll come back with more questions, but also do what research I can on my own regarding IMAGEMAGICK, too.


Thank you.


RE: Automate adding text into a PNG - rich2005 - 10-28-2022

Quote:...'m ok with 'flattening' the image, which is a concept I only barely understand...

Just an explanation for that. If the Gimp somefile.xcf image has several layers, then an IM command convert somefile.xcf newfile.png will produce a png for each layer. Obviously if the xcf is a single layer, flatten is not required.


RE: Automate adding text into a PNG - Joe_Wulf - 11-08-2022

@Rich, Thank you for the insights, suggestions and help.
Though I putzed around with gimp a bit more.... I found when I changed over to ImageMagick that I could get out exactly what I wanted.
Didn't need, nor try'ed the 'flatten'.  I found and used the source JPG, resized it, added the text annotation(s) desired, automated the process.  Done!
Thank you.  I'm good at this point now.

R,
-Joe