It is currently Sun Sep 21, 2014 2:07 pm


Latest GIMP Scripts & Plug-ins

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Need help creating a script - import text and images into template
PostPosted: Thu Apr 03, 2014 8:48 pm  (#1) 
Offline
GimpChat Member

Joined: Apr 03, 2014
Posts: 7
Hello! I am looking for help automating GIMP. We are a non-profit looking to expand our messaging but need help automating our process.

In short: I have a template with 5 Layers reserved for unique content ( I call these dynamic layers). After I populate the layers with images and text I export the image in jpeg for use on the web. Imagine a brochure with the 5 content boxes, each box in my case is a layer (there are additional layers in the image with static content). I change the content boxes to create the various "brochures". 2 layers are images, and 2 are text, the fifth is also an image.

What I would like to do is automate the process because I am in need of a lot of content for messaging purposes that is tailored for particular audience(s).

Some consideration:

1.) Using a text file called left_text.txt, I create messages, one message per line. There will be multiple lines of text. Text Left Layer
2.) Using a text file called right_text.txt, I create messages, one message per line. There will be multiple lines of text. Text Right Layer
3.) In a particular folder: place images to be used in one of the layers called left image.
4.) In a particular folder: place images to be used in one of the layers called right image.
5.) Image Banner - a folder with images used as banner images: place images to be used in the banner layer.
6.) always center images
7.) always us the formatting of the text layers

My though then is to automate the process as follows:

Start a script to:
1.) Pull the first line of text from the left_text.txt file and place it in the corresponding left text layer
2.) Pull the first line of text from the right_text.txt file and place it in the corresponding right text layer
3.) pull a random image from the right image folder and place it into the right image layer
4.) pull a random image from the right image folder and place it into the left image layer
5.) pull a banner image and place it in the banner layer
5.) save the file in xcf format
6.) clear the layers in a designated folder (can be a fixed folder!)
7.) Still using the first line of text in the left_text.txt file Iterate through each line of text in the right_text.txt file until all lines have been processed.
8.) move to the second line of text in the left_text.txt file and repeat the process of placing the text in the formatted text boxes and image boxes for all text lines in the text_right.txt file.

** Special Note: At times there will be no lines of text in the text_right.txt file. In which case skip the placing of text right text but do continue to process image files in image_right layer, image_left layer and banner_layer.

** Special Note: There will generally be more image files then text strings and that is why I am asking that random images be selected. If I change the message and we always start with the first image then the first images would be selected most often...

Once this is complete I should have a wide array of images including all the text information against random images which I can then review and adjust. I will scale images, move text...to perfect the final images but the bulk work of inserting the text and images into created images will be accomplished by the script.


Can anyone help?

Thanks, Rich


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Profile  
 
 Post subject: Re: Need help creating a script - import text and images into template
PostPosted: Thu Apr 03, 2014 10:55 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1274
Location: not from Guildford after all
I could work on this over the weekend, however, some additional information/clarification would be helpful.

From the list describing the automated process:
    3.) Can the same image appear twice for a given line in the right_text.txt file? Note that should unique right images be desired, the number of images in the right_image folder needs to equal or exceed either the number of lines in the left_text.txt file or the product of the number of lines in the left_text.txt file and the number of lines in the right_text.txt file, whichever is greater.
    4.) I assume it is a typo that the left_image is not being pulled from a left_image folder. Please confirm. Can the same image appear twice for a given line in the left_text.txt file? Note that should unique left images be desired, the number of images in the left_image folder needs to equal or exceed the number of lines in the left_text.txt file.
    5.(the first) From "consideration 5" I would assume there is to be a banner_image folder and the banners randomly selected as in 3 and 4. Please confirm. As in the preceding commentary, are these banners to be guaranteed unique? (If unique then the italicized note in my response to 3 applies.)
    5.(the second) How should the saved XCF files be named?
    6.) I do not know what this means. Please clarify.

It would also be helpful to know what the possibilities are for the filenames of the input images; e.g. "*.png", "*.PNG", "*.jpg".

And if you could provide some example files, it would be much appreciated.

_________________
A man who does not read good books has no advantage over a man who cannot read them. -- Mark Twain


Last edited by saulgoode on Thu Apr 03, 2014 11:06 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Need help creating a script - import text and images into template
PostPosted: Thu Apr 03, 2014 11:06 pm  (#3) 
Offline
Global Moderator
User avatar

Joined: Nov 16, 2011
Posts: 3309
Location: Metro Vancouver, BC
CSS Sprites might work for you.
A Gimp script to consider, CSS WebSprites.

_________________
Image
Gimp 2.8.14, Ubuntu 14.04, median user
Gimp Chat Tutorials Index


Top
 Profile  
 
 Post subject: Re: Need help creating a script - import text and images into template
PostPosted: Fri Apr 04, 2014 1:51 pm  (#4) 
Offline
GimpChat Member

Joined: Apr 03, 2014
Posts: 7
Hello saulgoode:

Here are my responses embeded inline with your questions. also, I have attached one of the templates I am using. I have several but they carry the same format and the final product is the same. Which, either I will rename templates to work with your script or you'll be able to offer a way to input a file name to use as the template. If we must use a file name lets pick something easy like bantemp.xcf

Let me add that I an very thankful for your help on this. If you have a paypall or would like a small donation to go someplace please let me know. I am obviously not a rich man or I wouldn't have tried this on my own...that said, this will be something very special for our organization as we will be able to communicate in new and exciting ways.

I could work on this over the weekend, however, some additional information/clarification would be helpful.

From the list describing the automated process:

3.) Can the same image appear twice for a given line in the right_text.txt file?
Note that should unique right images be desired, the number of images in the right_image folder needs to equal or exceed either the number of lines in the left_text.txt file or the product of the number of lines in the left_text.txt file and the number of lines in the right_text.txt file, whichever is greater.

The "text" line in the right_text.txt are marquee texts. There will only be a few of them and it is expected that they will be frequently reused.

So, yes it is inevitable that the same image inserted on the right side repeats the same line of text (on the right side) found in right_text.txt.


4.) I assume it is a typo that the left_image is not being pulled from a left_image folder. Please confirm. Can the same image appear twice for a given line in the left_text.txt file? Note that should unique left images be desired, the number of images in the left_image
folder needs to equal or exceed the number of lines in the left_text.txt file.

A left image should be pulled from the left image folder...

The images in the left side are swatches of color or gradients and will be a minimum number. Hence it is inevitable that the images on the left side will be re-used frequently.


5.(the first) From "consideration 5" I would assume there is to be a banner_image folder and the banners randomly selected as in 3 and 4. Please confirm. As in the preceding commentary, are these banners to be guaranteed unique? (If unique then the italicized note in my response to 3 applies.)

Yes, there will be a banner_iamage folder. There are a limited number of banners and it is inevitable that they will be reused


5.(the second) How should the saved XCF files be named?

Is it possible to allow me to set a folder? Is it possible to allow me to set
a prefix "name" and you add a numerical 4 digit suffix? Something like this: c:{nemaed_folder}\{named_prefix (I will include a dash)-}xxxx.xcf
Final format would look like this" c:\folder\filenamename-xxxx.xcf

6.) I do not know what this means. Please clarify.

Here is what I do: I select the layer I want to place a picture into ( image_right layer for example). Then I open an image I want to paste into this layer (any image.png) When I place the image in this layer it is "floating"...then I position the image within the frame
of the layer (image_right layer) and then I anchor the pasted layer. So good so far...

Noting: when I place the image and it is floating I can position it wherever I want. But anchoring it crops the image to the layer I am pasting into. In a manual mode this is fine because I place the image and move it wherever I want before I anchor it. However: when we automate the process we need to overcome the anchoring aspect because I still want to be able to proof the document and move the image to focus on the area of the image we want to show. THEN MANUALLY anchor it before I export it.

My statement about centering the image was simply intended to place the image in a fixed position so that I could select it and move it.

It would also be helpful to know what the possibilities are for the filenames of the input images; e.g. "*.png", "*.PNG", "*.jpg".

Lets use *.png


And if you could provide some example files, it would be much appreciated.

Here is the xcf I use as my template with images and text populated in the layers


Attachments:
File comment: Gimp image of Shelter The World Template.
STW_Template_Large_Format_001_twitter.xcf [2.56 MiB]
Downloaded 28 times
Top
 Profile  
 
 Post subject: Re: Need help creating a script - import text and images into template
PostPosted: Fri Apr 04, 2014 2:14 pm  (#5) 
Offline
GimpChat Member

Joined: Apr 03, 2014
Posts: 7
Hello saulgoode:

I have another thought I'd like to ask about. Currently, after I edit the template, insert text and images, move things around...I export the image in jpeg format. Later I go back and crop the image x pixels wide and x pixels high from the top left corner...The reason being is we also use the images on LinkedIn, twitter and facebook. That said are you aware of a script that I could run in batch mode to process these cropped images?

By your efforts we'll be able to focus on content and distribution and have a mini production capability...

Thanks again...I look forward to hearing from you soon. Rich


Top
 Profile  
 
 Post subject: Re: Need help creating a script - import text and images into template
PostPosted: Fri Apr 04, 2014 7:30 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1274
Location: not from Guildford after all
Thanks for your clarifications. I have the bulk of the script sussed out, however, I would really appreciate if you could provide me with a zipped file (or a tarball) of the three directories containing some images and .txt files.

My script currently looks for the "left_text.txt" file in the left image folder, and for the "right_text.txt" file in the right image folder. This can be changed if it is unsuitable.

_________________
A man who does not read good books has no advantage over a man who cannot read them. -- Mark Twain


Top
 Profile  
 
 Post subject: Re: Need help creating a script - import text and images into template
PostPosted: Sat Apr 05, 2014 8:16 pm  (#7) 
Offline
GimpChat Member

Joined: Apr 03, 2014
Posts: 7
Hello saulgoode! I attempted to post earlier and thought I'd check for a response...however, it appears I must not have submitted the reply. At any rate, here is the directory structure with images and text. I trust this is what you were looking for.

Rich

oops I see the problem...I missed the message informing me the compressed file was too large...here is a smaller version.


Attachments:
File comment: directory with text and images
STW.zip [4.1 MiB]
Downloaded 31 times
Top
 Profile  
 
 Post subject: Re: Need help creating a script - import text and images into template
PostPosted: Sat Apr 05, 2014 10:53 pm  (#8) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 3332
Location: Australia
Yours is a Noble cause Richg, so I'm pleased that Saulgoode has answered your request (I viewed the files) :bigthup

_________________
Image


Top
 Profile  
 
 Post subject: Re: Need help creating a script - import text and images into template
PostPosted: Sun Apr 06, 2014 10:23 am  (#9) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1274
Location: not from Guildford after all
I have completed a first cut of your script which you can download from here, however, ...

You are going to have to alter your template file a little bit. The script is not able to handle the left and right text layers in their current form. The problem lies with the fact that the on-screen text editor creates different text than that created using the old-style text editor. Whereas a text layer created in the traditional fashion might contain "This is MY House", when created with the onscreen editor it will contain "<markup><span font=\"Sans\"><span size=\"11796\">This is MY House</span></span></markup>". (This latter form used by GIMP is a limited subset of the Pango markup format.)

Unfortunately, the interface has not yet been created for plug-ins to set this type of markup text. There is an interface for my script to read the markup text for a layer; however, this interface is buggy and can not be relied upon for the information I need for this script (for example, the markup for your text layers does not include the name of the font being used).

What you need to do to remedy this is:
  • Double-click on the text_left layer to activate the Text Tool.
  • If the Tool Options dialog is not visible, perform "Windows->Dockable Dialogs->Tool Options" to raise it (the dialog should show the options for the Text Tool).
  • Click on the corresponding (left) text in the image window and then using the DELETE and BACKSPACE keys to remove all of the text.
  • In the tool options dialog, choose your font and font size.
  • In the tool options dialog, check the box labeled "Use editor". A small dialog box should appear somewhere on your screen.
  • Enter your text into this dialog.
Repeat the above steps for the text_right layer and then save your template. [*] In the future, do not use the on-screen editing features for creating/editing the text_left and text_right layers. If you want to change the font or its size, use the settings in the Tool Options dialog.

The script adds the command "Filters->STW->Create Brochures..." which should be run with your template file. The template file should contain your five "dynamic" layers. These layers are identified by their names and thus should be named text_left, text_right, image_left, image_right, and banner_image.

The dialog that appears when you run the command is pretty self-explanatory.
Image
You do, however, need to make sure that the output directory exists before you press OK -- the script is not able to create the directory (yet). There should be an option to create a directory in the file dialog that appears when you choose "Other" from the Output Folder dropdown. The names of the files created will be of the form brochure-0001.xcf, brochure-0002.xcf, brochure-0003.xcf, ... where "brochure-" is the Output Basename specified in the dialog.

The image_left and image_right layers in the output files will have layermasks added to them. This is done so that the entire layer is available (i.e., it is not cropped) and can later be repositioned. When you use the Move Tool to reposition a layer that has an attached layermask, the mask will be moved along with the layer -- we do not want this. So...

I have added a second command "Filters->STW->STW Float Layer" that will turn the layer into a floating selection, allowing you to use the Move Tool to position the layer as you please (while the mask remains in place), anchoring the floated layer when done. The command is also available by right-clicking on the layer's thumbnail preview in the Layers Dialog.

Finally, any of the output brochure files can serve as a template. If an image_ layer has a layermask then the boundaries of the mask determine the framing of the image; if there is no mask then it is the layer itself.

Here is an example of the brochures (scaled down) produced from your example files.
Image

You can download an example output brochure from here (download it using the Original File link in the lower right). Note that I substituted fonts for the dynamic text layers as I did not have the ones you used on my machine.

_________________
A man who does not read good books has no advantage over a man who cannot read them. -- Mark Twain


Top
 Profile  
 
 Post subject: Re: Need help creating a script - import text and images into template
PostPosted: Sun Apr 06, 2014 12:17 pm  (#10) 
Offline
GimpChat Member

Joined: Apr 03, 2014
Posts: 7
Thank you saulgoode! What I do is a labor of love...I've been so fortunate in my life and giving back is the best reward I've ever received!

This was extremely quick! I will begin practicing with the script in a few hours and will post back any questions. In the meantime did you see the post regarding the cropping and saving as jpegs.

So you don't have to scroll here is a summary of what I was hoping to do. Most social media sites have the ability to upload images. The problem is they each unique image size requirements. I would like to define the image size I am interested in by essentially cropping the brochure. The brochure has been crafted to allow for cropping at logical places to fit the image requirements of the social media sites. For example the upper left image and text get cropped for linked in...the upper banner gets cropped for twitter...you get the idea.

Would it b possible to grate a script that

1.) allows me to "set" the x an y offset ( in px) from the upper left corner of an image and save it to a directory?
2.) export for web as jpg
3.) run the script while gimp open or closed...open would allow me to set the offsets without needing to edit the script...either way
4.) naming convention can the the open file name appended with the image size.
5.) since these are all coming from our STW directory we could simply write them back to the same directory with the appended image size : For example: original file name is c:\folder\filenamename-xxxx.xcf exported file name would be c:\folder\filenamename-xxxx-wXl.jpg OR c:\folder\filenamename-xxxx-500X500.jpg or c:\folder\filenamename-xxxx-100X500.jpg

I am hoping this is fairly simple to do...

Also, have you given any though on a donation?

Thanks, Rich


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

* Login  

* Subscribe to Gimp Chat's RSS Feed    * Subscribe to Gimp Chat's Tutorial Feed    * Subscribe to Gimp Chat's G'MIC Feed


Powered by phpBB3 © phpBB Group