Gimp-Forum.net

Full Version: How to pad an image with extra transparent border
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

I am back with a continuation of my project from my last post. I have 60 images that start at 420x37 and decrease in length by 7 pixels per image like so

[attachment=11037]
[attachment=11038]
...
[attachment=11039]

What I need to do is make all of the images back to 420x37 by putting a transparent edge on the left side like so
[attachment=11040]

I am on the right track using canvas resize with an offset to move the image to the right. Everything looks fine in Gimp but when I try to flatten the image so that I can save the new file I get an error.

Also is there a way to automate the process for all 60 images?

Thanks for helping out a newbie!
1) what error?
2) yes, canvas resize is the way. You can use the widget in the dialog to drag the thumbnail of current image to the edge of the new canvas (no need for to compute an offset then). And don't forget to check the Resize all layers option.
3) As I said in a previous post, use File > Open as layers to open all you images as layers in a single Gimp image. So the shift/pad in a single operation.
4) There are scripts to export the individual layers (for instance my own ofn-export-layers).

But since you are a programmer, maybe you can do everything with ImageMagick in a shell script. For instacne starsyin with this 300x300 image:

[attachment=11041]


convert 300x300.png -resize 400x300 -background none -gravity East -extent 400x300 400x300.png

produces this 400x300 image:

[attachment=11042]
(in fact if you look your whole process is doable with IM).
Another way using a couple of old script-fu (zipped & attached, unzip, put in your User scripts folder)

This is a quick animation of the process and I have resized docks .. to make it more visible. Not 60 layers, only 6 Wink as a demo  https://i.imgur.com/RbObgMd.mp4

1. Load the images as layers Image -> Open As Layers and adjust position as required.
2. Use the Align tool. Rubber band the canvas. Set Relative to Canvas. Click on the Right side icon.
3. Use the Multiple Layer Actions script Layer -> Multiple layer actions. Choose All layers and Action -> Layer to Image size and OK
4. Export the layers to individual files using the export script. Set a destination / order / All layers..
(01-20-2024, 01:51 PM)rich2005 Wrote: [ -> ]3. Use the Multiple Layer Actions script Layer -> Multiple layer actions. Choose All layers and Action -> Layer to Image size and OK
Because you started with "native tool" like the Align(which I love) and to stay more with GIMP "native" options, at step 3, I would Image > Canvas Size... 1 pixel on the width, then just Image > Crop to Content the 60 layers will have their transparent part added at the right size Wink
@PixLab - The great thing about Gimp, always many options.

@rinaldop Although this is a Gimp forum, so this is off topic, but I mentioned before ImageMagick (IM).

For a single image it might be this, looks a bit daunting at first

Code:
magick base.png -gravity center -chop "width"x0 -background none -compose Copy -gravity east -extent 420x37 out.png

where:
-gravity center works in the middle of the image (keeps those rounded ends)
-chop "width"x0 is the size of the strip to remove (7 pixels )
-background none ensures transparency
-compose copy -gravity east pushes to the right side
-extent 420x37 restores the canvas size.

Of course you need to put that in a loop. (Using AIDA64 ? Long time since I used that, so assuming Windows) and I am not much use with Windows batch files, but in linux it looks like this.

https://i.imgur.com/WptLwHo.mp4
WOW You guys are AMAZING! Thank you all so much!

What Aida64 will do is display the image associated with the sensor reading. For example if I am using the program to display FPS when the FPS is 0 then image-0.png is displayed, when FPS is 1 then image-1.png is displayed until at what is set for max FPS (for example 60) then image-60.png is displayed.

Since you all should me how to automate the process I am going to try 420 frames!
(01-20-2024, 01:51 PM)rich2005 Wrote: [ -> ]Another way using a couple of old script-fu (zipped & attached, unzip, put in your User scripts folder)

This is a quick animation of the process and I have resized docks .. to make it more visible. Not 60 layers, only 6 Wink as a demo  https://i.imgur.com/RbObgMd.mp4

1. Load the images as layers Image -> Open As Layers and adjust position as required.
2. Use the Align tool. Rubber band the canvas. Set Relative to Canvas. Click on the Right side icon.
3. Use the Multiple Layer Actions script Layer -> Multiple layer actions. Choose All layers and Action -> Layer to Image size and OK
4. Export the layers to individual files using the export script. Set a destination / order / All layers..

Normally I hate asking for help and prefer to figure things out on my own because I feel that it is an imposition on others to do my work for me but I want to finish this project for a friend and I have already been working on it for 2 weeks.

Can you show me how to take the original 420 object and shrink it down by 1 pixel each time and pad the open space with a transparent background producing 420 images? Then I can reverse them with this technique.

This is my ultimate goal, 420 times 
[attachment=11049]
(01-21-2024, 04:25 PM)rinaldop Wrote: [ -> ]Can you show me how to take the original 420 object and shrink it down by 1 pixel each time and pad the open space with a transparent background producing 420 images? Then I can reverse them with this technique.

This is my ultimate goal, 420 times 

I have run out of "easy" ideas for Gimp. (needs an expert )

A little modified plugin attached, duplicate-shift.py (zipped, unzip and put in your User plug-ins folder)
It registers in the Tools menu as dupshift
Apply it and it makes a duplicate layer. 
Then offsets from the left by a pixel, the same as Layer -> Transform -> Offset 
It keeps transparency and the canvas size.

420 layers ??? You will need to repeat the plugin another 419 time Wink ctrl-F repeats the last used.  Just keep tapping away, might take 10 minutes.  I did the attached .xcf.gz while watching the TV.

Snags: Since it is an offset you truncate the right side and lose that little end bevel.
(01-21-2024, 08:10 PM)rich2005 Wrote: [ -> ]...
Hello again rich,

I don't want you to think that I forgot about your help! I finally finished the project and my friend loves it!

Thanks for all the help!