topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday April 16, 2024, 5:21 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: GIMP script to batch split + rotate TIFF images  (Read 23522 times)

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
GIMP script to batch split + rotate TIFF images
« on: March 12, 2009, 05:15 PM »
I request a GIMP script that will batch split and then rotate TIFF images.

I will make a bunch of scans as TIFF images (two booklet sized pages on each image) that I want transformed like this:
1. split in half, 2. rotated , 3. make one pdf of all the rotated, single page image files

I'm only looking for help with step 1 & 2 here.

I've briefly looked into learning GIMP scripting myself (might come in handy) but chances are someone here already knows scripting for GIMP and can kickstart me on this.   :tellme:

edit: I should add that I my input for this will be one TIFF containing multiple images (not multiple separate TIFF files with one image in each)
« Last Edit: March 12, 2009, 05:26 PM by Nod5 »

Ehtyar

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,237
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #1 on: March 12, 2009, 11:46 PM »
GIMP is not the place for batch image processing. I would recommend you try something like ImageMagick.

Ehtyar.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #2 on: March 13, 2009, 02:13 AM »
Ok, but I got the impression that GIMP scripting would be pretty versatile. I've glanced at ImageMagick (and GraphicsMagick ) before but never gotten around to learn the details (or at least not learned them enough to remember them). So ok, I extend the request to them too so if anyone with experience with them can whip up a script (or rather a long command line string) to do what I'm after in step 1 & 2 then that'd be great. You see this week I have not enough spare time or spare free brain space to myself read manuals for these tools so that's why I'm making a request instead.

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #3 on: March 13, 2009, 03:52 AM »
Perhaps the following will get the ball rolling:


Translated -- how about something like the following?

  • use mogrify to rotate
  • use mogrify with crop or extract to get at one page
  • use mogrify with crop or extract to get at the other page

Perhaps there are other options to mogrify that would be better choices :)

Don't know what platform is relevant here, but if it's Windows, may be the following will be of some use:

http://www.imagemagi....php?f=8&t=12926

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #4 on: March 13, 2009, 05:34 PM »
Great, that got me going a bit! Rotation: done.
mogrify.exe -rotate -90 "___filepath___"
Split in halfs: problems. This gives me one of the two pages on each image. But crops away the other.
mogrify.exe -rotate -90 -crop 100%x50% "___filepath___"
But I can't yet grasp how to target the right half of the image via the geometry option
http://imagemagick.o...cessing.php#geometry

When I've sorted the blanks I think this strategy would work (done in steps via AHK):
1. make two copies of the TIFF
2. on copy1 do -rotate -90 -crop 100%x50%
3. on copy2 do __________ [crop that leaves the right hand half of the image]
4. _______ thus combining them like this: copy1subimage1, copy2subimage1, copy1subimage2, ... (or extract them and name the output in that order)
5. make pdf

edit:
on second thought, rotate upside down, chop , rotate back should do it.
Tried to put it together in AHK but it is not running. Some error in the AHK code I think. Time to sleep, I'll try again tomorrow. Anyone else spotting errors?
FileCopy, %1%, 1.tiff
FileCopy, %1%, 2.tiff

mogpath = C:\test\ImageMagick-6.5.0-0\mogrify.exe

RunWait, %comspec% /c ""%mogpath%" -rotate -90 -chop 50x0`%

"%A_Scriptdir%\1.tif""
RunWait, %comspec% /c ""%mogpath%" -rotate 90 "%A_Scriptdir%\2.tif""
RunWait, %comspec% /c ""%mogpath%" -chop 50x0`%

"%A_Scriptdir%\2.tif""
RunWait, %comspec% /c ""%mogpath%" -rotate 180 "%A_Scriptdir%\2.tif""
« Last Edit: March 13, 2009, 06:01 PM by Nod5 »

Ehtyar

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,237
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #5 on: March 13, 2009, 05:56 PM »
Perhaps if you supplied a sample image we'd be more able to help you with actual command lines.

Ehtyar.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #6 on: March 13, 2009, 06:17 PM »
I'm attaching a mockup file that roughly illustrates the format of the input (I used imagemagick to join two tiffs together... so I'm slowly learning something  :D)
« Last Edit: March 13, 2009, 06:21 PM by Nod5 »

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #7 on: March 13, 2009, 10:48 PM »
Don't know if the following is of any help, but after looking at:

  http://www.imagemagi...e/crop/#crop_percent

I tried the following (with success locally) to get at the right-half of an image:

convert inputimage.extension -gravity east -crop 50%x100% outputimage.extension

FWIW, I noticed a "Offsets in geometry" section in:

  http://imagemagick.o...cessing.php#geometry

and a bit on -gravity at:

  http://imagemagick.o...-options.php#gravity

The following page had some pointers to groups of examples:

  http://www.imagemagick.org/Usage/

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #8 on: March 14, 2009, 05:58 AM »
TIFFRotateSplitMakePDF v090314, http://nod5.dcmember...atesplitmakepdf.html
by Nod5, with help from ewemoa

input: multiimage file.tif with two scanned pages per image (= a bookspread, tilted 90 degrees)
what the script does: rotate 90 degrees, split each image in two (L/R page), output file.pdf with all split images in page order

tiffrotatesplitmakepdf.zip contains .exe , .ahk (source) and md5 hashes. made in Autohotkey. requires: http://www.imagemagick.org/

tiffrotatesplitmakepdf2.png
Thank you ewemoa!  :Thmbsup:

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #9 on: March 14, 2009, 06:32 AM »
Congratulations!  Glad that it's working for you :)

(Thanks to Ehtyar for bringing up ImageMagick -- it's been years since I've used it -- didn't know there was a Windows port!)

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #10 on: March 14, 2009, 06:39 AM »
Yes, thanks to Ehtyar too!

TIFFRotateSplitMakePDF v090315, http://nod5.dcmember...atesplitmakepdf.html
v090315: ctrl+drop to skip rotate
« Last Edit: March 14, 2009, 08:35 AM by Nod5 »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #11 on: March 14, 2009, 06:53 AM »
nice  :up:

Ehtyar

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,237
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #12 on: March 14, 2009, 03:58 PM »
No probs guys. I ran across it when I started using PHP, ImageMagick does a much better job than GD. The way GraphicsMagick talks itself up is interesting, I can't imagine all their claims can be justified as easily as they're spoken.

Nice job Nod5.

Ehtyar.

davisjt1977

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 2
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #13 on: March 18, 2009, 01:28 AM »
Just starting.
This script is exactly what I need.
Have downloaded & installed AHK & ImageMagick.
But get error that I have not been able to resolve.
ImageMagick directory not found. Set it in TIFFRotateSplitMakePDF.ini
But I have edited this file w/ complete path.
Pls help
thanks

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #14 on: March 19, 2009, 05:19 PM »
Welcome to DC davisjt1977!
The default ini is a bit confusing - you have to remove the comment character ( ; ) in it. Check if you've done that. So this won't work:
;imagemagickdirectory=C:\program files\ImageMagick-6.5.0-0
this works:
imagemagickdirectory=C:\program files\ImageMagick-6.5.0-0

edit: I've now updated the program so that the comment character from now on never gets added to the ini:
http://nod5.dcmember...atesplitmakepdf.html
v090319 ini bugfix
« Last Edit: March 19, 2009, 05:26 PM by Nod5 »

davisjt1977

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 2
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #15 on: April 23, 2009, 09:44 AM »
Thanks
Got it working
This is a fantastic tool & I have customized it to my situation.
 :-*

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #16 on: April 24, 2009, 03:21 AM »
Cool! If you think any customization you add might be useful to others too then just post the code and I'll see if I can add it to the program. :Thmbsup:

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: GIMP script to batch split + rotate TIFF images
« Reply #17 on: September 01, 2011, 10:10 PM »
FWIW, I recently had occasion to reuse the splitting functionality described earlier in this topic:

convert inputimage.extension -gravity east -crop 50%x100% outputimage.extension

To get at the other half, I used:

convert inputimage.extension -gravity west -crop 50%x100% outputimage.extension

Using the +repage option seemed to give better results as well:

convert inputimage.extension -gravity east -crop 50%x100% +repage outputimage.extension
convert inputimage.extension -gravity west -crop 50%x100% +repage outputimage.extension

FWIW, it may be that +repage is only of relevance to one of the two invocations.

This was in the context of transforming an existing PDF somewhat similar in format to the TIFF described.  The original PDF in this case had side-by-side pages (instead of one above another) on each page (so no rotation required).  Perhaps the original program can be modified to operate on such PDFs :)
« Last Edit: September 01, 2011, 10:14 PM by ewemoa »