1

Don't be confused by the title, my question is not overly complicated:

I want move a section of an image to another place inside the image, but in batch (6000 images). Specifically, I want to move the horizontal bar at the top to the bottom of the image.

IMHO, this can be done in three ways:

  • a. Selecting the horizontal section and then cutting and pasting it, or
  • b. Selecting the horizontal section, then dragging and dropping it elsewhere, i.e. the bottom of the picture.
  • c. Split each picture into two pictures and then combine them as "Layers", that too, is a bit steep. Yes, I can do that with some software, however, I wanna do that to 6000 images, so, a batch process.

I don't mind if the section is just copied or moved. I can easily crop the old section out.

I tried out a couple of image editors, but so far, none of them could do what I wanted. Pretty much all of them can move the horizontal bar to the bottom, but not in batch. GIMP came the closest, but I don't know how to record a macro in/for GIMP, nor how to do it all in a macro.

What I've done so far was:

  • read up on Python and Script-Fu in GIMP, but that's a bit over my head, as I'm not a programmer. (I did manage to add keystrokes to the paste-into-selection function, so a solution would be {1} select, Ctrl-C, move, Ctrl-Shift-B)
  • try some image editors, but they either cannot do batch, OR they can, but they don't have a cutting and pasting functions, let alone dragging and dropping.

I am not wedded to GIMP, so if you have another solution, please tell me. I only mention it because it seems to be only one which has a macro capabilities. But I haven't found them in Gimp, as of yet.

Ideally, a command line solution would be to either record or write a script, and then have the following command:

C:\>GIMPDir\gimp move-pic-script.scr *.jpg 

... where the script would contain the following: open image, select area, copy area, move to bottom, paste, save and close image.

If it's at all possible, and all things being equal, I'd prefer a freeware solution. Thanks.

EDIT: The images are 352 by 276 pixels, a horizontal bar of 352 by 36 pixels needs to move to a bottom section of again, 352 by 36. OS is Windows 10

EDIT 2: I found this commmand on stack overflow

(gimp-image-select-rectangle image operation x y width height)

So, I guess that in my case

(gimp-image-select-rectangle *.jpg operation 0 0 352 36)

could be the start of a script I can use... however, I don't know what "operation" in the above line means. Other unknows are the commands for CopyTheSelection, for MoveTheSelection and for PasteIntoSelection and for saving and closing the file.

EDIT 3 to add information the Bing AI gave me:

Yes, I 'cheated' and asked the Bing AI the following:

Can you write me a script in Script-Fu for GIMP which performs the following steps:
Step 1, selecting a rectangle within an image.
Step 2, copying that selection to the clipboard. Step 3, pasting that selection to another area within the same image. Step 4, save the altered image?

Its answer was .... Searching for: Script-Fu GIMP script selecting a rectangle within an image Script-Fu GIMP script copying selection to clipboard Script-Fu GIMP script pasting selection to another area within the same image Script-Fu GIMP script saving altered image

Certainly! Here’s a script in Script-Fu for GIMP that performs the steps you mentioned:

    (define (my-script-fu-script image drawable)
      (let* ((x 100) ; x-coordinate of the top-left corner of the rectangle
             (y 100) ; y-coordinate of the top-left corner of the rectangle
             (width 200) ; width of the rectangle
             (height 150) ; height of the rectangle
             (selection-channel (car (gimp-image-get-selection image))))
        ; Step 1: Selecting a rectangle within an image
        (gimp-image-select-rectangle image CHANNEL-OP-REPLACE x y width height)
        
    ; Step 2: Copying that selection to the clipboard
    (gimp-edit-copy drawable)
    
    ; Step 3: Pasting that selection to another area within the same image
    (gimp-edit-paste drawable TRUE)
    
    ; Step 4: Save the altered image
    (gimp-file-save RUN-NONINTERACTIVE image drawable "path/to/save/your/altered/image.png" "path/to/save/your/altered/image.png")
    
    ; Clean up the selection channel
    (gimp-image-remove-channel image selection-channel)))

; Register the script with GIMP
(script-fu-register "my-script-fu-script" ; Name of the script
                    "<Image>/Filters/My Scripts/My Script-Fu Script" ; Menu location for the script
                    "Description of my Script-Fu script" ; Description of the script
                    "Your Name" ; Author name
                    "Copyright information" ; Copyright information
                    "Date" ; Date of creation/modification
                    "" ; Menu label for the script
                    SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0)

; Run the script by going to Filters > My Scripts > My Script-Fu Script in GIMP.

I still have questions regarding how to get the syntax of the path right etc. , but I suppose this helps.... ;-)

4
  • "I want to move the horizontal bar at the top to the bottom." – What is the height of the bar? Is it constant for all the 6000 images? Or is it a constant percentage of the total height (that can vary from image to image)? Or should software detect the height of the bar for each image independently? Are all the images of the same resolution? Sep 19, 2023 at 4:26
  • Can you post few images so we can test our solutions on a sample of your actual data? What is your OS? Sep 19, 2023 at 4:28
  • the images are 352 by 276. Sep 19, 2023 at 4:48
  • look at imagemagick
    – Gantendo
    Sep 19, 2023 at 4:58

1 Answer 1

1

This was about a video clip of Utada Hikaru singing the song "Colors". As you can see, the original picture had both supertitles and subtitles, the goal was to move the supertitles below the image, so they would be both subtitles. With GIMP, cutting and pasting the supertitles proved too difficult for my GIMP skill level, which is basically zero.

The solution was method „c.” as mentioned in the question and it involved using XNview for separating the supertitles, and ImageMagick for re-attaching them again.

Specifically:

  • Use any program to extract all frames (7072). I used VirtualDub, menu File|Export|Image sequence. Set compression to uncompressed with Ctrl-p

  • Load all images in XNView (Ctrl-U, Transformation tab, pick „Cutting”, set X, Y, width and height

  • rename all supertitles with to "Name0000-B.jpg" and rename all remainders to "Name000-A.jpg"

  • at the command line of ImageMagick use the following line 7072 times:

    magick convert -append Name0001-A.jpg Name0001-B.jpg Name0001.jpg

    magick convert -append Name0002-A.jpg Name0002-B.jpg Name0002.jpg .

    .

    .

    magick convert -append Name7072-A.jpg Name7072-B.jpg Name7072.jpg

  • The 'trick' is to use the minus append option, not the plus append option. + will append the two pictures side by side, not on top of each other like is the need here.

C'est ça!

This is probably a crude and convoluted solution, the big advantage is, it worked, with free software at that. So there. Even though I found ImageMagick before, I should mention @Gantendo, for also suggesting it.

This was the original image

This was the goal, how the image should look

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .