Can GIMP split an image into multiple images?

20

5

I've been scanning a lot of photos recently, more than one at a time. I now have multiple jpegs, each containing multiple photos.

Can I, using GIMP , "split" a jpg into 3 smaller files ?

What I used to do is : copy the jpg 3 times, and crop a different picture in each copy.

There must be an easier way to do this !

EDIT : Is there a plugin that can do that ? I've looked around, but only found plugins that "cut" an image into pieces of equal size.

Manu

Posted 2009-08-08T20:38:43.517

Reputation: 2 764

can you post an example picture structure? What I'm looking for is if the pictures are separated by blank space or butted up nxt to each other... – James Mertz – 2010-10-25T16:31:04.040

Answers

21

ImageMagick. It's a command-line tool but amazingly powerful and flexible so worth the effort to learn it. For example:

convert -extract 1024x1024+0+0 original.png target.png

Where:

  • 1024x1024 is the width and height of the required crop
  • +0+0 are x and y offsets into the original image

You can stick dozens of these commands into a .cmd file and run them effortlessly.

Look at the ImageMagick documentation to see there are thousands of options to these commands. A very powerful tool and open source too!

Zond

Posted 2009-08-08T20:38:43.517

Reputation: 226

1How is ImageMagick related to Gimp? – Milche Patern – 2019-05-16T04:40:37.763

15

You can do it like this:

  • Rectangle select an image
  • Edit -> Copy
  • Edit -> Paste as -> New Image

Michael Borgwardt

Posted 2009-08-08T20:38:43.517

Reputation: 3 047

6

You can divide an image in GIMP in a row-column way with guide rows and the guillotine (paper cutter) tool. From GIMP User Manual:

In addition to the image grid, GIMP also gives you a more flexible type of positioning aid: guides. These are horizontal or vertical lines you can temporarily display on an image while you are working on it.

To create a guide, simply click on one of the rulers in the image window and pull out a guide, while holding the mouse button pressed. The guide is then displayed as a blue, dashed line, which follows the pointer. As soon as you create a guide, the “Move” tool is activated and the mouse pointer changes to the Move icon.

The Guillotine command slices up the current image, based on the image's guides. It cuts the image along each guide, similar to slicing documents in an office with a guillotine (paper cutter) and creates new images out of the pieces. You can access this command from the image menubar through Image -> Transform -> Guillotine.

Milche Patern

Posted 2009-08-08T20:38:43.517

Reputation: 319

thanks this works well for my film strips. i do a zealous crop first, to make the guides easier quicker to lay – austin – 2019-03-22T23:18:35.700

6

Michael's Paste as -> New Image works, but I generally use Cut rather than Copy so I don't duplicate content.

Bob Weber

Posted 2009-08-08T20:38:43.517

Reputation: 358

5

I've been using the Divide Scanned Images plug-in which works well.

UPDATE: https://github.com/FrancoisMalan/DivideScannedImages

Raymond

Posted 2009-08-08T20:38:43.517

Reputation: 2 101

5

In order to make it quickly you can use:

Ctrl + D to duplicate the Image
Shift + C to crop the images
Ctrl + S to save

nekrum

Posted 2009-08-08T20:38:43.517

Reputation: 61

2

I wrote a simple Gimp plugin to save the current selection as a JPG (fixed quality).

This requires you to manually select each photograph. Output file names are auto-generated.

Get it/modify on GitHub

Screenshot

Input vs output

Andy Joiner

Posted 2009-08-08T20:38:43.517

Reputation: 363

1

I have made a script based on the answer from Zond. It will tile your image file according with the user input parameters. The script is as follows:

# Usage:
#
# sh crop.sh <tileset_image_file> <tileset_image_width> <tileset_image_height> <tile_size_X> <tile_size_y>
#
# Example:
#   sh crop.sh tileset01.png 128 192 32 32
#
# - Will generate 24 tiles of 32x32 named tile1.png, tile2.png, ..., tile24.png
#

# Your tileset file. I've tested with a png file.
origin=$1

# Control variable. Used to name each tile.
counter=0

# Location of the tool that we are using to extract the files. I had to create a shortcut of the tool in the same folder as the script.
program=convert.exe

# The size of the tile (32x32)
tile_size_x=$4
tile_size_y=$5

# Number of rows (horizontal) in the tileset.
rows=$2
let rows/=tile_size_x

# Number of columns (vertical) in the tileset.
columns=$3
let columns/=tile_size_y

# Tile name prefix.
prefix=tile

# Tile name sufix.
sufix=.png

echo Extracting $((rows * $columns)) tiles...

for i in $(seq 0 $((columns - 1))); do

    for j in $(seq 0 $((rows - 1))); do

        # Calculate next cut offset.
        offset_y=$((i * tile_size_y))
        offset_x=$((j * tile_size_x))

        # Update naming variable.
        counter=$((counter + 1))

        tile_name=$prefix$counter$sufix

        echo $program -extract $tile_size"x"$tile_size"+"$offset_x"+"$offset_y $origin $tile_name
        $program -extract $tile_size_x"x"$tile_size_y"+"$offset_x"+"$offset_y $origin $tile_name
    done
done
echo Done!

The script works with "sh" and the "convert" tool from ImageMagick. I'm not sure if the windows cmd provides sh in a native way, in this case one can take a look at this topic to get sh working. Furthermore, the ImageMagick must be installed in the system and a shortcut for the convert tool in the same folder in which the script will run.

  • I've tested only with png images. Hope it helps.

Vitor

Posted 2009-08-08T20:38:43.517

Reputation: 11

0

Vitor script for linux with sh. I only had to change three lines.

#!/usr/bin/env sh
# Usage:
# sh crop.sh <tileset_image_file> <tileset_image_width> <tileset_image_height> <tile_size_X> <tile_size_y>
#
# Example:
#   sh crop.sh tileset01.png 128 192 32 32
#
# - Will generate 24 tiles of 32x32 named tile1.png, tile2.png, ..., tile24.png
#

# Your tileset file. I've tested with a png file.
origin=$1

# Control variable. Used to name each tile.
counter=0

# Location of the tool that we are using to extract the files. I had to create a shortcut of the tool in the same folder as the script.
program=convert

# The size of the tile (32x32)
tile_size_x=$4
tile_size_y=$5

# Number of rows (horizontal) in the tileset.
rows=$2
rows=$((rows / $tile_size_x))

# Number of columns (vertical) in the tileset.
columns=$3
columns=$((columns / $tile_size_y))

# Tile name prefix.
prefix=tile

# Tile name sufix.
sufix=.png

echo Extracting $((rows * $columns)) tiles...

for i in $(seq 0 $((columns - 1))); do

    for j in $(seq 0 $((rows - 1))); do

        # Calculate next cut offset.
        offset_y=$((i * tile_size_y))
        offset_x=$((j * tile_size_x))

        # Update naming variable.
        counter=$((counter + 1))

        tile_name=$prefix$counter$sufix

        echo $program -extract $tile_size"x"$tile_size"+"$offset_x"+"$offset_y $origin $tile_name
        $program -extract $tile_size_x"x"$tile_size_y"+"$offset_x"+"$offset_y $origin $tile_name
    done
done
echo Done!

Jean

Posted 2009-08-08T20:38:43.517

Reputation: 1

0

Here is another: Split a single image into four. The values have to be put in manually into the script below, depending on how large your original image is. Use the ImageMagick tool "identify" or the "file" tool to check the original image's width and height.

See command line options for '-extract' to see how a 'geometry' is specified.

#!/bin/bash

ORIGINAL=Integration_Tree.png

NEW_WIDTH=2598   # 1/2 of the original width
NEW_HEIGHT=1905  # 1/2 of the original height

NEW_SIZE="${NEW_WIDTH}x${NEW_HEIGHT}"
POS_IMG0="0+0"
POS_IMG1="${NEW_WIDTH}+0"
POS_IMG2="0+${NEW_HEIGHT}"
POS_IMG3="${NEW_WIDTH}+${NEW_HEIGHT}"

for X in 0 1 2 3; do
   VAR="POS_IMG${X}"
   NEW_GEOMETRY="${NEW_SIZE}+${!VAR}" # cunning use of bash variable indirection
   CMD="convert -extract ${NEW_GEOMETRY} \"${ORIGINAL}\" \"out${X}.png\""
   echo $CMD
   convert -extract ${NEW_GEOMETRY} "${ORIGINAL}" "out${X}.png"
   if [[ $? != 0 ]]; then
      echo "Some error occurred" >&2
      exit 1
   fi
done

David Tonhofer

Posted 2009-08-08T20:38:43.517

Reputation: 920