Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Batch edit text in hundreds of png images

Community Beginner ,
Jan 04, 2020 Jan 04, 2020

Copy link to clipboard

Copied

I have hundreds of .png images of different sizes, they all show some text against a mostly monochromatic background. I have to change all the text in all these images to another font.

 

I know how to do it individually (use a Mask to cover the original text and add a new Type object), but I have hundreds of these pictures that need to be edited. Is there anything, a script, an automation process, or just a simpler way that can make this task even a little bit easier? Every little thing counts.

 

One problem is that photoshop does not have OCR, but I can maybe find a python script that automatically extracts the text from the png files into txt files using OCR.

 

The next step will probably be using a photoshop script or Actions that creates a new Type object using the text from the txt file, but how do I make sure the Type object has the correct font size and position (similar to that of the original text)? Is there some quick operation that can take care of that?

 

Also, is there a way to make sure the center of a Type object in Photoshop aligns with a specific (X,Y) coordinates?

 

Even if the process cannot be completely automated, any method and suggestion that can make this task a little bit easier is welcome. I am at my wit's end. Thank you in advance!

TOPICS
Actions and scripting

Views

4.3K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jan 04, 2020 Jan 04, 2020

To get the center of a Type object you need to determine the boundaries of each text object - in principle, if we are talking about hundreds of images, not thousands - this can be done manually (in batch cycle with action). Convert PNG to a format with layers, create a new layer with a solid fill over the text - then use the borders of this layer as a container for text (app.activeDocument.activeLayer.bounds)

 

If the text is contrasting and can be easily separated from the background with selecti

...

Votes

Translate
Adobe
Community Expert ,
Jan 04, 2020 Jan 04, 2020

Copy link to clipboard

Copied

Png files have a raster image layer there is no text layer the you can change. You will not be able to remove the text from the image for you do not have the image content the text covers.  You need the layered document the png files were saved from.

JJMack

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2020 Jan 23, 2020

Copy link to clipboard

Copied

I do not have the layered document. If I had them, it would be so much easier. But thank you all the same.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jan 04, 2020 Jan 04, 2020

Copy link to clipboard

Copied

To get the center of a Type object you need to determine the boundaries of each text object - in principle, if we are talking about hundreds of images, not thousands - this can be done manually (in batch cycle with action). Convert PNG to a format with layers, create a new layer with a solid fill over the text - then use the borders of this layer as a container for text (app.activeDocument.activeLayer.bounds)

 

If the text is contrasting and can be easily separated from the background with selection tools, you can use the bounds of the resulting selection as the container coordinates for the text object (app.activeDocument.selection.bounds). 2020-01-04_17-25-43.pngexpand image

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2020 Jan 23, 2020

Copy link to clipboard

Copied

Thank you! I ended up writing a script that did this. It worked pretty well for many of the simpler images. It requires some manual operation when dealing with complex images that not only contain text, but also icons and other shapes. For those I had to manually select the part that contains the text. But for simple images it works like a charm!

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2020 Jan 23, 2020

Copy link to clipboard

Copied

LATEST

Also, in case anyone's wondering, or having similar problems, what I ended up doing was like this: (Most of these steps can be automated using Action with a few scripts thrown in)

 

1. Magic wand select a background pixel (like pixel (3,3)) and invert selection.

(Optional for complex images) Intersect-select the part that contains text. Before you start, divide images into different folders based on their layout. Simple images that only contain text (or text in a rectangle with fancy borders) can be completely automated. Images with similar layout can also be automated (for example, if the text is all underneath an icon or something. I can use a script to intersect-select the bottom 20% (or bottom 30 px, etc.) of the image height to get the text selection).

 

2. Use the bounds of the resulting selection as the container coordinates for the text object. Crop image to selection and export as png to a folder for optimal OCR results. Undo last action,  Layer via cut, rename new layer "text" (or something consistent, for easier automation). Save as .psd file.

 

3. Use OCR software (I used Tesseract OCR combined with Windows Powershell to loop through all images in a folder) to turn the png you exported in Step 2 into .txt files of the same name.

 

4. Write script that gets the activeDocument name and looks for a txt file with the same name in the same folder, copy txt file content to a newly created text layer. Resize text layer according to the width of the layer named "text" in the psd file. Position it like the "text" layer. Create rectangle (positioned like the "text" layer) filled with solid color taken from a color sampler taken at a background pixel. Save and export.

 

The tricky thing is to get the text color right. Any ideas?

Maybe like get the second most dominant color in the image as text color?

Fortunately the text mostly alternates between five or six fixed colors, but still...

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2020 Jan 04, 2020

Copy link to clipboard

Copied

Is the text all the same color and different from any color in your images? I was thinking you could create a script using color range to select the text, then mask it it out. For a new text layer, you can create the text, get the bounds of the text layer, then center it. 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2020 Jan 23, 2020

Copy link to clipboard

Copied

Thank you! I ended up writing a script just like you described.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2020 Jan 04, 2020

Copy link to clipboard

Copied

Even if you can perfectly select the text how are you going to remove the old text. Content aware fill HE HE

Capture.jpgexpand image

Mask it out what good is that

image.pngexpand image

 

JJMack

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2020 Jan 23, 2020

Copy link to clipboard

Copied

Yes, only a few images are like this. Most of them are against a monocolor or gradient background, which are easier to edit. Thank you for the reply!

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 04, 2020 Jan 04, 2020

Copy link to clipboard

Copied

Find the original PSD files to edit. Or, I'd recreate them rather than edit.

This time, save the PSD's. This is easily scriptable with original text layers.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 23, 2020 Jan 23, 2020

Copy link to clipboard

Copied

Unfortunately I do not have the original PSD files. My boss gave me these images to edit and he said there was no original PSD files. But thank you all the same.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines