0

Original Images & Desired Outcome

I have a batch of PNG images which need the same automated image processing:

  • Middle part (red) shall get eliminated entirely and its void filled from above/below
  • Top (blue) and middle part (red) always have the same height
  • The bottom part (green) may vary in height

Original and Desired Outcome

How do I achieve this in an image editor with macro/scripting capabilities?

I came up with the following possible procedures

  • Sorted from most desired with fewest processing steps,
  • To least desired with most processing steps, but if not possible otherwise, fine with it too.

Approach 1: Eliminate undesired portion and void gets filled by neighboring areas

Eliminate undesired portion and void gets filled by neighboring areas

Approach 2: Move desired part so that it covers undesired part entirely and then crop to be without void

Move desired part so that it covers undesired part entirely and then crop to be without void

Approach 3: Move desired part over undesired but larger part - Then crop remainder and void

Move desired part over undesired but larger part. Then crop remainder and void.

12
  • Hi. Welcome to GDSE. I don't think this would work in Photoshop with an Action and Batch operation. The problem is that the green part would vary, and the height of the result would be different each time. Actions can only repeat the exact same steps over and over. Photoshop has no decision making capabilities based on content. It doesn't know anything about an image, it's just a dumb machine. What you want to do would likely require specialist programming/scripting with some kind of image analysis, and that would be off-topic for this site unfortunately.
    – Billy Kerr
    Mar 12 at 13:35
  • 1) Thanks for confirming that in Photoshop only fixed dimensions would work. Well in the case of my batch, I have i.e. 50% with this green height and i.e. 30% with another height, and only 20% with very varying heights. So to cover the 50% + 30% I could just record two different macros, and only do the 20% per hand.
    – porg
    Mar 12 at 13:41
  • 1
    @BillyKerr, just for the record: It is possible to record such an action in Photoshop which will work with a green area in any height. For example using Canvas Size like this.
    – Wolff
    Mar 12 at 15:15
  • 1
    It runs all the steps but it's just too fast to record. Actually you can see all steps in the Actions panel on the left. But I can add an answer explaining the steps.
    – Wolff
    Mar 12 at 16:42
  • 1
    @Wolff - cool, I'd never have though of that. Nice trick.
    – Billy Kerr
    Mar 12 at 17:01

1 Answer 1

2

Here is a recipe for an action for Photoshop. I know you specifically states that you don't have access to Photoshop, but it might be useful to know the method anyway.

We assume that:

  • All your images are flattened (only consists of a Background Layer).
  • The images have different width and height.
  • The top part which you want to keep (in blue) is always 50 px tall.
  • The middle part which you want to cut out (in red) is always 90 px tall.

Method

We start out with an image like this:

Open the Actions panel, create a new Set, create a new Action within that set and start recording.

Perform Image > Canvas Size and set it up like this:

Make sure Relative is unticked. Set the Height field to 50 px and don't touch the Width field. Set the Anchor to center top.

This will crop away everything except for the top part, which you want to keep:

Perform Select > All and Edit > Copy to copy the top part of the image to the clipboard for later use.

Perform File > Revert to revert the image to its initial state:

Again perform Image > Canvas Size but this time with these settings:

Make sure Relative is ticked. Set the Height field to -90 px and leave the Width field at 0. Set the Anchor to center bottom.

This will crop away the top 90 px of the image:

Perform Edit > Paste to paste in the top part of the image we copied to the clipboard earlier:

The pasted content gets its own layer which is selected by default. Hold down Shift and left-click the Background layer to select that as well.

In the Options panel in the top, click the Align top edges button to align the top part with the top of the background:

Finally, perform Layer > Flatten Image to flatten the image and get the final result:

Running the action looks like this:

6
  • 1
    Thanks a lot! Still very much appreciated though being a solution for Photoshop for these reasons: 1) I may get a PS trial just to perform this batch which I need to do (and if satisfied I may subscribe for a bit) 2) Great recipe, as it gives ideas how it could be done with image editors having similar macro/scripting capabilites. Gave it an upvote at least. Would accept an answer which shows how to do this with GIMP or ImageMagick. Thank you very much Wolff!
    – porg
    Mar 12 at 19:00
  • @porg - well you could do the same thing in GIMP manually, but GIMP has no macro/action recording. You can use scripts written in ScriptFu or Python in GIMP, but coding is generally off-topic here, as already explained. Perhaps you could ask on Stack Overflow. Good luck anyway.
    – Billy Kerr
    Mar 13 at 12:00
  • @BillyKerr I narrowed the solution scope to GUI image editors with macro/scripting capabilities and hence accepted your greatly written and illustrated Photoshop answer! Thanks again! 👍 Will try the programmatic/scripting approach now with ImageMagick myself. And at a more suited forum share if I find a solution in a separate Q&A or ask the question again there.
    – porg
    Mar 14 at 11:35
  • Studying the ImageMagick manpages further was eventually worth it. ImageMagick -chop does all what I wanted in a single operation 🙂 Also interesting is its functional counterpart -splice. Wrote a Q&A with command line explanation and illustrations.
    – porg
    Mar 14 at 15:26
  • 1
    @porg, nice! I've dabbled with ImageMagick, but since I never really need it for anything it's just for fun. It's good to know it exists though. Might come in handy one day.
    – Wolff
    Mar 14 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.