Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cut squares from iamge
#1
Hi

Is there a way in GIMP or a plugin, script, ... to extract all the black squares from this image automatically to separate PNG files?
So I need a folder that has all squares (no matter if the square is empty or not) saved as 1.png, 2.png, 3.png, ... from this image
I need step by step instructions because I'm a beginner

My GIMP file is here:

https://www.mediafire.com/view/zh9zdytld...t.xcf/file

Image preview:

https://ibb.co/SvBJGfb

Why can't we attach a file here on the forum (file is under 100kb in zip file)?
Error: Request Entity Too Large

The requested resource does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit.
Reply
#2
The file size attachment limits are 500KB (png / jpeg ...) or 2 MB for a gimp .xcf

Chopping it up might be possible using a set of guides. Attaching an old script that creates guides by number or spacing. I think your image is 150 px squares

   

Then a couple of Ofnuts python plugins from  http://sourceforge.net/projects/gimp-too...s/scripts/
ofn-guillotine-layer (dated 2017-04-30) to chop up into layers and ofn-export-layers (dated 2023-10-24) which does what it says.

The attached file test.xcf.gz as an example has the grid of guides. I had to move the top layer a little to line it up. Then applied guillotine Open it in Gimp and have a look.

Remember to unzip the scrip which goes in your User scripts folder. It registers in Image -> Guides -> Grid
The python plugins go in the plug-ins folder. Unzip and read the help files.


Attached Files
.zip   guides-grid.zip (Size: 1.02 KB / Downloads: 363)
.gz   test.xcf.gz (Size: 206.76 KB / Downloads: 88)
Reply
#3
Hi

Thanks a lot! But is it possible to give me an overview step by step of what you did and in what order (+ settings for everything you used)?
As a beginner I can't figure it out. I never even used a plugin/script. And in addition I have autism and new things are hard to learn for me Blush

I understand the basic idea: each square will become a layer and then each layer is exported.
But I don't know what the guides are/do and why they are needed in combination with the 2 plugins...
Where did you find the script?

The script I find in GIMP after installing but both plugins I don't find!
I copied them to a subfolder (with same name as plugin) in 'GIMP 2\lib\gimp\2.0\plug-ins\'
Why they don't appear in GIMP: I don't have Layer>Guillotine and File>Export>Export ?
Reply
#4
If all the tiles have the same size, the ofn-layer-tiles script is the most direct way to split a layer to individual files.
Reply
#5
Another solution is with G'MIC(*): Filters > G'MIC_Qt, a window opens, go to Arrays & Tiles > Extract Objects, move the white dot to the blue, it will auto select all the things, click OK and all will be on new layers at their respective places.

   

   

(*) If you don't have G'MIC, download, install, then restart GIMP
Patrice
Reply
#6
As ofnuts said his ofn-tiles plugin is very direct, it is a bit picky about image sizes, which have to be multiples of the tile size. Give it a try, you will not learn without trying.

Worth trying the gmic plugin as well.

I am very hands on. This using a grid of guides and the script / plugins mentioned earlier.

https://youtu.be/A3o2OR23Hnw about 8 minutes duration.

 



It does show where to put the script and plugins. Best place is your User profile, for Windows usually:
C:\Users\"yourname"\AppData\Roaming\GIMP\2.10\plug-ins
C:\Users\"yourname"\AppData\Roaming\GIMP\2.10\scripts

Why are your plugins not showing ? You can put in individual folder where the folder name is the same as the plugin minus the extension, so ofn-export-layers.py goes in a folder ofn-export-layers. Hardly worth the effort for a single file. (however it will be required when Gimp 3.0 comes along)

A bit in there about determining the tile size and general hints.
Reply
#7
Great video!! Everything is working. It seems on windows you can only use the user folder.

Additional questions: 

- what are the "border guides" of the script? If I enable it, what happens?

- is it normal it takes a lot of time to write the PNG files?

- do you know if there is also a way to automate the cropping (as seen in minutes 6:00)? So I have a lot of those images with the squares at the exact same positiion, just another thing in the squares (so if it works on this file, it will work on ALL files). Is there a script or plugin that can crop those automatically so that I can apply the method in the video to the cropped result (and I don't have to do the cropping manually each time)

PS: I'll try the other ways too!
Reply
#8
(02-23-2024, 06:12 PM)gimpygirl Wrote: Additional questions: 

- what are the "border guides" of the script?

These are guides that follow the edges of the canvas, can be useful in some circumstances.

Quote:- is it normal it takes a lot of time to write the PNG files?

It can, I am guessing that your full version is more than the 128 separate images. You learn to be patient and go for a coffee (or a beer)

Quote:PS: I'll try the other ways too!

Please do that, Gimp always has more than one way for most things.

Edit: Just seen this - do you know if there is also a way to automate the cropping

Not sure, It should be possible. I cropped after the guillotine on the basis you might want to keep / remove the edge decoration. You can crop right at the start before making the grid of guides. If you did that and make sure the image is a multiple of the tile size, then Ofnuts ofn-layer-tile.py plugin should be faster.
Reply
#9
- I don't know coding but maybe for you/sombody it's easy to adjust this?

https://stackoverflow.com/questions/5811...g-the-gimp

I would like to have an automatic way to remove the "border" around the squares.

- Is there a way I can do the operation you explained in the video (without the manual cropping) on a batch of files (including the script and the 2 plugins)? Or is it only possible file by file manually?
Reply
#10
(02-23-2024, 07:06 PM)gimpygirl Wrote: I would like to have an automatic way to remove the "border" around the squares.

That would have been nice to tell us this from the beginning... With different output comes different method, instead of adding more steps...

Anyway, no script needed for that. If you did give a try to my post #5 using G'MIC with the settings I shown in the screenshot, layers come out already sized without transparent borders AND without blue border ➤ at the same place.

[attachment=11276]

If you want the layers at the canvas size ➤ Just go to Image > Canvas Size..., increase the width by 1 pixel, fill with transparent...

   

Then go to Image > Crop to Content and all your layers are the size of the canvas

Then use a script to export all layers as images (Ofnuts has one for example),  done
Patrice
Reply


Forum Jump: