RSS/Atom feed Twitter
Site is read-only, email is disabled

rotate image script-fu

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

15 of 15 messages available
Toggle history

Please log in to manage your subscriptions.

rotate image script-fu Jason Pearce 17 Jun 04:05
  rotate image script-fu Joel 17 Jun 05:14
   rotate image script-fu Jason Pearce 17 Jun 06:10
    rotate image script-fu Dave Gomez 17 Jun 06:58
     rotate image script-fu Jason Pearce 17 Jun 08:00
    rotate image script-fu Dave Gomez 17 Jun 06:58
    rotate image script-fu Joel 17 Jun 07:37
     rotate image script-fu Jason Pearce 17 Jun 08:03
      rotate image script-fu Joel 17 Jun 10:07
       rotate image script-fu Akkana 17 Jun 19:10
rotate image script-fu Andrei Thomaz 17 Jun 05:08
  rotate image script-fu Joel 19 Jun 02:06
rotate image script-fu Andrei Thomaz 20 Jun 07:25
rotate image script-fu Andrei Thomaz 20 Jun 07:41
  rotate image script-fu Joel 20 Jun 08:52
Jason Pearce
2002-06-17 04:05:15 UTC (almost 22 years ago)

rotate image script-fu

Hi gimpers,
I want to be able to run a script in batch mode, that gets all the images in a directory , rotates them by 270 clockwise and then saves them to the same dirctory . but I am having some trouble getting started . I understand that I just have to call the plugin rotate image. Has anyone written a script like this ? or similar that i could have a look at . thanks in advance
jason

Andrei Thomaz
2002-06-17 05:08:35 UTC (almost 22 years ago)

rotate image script-fu

Hello Jason,

would you can send me the script? I am very interested about using GIMP to make/process animations, so a script that gets all the imagens in a directory, and apply some kind of transformation in them would be very useful for me. And I am still a Script-fu beginner :)

thank you, andrei

From: Jason Pearce
Reply-To: gimp-user@lists.xcf.berkeley.edu To: gimp-user@lists.xcf.berkeley.edu Subject: [Gimp-user] rotate image script-fu Date: Mon, 17 Jun 2002 12:05:15 +1000

Hi gimpers, I want to be able to run a script in batch mode, that gets all the images in a directory , rotates them by 270 clockwise and then saves them to the same dirctory . but I am having some trouble getting started . I understand that I just have to call the plugin rotate image. Has anyone written a script like this ? or similar that i could have a look at . thanks in advance
jason

Joel
2002-06-17 05:14:23 UTC (almost 22 years ago)

rotate image script-fu

Jason,

While this certainly can be done with script-fu, the *easiest* way to rotate all of the images in a directory is with the ImageMagick program, convert. At the command line, go to the directory holding the images, then enter:

for i in *; do convert -rotate 270 $i $i; done

This goes through all of the files in the directory, rotates any image file found by 270 degrees, and over-writes the old file with the new version.

--Joel

Hi gimpers,
I want to be able to run a script in batch mode, that gets all the images in a directory , rotates them by 270 clockwise and then saves them to the same dirctory . but I am having some trouble getting started . I understand that I just have to call the plugin rotate image. Has anyone written a script like this ? or similar that i could have a look at . thanks in advance
jason

Jason Pearce
2002-06-17 06:10:04 UTC (almost 22 years ago)

rotate image script-fu

Hi Joel,
thanks for the tip,
whan i ran your script i recieved the error convert: Missing an image file name. 20 time (there are 20 files in this directory) I wrote it as you sent it to me, is there something i have missed. [jason@localhost narooma_rest]$ for i in *;do convert -rotate 270 $i$i;done convert: Missing an image file name. convert: Missing an image file name. [jason@localhost narooma_rest]$

I am running ImageMagic 5.3.0 thanks again Joel .
When I used winblows it was just a matter of creating an action in Photoshop that i could use over and over.
thats why I thought a script-fu would be good but this looks even easier (if it will work)
jason

On Monday 17 June 2002 13:14, you wrote:

Jason,

While this certainly can be done with script-fu, the *easiest* way to rotate all of the images in a directory is with the ImageMagick program, convert. At the command line, go to the directory holding the images, then enter:

for i in *; do convert -rotate 270 $i $i; done

This goes through all of the files in the directory, rotates any image file found by 270 degrees, and over-writes the old file with the new version.

--Joel

Hi gimpers,
I want to be able to run a script in batch mode, that gets all the images in a directory , rotates them by 270 clockwise and then saves them to the same dirctory . but I am having some trouble getting started . I understand that I just have to call the plugin rotate image. Has anyone written a script like this ? or similar that i could have a look at . thanks in advance
jason

Dave Gomez
2002-06-17 06:58:10 UTC (almost 22 years ago)

rotate image script-fu

Try $1 instead of i.

On 6/16/02 9:10 PM, "Jason Pearce" wrote:

Hi Joel,
thanks for the tip,
whan i ran your script i recieved the error convert: Missing an image file name. 20 time (there are 20 files in this directory) I wrote it as you sent it to me, is there something i have missed. [jason@localhost narooma_rest]$ for i in *;do convert -rotate 270 $i$i;done convert: Missing an image file name. convert: Missing an image file name. [jason@localhost narooma_rest]$

I am running ImageMagic 5.3.0 thanks again Joel .
When I used winblows it was just a matter of creating an action in Photoshop that i could use over and over.
thats why I thought a script-fu would be good but this looks even easier (if it will work)
jason

On Monday 17 June 2002 13:14, you wrote:

Jason,

While this certainly can be done with script-fu, the *easiest* way to rotate all of the images in a directory is with the ImageMagick program, convert. At the command line, go to the directory holding the images, then enter:

for i in *; do convert -rotate 270 $i $i; done

This goes through all of the files in the directory, rotates any image file found by 270 degrees, and over-writes the old file with the new version.

--Joel

Hi gimpers,
I want to be able to run a script in batch mode, that gets all the images in a directory , rotates them by 270 clockwise and then saves them to the same dirctory . but I am having some trouble getting started . I understand that I just have to call the plugin rotate image. Has anyone written a script like this ? or similar that i could have a look at . thanks in advance
jason

Dave Gomez
2002-06-17 06:58:10 UTC (almost 22 years ago)

rotate image script-fu

Try $1 instead of i.

On 6/16/02 9:10 PM, "Jason Pearce" wrote:

Hi Joel,
thanks for the tip,
whan i ran your script i recieved the error convert: Missing an image file name. 20 time (there are 20 files in this directory) I wrote it as you sent it to me, is there something i have missed. [jason@localhost narooma_rest]$ for i in *;do convert -rotate 270 $i$i;done convert: Missing an image file name. convert: Missing an image file name. [jason@localhost narooma_rest]$

I am running ImageMagic 5.3.0 thanks again Joel .
When I used winblows it was just a matter of creating an action in Photoshop that i could use over and over.
thats why I thought a script-fu would be good but this looks even easier (if it will work)
jason

On Monday 17 June 2002 13:14, you wrote:

Jason,

While this certainly can be done with script-fu, the *easiest* way to rotate all of the images in a directory is with the ImageMagick program, convert. At the command line, go to the directory holding the images, then enter:

for i in *; do convert -rotate 270 $i $i; done

This goes through all of the files in the directory, rotates any image file found by 270 degrees, and over-writes the old file with the new version.

--Joel

Hi gimpers,
I want to be able to run a script in batch mode, that gets all the images in a directory , rotates them by 270 clockwise and then saves them to the same dirctory . but I am having some trouble getting started . I understand that I just have to call the plugin rotate image. Has anyone written a script like this ? or similar that i could have a look at . thanks in advance
jason

Joel
2002-06-17 07:37:36 UTC (almost 22 years ago)

rotate image script-fu

You made one slight mistake. There should be two separate $i's (not $i$i, but $i $i). We want to put the current file name in for both the input and the output files.

To get instructions for convert, enter "man convert". Here's the synopsis: convert [ options ... ] input_file output_file

So, I'll break the command into pieces:

1. Loop over everything in the directory (*) with variable (i): for i in *;

2. run the convert program, with the rotate option (rotating by 270 degrees). The input file and output file are *both* the current value of i. To get the current value of i, use $i.
do convert -rotate 270 $i $i;

3. We could put more commands in, but in this case, we're done. done

So, all together, it's: for i in *; do convert -rotate 270 $i $i; done

--Joel

Hi Joel,
thanks for the tip,
whan i ran your script i recieved the error convert: Missing an image file name. 20 time (there are 20 files in this directory) I wrote it as you sent it to me, is there something i have missed. [jason@localhost narooma_rest]$ for i in *;do convert -rotate 270 $i$i;done convert: Missing an image file name. convert: Missing an image file name. [jason@localhost narooma_rest]$

I am running ImageMagic 5.3.0 thanks again Joel .
When I used winblows it was just a matter of creating an action in Photoshop that i could use over and over. thats why I thought a script-fu would be good but this looks even easier (if it will work)
jason

On Monday 17 June 2002 13:14, you wrote:

Jason,

While this certainly can be done with script-fu, the *easiest* way to rotate all of the images in a directory is with the ImageMagick program, convert. At the command line, go to the directory holding the images, then enter:

for i in *; do convert -rotate 270 $i $i; done

This goes through all of the files in the directory, rotates any image file found by 270 degrees, and over-writes the old file with the new version.

--Joel

Hi gimpers,
I want to be able to run a script in batch mode, that gets all the images in a directory , rotates them by 270 clockwise and then saves them to the same dirctory . but I am having some trouble getting started . I understand that I just have to call the plugin rotate image. Has anyone written a script like this ? or similar that i could have a look at . thanks in advance
jason

Jason Pearce
2002-06-17 08:00:07 UTC (almost 22 years ago)

rotate image script-fu

Hi Dave,
I tried
for i in *;do convert -rotate 270 $1;done for i in *;do convert -rotate 270 $1$1;done for i in *;do convert -rotate 270 $1$i;done $ for i in *;do convert -rotate 270 $i$1;done and all gave me the same output
convert: Missing an image file name. any other ideas
cheers jason

On Monday 17 June 2002 14:58, you wrote:

Try $1 instead of i.

On 6/16/02 9:10 PM, "Jason Pearce" wrote:

Hi Joel,
thanks for the tip,
whan i ran your script i recieved the error convert: Missing an image file name. 20 time (there are 20 files in this directory) I wrote it as you sent it to me, is there something i have missed. [jason@localhost narooma_rest]$ for i in *;do convert -rotate 270 $i$i;done convert: Missing an image file name. convert: Missing an image file name. [jason@localhost narooma_rest]$

I am running ImageMagic 5.3.0 thanks again Joel .
When I used winblows it was just a matter of creating an action in Photoshop that i could use over and over. thats why I thought a script-fu would be good but this looks even easier (if it will work)
jason

On Monday 17 June 2002 13:14, you wrote:

Jason,

While this certainly can be done with script-fu, the *easiest* way to rotate all of the images in a directory is with the ImageMagick program, convert. At the command line, go to the directory holding the images, then enter:

for i in *; do convert -rotate 270 $i $i; done

This goes through all of the files in the directory, rotates any image file found by 270 degrees, and over-writes the old file with the new version.

--Joel

Hi gimpers,
I want to be able to run a script in batch mode, that gets all the images in a directory , rotates them by 270 clockwise and then saves them to the same dirctory . but I am having some trouble getting started . I understand that I just have to call the plugin rotate image. Has anyone written a script like this ? or similar that i could have a look at . thanks in advance
jason

Jason Pearce
2002-06-17 08:03:58 UTC (almost 22 years ago)

rotate image script-fu

Hi Joel,
your a legend .
thanks very much
jason

On Monday 17 June 2002 15:37, you wrote:

You made one slight mistake. There should be two separate $i's (not $i$i, but $i $i). We want to put the current file name in for both the input and the output files.

To get instructions for convert, enter "man convert". Here's the synopsis: convert [ options ... ] input_file output_file

So, I'll break the command into pieces:

1. Loop over everything in the directory (*) with variable (i): for i in *;

2. run the convert program, with the rotate option (rotating by 270 degrees). The input file and output file are *both* the current value of i. To get the current value of i, use $i. do convert -rotate 270 $i $i;

3. We could put more commands in, but in this case, we're done. done

So, all together, it's: for i in *; do convert -rotate 270 $i $i; done

--Joel

Hi Joel,
thanks for the tip,
whan i ran your script i recieved the error convert: Missing an image file name. 20 time (there are 20 files in this directory) I wrote it as you sent it to me, is there something i have missed. [jason@localhost narooma_rest]$ for i in *;do convert -rotate 270 $i$i;done convert: Missing an image file name. convert: Missing an image file name. [jason@localhost narooma_rest]$

I am running ImageMagic 5.3.0 thanks again Joel .
When I used winblows it was just a matter of creating an action in Photoshop that i could use over and over. thats why I thought a script-fu would be good but this looks even easier (if it will work)
jason

On Monday 17 June 2002 13:14, you wrote:

Jason,

While this certainly can be done with script-fu, the *easiest* way to rotate all of the images in a directory is with the ImageMagick program, convert. At the command line, go to the directory holding the images, then enter:

for i in *; do convert -rotate 270 $i $i; done

This goes through all of the files in the directory, rotates any image file found by 270 degrees, and over-writes the old file with the new version.

--Joel

Hi gimpers,
I want to be able to run a script in batch mode, that gets all the images in a directory , rotates them by 270 clockwise and then saves them to the same dirctory . but I am having some trouble getting started . I understand that I just have to call the plugin rotate image. Has anyone written a script like this ? or similar that i could have a look at . thanks in advance
jason

Joel
2002-06-17 10:07:02 UTC (almost 22 years ago)

rotate image script-fu

Glad it worked for you!

When I used winblows it was just a matter of creating an action in Photoshop that i could use over and over. thats why I thought a script-fu would be good but this looks even easier (if it will work)
jason

Heh.... want it to be even easier?

You could set up a shell script to do the whole thing with a couple of keystrokes. To do this, create a new text file (call it r, or r270, or something else that's easy for you to type and remember). Copy the text below into the file:

------------------------- #!/bin/sh

if [ $# = 1 ]; then
cd $1
fi

for i in *; do convert -rotate 270 $i $i; done

if [ $# = 1 ]; then cd ~-
fi
----------------------------

When you're done, put the file somewhere on your path. (probably in /usr/local/bin)

Then chmod +x so that it can be executed.

Once you've done this, you'll be able to convert a batch of images by just getting to the directory where the images are and typing 'r', or by just getting to a command prompt and typing 'r [directory]'.

Mmmmmmmm.... script-a-licious! ;-)

--Joel

Akkana
2002-06-17 19:10:28 UTC (almost 22 years ago)

rotate image script-fu

Joel writes:

You could set up a shell script to do the whole thing with a couple of keystrokes.

Here's another rotating script: I can never remember the arguments to convert, and I do this a lot when I import images from my camera, so I have a script I call "rotateall". I could say rotateall -left * (to do what the original poster wanted), or a more complicated line like rotateall -right img1.jpg img2.jpg -left img5.jpg img7.jpg ...

I didn't know it was safe in Convert to have the input and output files be the same name (the man page doesn't mention that, and in most programs it's not safe) so my script uses a temp file.

...Akkana

#!/bin/csh -f

set degrees = 90

while ($#argv >= 1) if ("$argv[1]" == '-left') then
set degrees = -90
echo "Rotating left"
else if ("$argv[1]" == '-right') then set degrees = 90
echo "Rotating right"
else if ("$argv[1]" =~ -*) then
echo "Usage: rotate [-left|-right] img ..." exit
else
echo rotate $argv[1] $degrees convert -rotate $degrees $argv[1] foo mv foo $argv[1]
endif
shift
end

Joel
2002-06-19 02:06:47 UTC (almost 22 years ago)

rotate image script-fu

would you can send me the script? I am very interested about using GIMP to make/process animations, so a script that gets all the imagens in a directory, and apply some kind of transformation in them would be very useful for me. And I am still a Script-fu beginner :)

thank you, andrei

Now *that* is a noble cause. ;-)

I'm not really all that crazy about Scheme (Gimp's built-in scripting language), so I don't write with it. I really, really like Python, though, and there are Python bindings for the Gimp. You can download them at http://www.daa.com.au/~james/pygimp/

Use the documentation there, plus the PDB browser, to figure out everything you can do. In the meantime, here's a quick little script I whipped up to rotate a series of images in a directory. To avoid writing something that would be trivial to do with "convert," I've put in a little twist... The first image is slightly rotated, the second a little bit more, and so on, until the last image, which goes to the user-specified rotation.

Enjoy!

--Joel

rotate.py -----------------------------------------------------------------

#!/usr/bin/env python #
# rotate.py
#
# animate rotating all images in a directory; The first image gets rotated # very little, progressing to the final image, which gets rotated by # a user-specified degree.
#
# Copyright 2002, Joel Hatch
# Licensed under the GNU GPL
# 18 June 2002

from gimpfu import * import math, os, traceback

Error = "Error"

def rotateImages(directory, degrees): "Rotate images in a directory"

# Make sure the directory is valid path = os.path.normpath(directory) if not os.path.isdir(path):
raise Error, "Directory %s not found" % path

# Get and sort a list of files in the directory oldDir = os.getcwd()
os.chdir(path)
files = os.listdir(path)
files.sort()

# figure out how far to rotate each image; we are going to get a # group of images, and rotate each image further until the last image # is the full rotation. (convert to radians) standardRotation = (float(degrees) * math.pi) / (len(files) * 180) currentRotation = 0

for file in files:
try:
# load the image
graphicFile = pdb.gimp_file_load(file, file)

# add an alpha channnel to the bottom layer, so the background # will be transparent
pdb.gimp_layer_add_alpha(graphicFile.layers[0])

# calculate how big the containing box will need to be # (our picture is a rectangle, inside a circle (the rotation), # inside a square (the containing box size). The width and # height of the containing box are the same as the diameter of # the circle, which can be found from the rectangle with d^2=w^2+h^2 size = math.sqrt(graphicFile.width**2 + graphicFile.height**2)

# calculate the top left position of our image inside the # containing box
top = (size - graphicFile.height)/2 left = (size - graphicFile.width)/2

# resize the image to the containing box pdb.gimp_image_resize(graphicFile, size, size, left, top)

# rotate every layer in the image currentRotation = currentRotation - standardRotation for layer in graphicFile.layers: pdb.gimp_rotate(layer, FALSE, currentRotation) left, top = layer.offsets pdb.gimp_layer_resize(layer, size, size, left, top)

# save and close the file if len(graphicFile.layers) > 1: finalLayer = pdb.gimp_image_merge_visible_layers(graphicFile, CLIP_TO_IMAGE)
else:
finalLayer = graphicFile.layers[0] finalName = "n_%s.png" % os.path.splitext(file)[0] pdb.file_png_save(graphicFile, finalLayer, finalName, finalName, \ FALSE, 6, TRUE, TRUE, TRUE, TRUE, TRUE) pdb.gimp_image_delete(graphicFile) # If you want to display the image, instead of closing it, comment the # above line, and un-comment the line below # pdb.gimp_display_new(graphicFile)

except: traceback.print_exc()

# change back to the default directory os.chdir(oldDir)

register(
"python_fu_rotate",
"Rotate all images in a directory", "",
"Joel Hatch",
"",
"16 June 2002",
"/Xtns/Python-Fu/Animation/Rotate", "RGB*, GRAY*",
[
(PF_STRING, "Directory", "Directory containing files to rotate", ""), (PF_INT, "degrees", "Degrees to rotate the final image", "") ],
[],
rotateImages)

main()

------------------------------------------------------

Andrei Thomaz
2002-06-20 07:25:47 UTC (almost 22 years ago)

rotate image script-fu

thank you very much. I am still in my first steps with Scheme, but Python seems easier :)

andrei

From: Joel
To: "Andrei Thomaz"
,gimp-user@lists.xcf.berkeley.edu
Subject: Re: [Gimp-user] rotate image script-fu Date: Tue, 18 Jun 2002 14:06:47 -1000

would you can send me the script? I am very interested about using GIMP

to

make/process animations, so a script that gets all the imagens in a directory, and apply some kind of transformation in them would be very useful for me. And I am still a Script-fu beginner :)

thank you, andrei

Now *that* is a noble cause. ;-)

I'm not really all that crazy about Scheme (Gimp's built-in scripting language), so I don't write with it. I really, really like Python, though, and there are Python bindings for the Gimp. You can download them at http://www.daa.com.au/~james/pygimp/

Use the documentation there, plus the PDB browser, to figure out everything you can do. In the meantime, here's a quick little script I whipped up to rotate a series of images in a directory. To avoid writing something that would be trivial to do with "convert," I've put in a little twist... The first image is slightly rotated, the second a little bit more, and so on, until the last image, which goes to the user-specified rotation.

Enjoy!

--Joel

rotate.py -----------------------------------------------------------------

#!/usr/bin/env python #
# rotate.py
#
# animate rotating all images in a directory; The first image gets rotated # very little, progressing to the final image, which gets rotated by # a user-specified degree.
#
# Copyright 2002, Joel Hatch
# Licensed under the GNU GPL
# 18 June 2002

from gimpfu import * import math, os, traceback

Error = "Error"

def rotateImages(directory, degrees): "Rotate images in a directory"

# Make sure the directory is valid path = os.path.normpath(directory) if not os.path.isdir(path):
raise Error, "Directory %s not found" % path

# Get and sort a list of files in the directory oldDir = os.getcwd()
os.chdir(path)
files = os.listdir(path)
files.sort()

# figure out how far to rotate each image; we are going to get a # group of images, and rotate each image further until the last image # is the full rotation. (convert to radians) standardRotation = (float(degrees) * math.pi) / (len(files) * 180) currentRotation = 0

for file in files: try:
# load the image
graphicFile = pdb.gimp_file_load(file, file)

# add an alpha channnel to the bottom layer, so the background # will be transparent
pdb.gimp_layer_add_alpha(graphicFile.layers[0])

# calculate how big the containing box will need to be # (our picture is a rectangle, inside a circle (the rotation), # inside a square (the containing box size). The width and # height of the containing box are the same as the diameter of # the circle, which can be found from the rectangle with d^2=w^2+h^2
size = math.sqrt(graphicFile.width**2 + graphicFile.height**2)

# calculate the top left position of our image inside the # containing box
top = (size - graphicFile.height)/2 left = (size - graphicFile.width)/2

# resize the image to the containing box pdb.gimp_image_resize(graphicFile, size, size, left, top)

# rotate every layer in the image currentRotation = currentRotation - standardRotation for layer in graphicFile.layers: pdb.gimp_rotate(layer, FALSE, currentRotation) left, top = layer.offsets pdb.gimp_layer_resize(layer, size, size, left, top)

# save and close the file if len(graphicFile.layers) > 1: finalLayer = pdb.gimp_image_merge_visible_layers(graphicFile, CLIP_TO_IMAGE)
else:
finalLayer = graphicFile.layers[0] finalName = "n_%s.png" % os.path.splitext(file)[0] pdb.file_png_save(graphicFile, finalLayer, finalName, finalName, \
FALSE, 6, TRUE, TRUE, TRUE, TRUE, TRUE) pdb.gimp_image_delete(graphicFile) # If you want to display the image, instead of closing it, comment the # above line, and un-comment the line below # pdb.gimp_display_new(graphicFile)

except: traceback.print_exc()

# change back to the default directory os.chdir(oldDir)

register(
"python_fu_rotate",
"Rotate all images in a directory", "",
"Joel Hatch",
"",
"16 June 2002",
"/Xtns/Python-Fu/Animation/Rotate", "RGB*, GRAY*",
[
(PF_STRING, "Directory", "Directory containing files to rotate", ""),
(PF_INT, "degrees", "Degrees to rotate the final image", "") ],
[],
rotateImages)

main()

------------------------------------------------------

Andrei Thomaz
2002-06-20 07:41:51 UTC (almost 22 years ago)

rotate image script-fu

is this available only for Linux? i am using a windows version of GIMP... (please, don't kill me. I share my computer with my family, so no linux for now...)

andrei

From: Joel
To: "Andrei Thomaz"
,gimp-user@lists.xcf.berkeley.edu
Subject: Re: [Gimp-user] rotate image script-fu Date: Tue, 18 Jun 2002 14:06:47 -1000

would you can send me the script? I am very interested about using GIMP

to

make/process animations, so a script that gets all the imagens in a directory, and apply some kind of transformation in them would be very useful for me. And I am still a Script-fu beginner :)

thank you, andrei

Now *that* is a noble cause. ;-)

I'm not really all that crazy about Scheme (Gimp's built-in scripting language), so I don't write with it. I really, really like Python, though, and there are Python bindings for the Gimp. You can download them at http://www.daa.com.au/~james/pygimp/

Use the documentation there, plus the PDB browser, to figure out everything you can do. In the meantime, here's a quick little script I whipped up to rotate a series of images in a directory. To avoid writing something that would be trivial to do with "convert," I've put in a little twist... The first image is slightly rotated, the second a little bit more, and so on, until the last image, which goes to the user-specified rotation.

Enjoy!

--Joel

rotate.py -----------------------------------------------------------------

#!/usr/bin/env python #
# rotate.py
#
# animate rotating all images in a directory; The first image gets rotated # very little, progressing to the final image, which gets rotated by # a user-specified degree.
#
# Copyright 2002, Joel Hatch
# Licensed under the GNU GPL
# 18 June 2002

from gimpfu import * import math, os, traceback

Error = "Error"

def rotateImages(directory, degrees): "Rotate images in a directory"

# Make sure the directory is valid path = os.path.normpath(directory) if not os.path.isdir(path):
raise Error, "Directory %s not found" % path

# Get and sort a list of files in the directory oldDir = os.getcwd()
os.chdir(path)
files = os.listdir(path)
files.sort()

# figure out how far to rotate each image; we are going to get a # group of images, and rotate each image further until the last image # is the full rotation. (convert to radians) standardRotation = (float(degrees) * math.pi) / (len(files) * 180) currentRotation = 0

for file in files: try:
# load the image
graphicFile = pdb.gimp_file_load(file, file)

# add an alpha channnel to the bottom layer, so the background # will be transparent
pdb.gimp_layer_add_alpha(graphicFile.layers[0])

# calculate how big the containing box will need to be # (our picture is a rectangle, inside a circle (the rotation), # inside a square (the containing box size). The width and # height of the containing box are the same as the diameter of # the circle, which can be found from the rectangle with d^2=w^2+h^2
size = math.sqrt(graphicFile.width**2 + graphicFile.height**2)

# calculate the top left position of our image inside the # containing box
top = (size - graphicFile.height)/2 left = (size - graphicFile.width)/2

# resize the image to the containing box pdb.gimp_image_resize(graphicFile, size, size, left, top)

# rotate every layer in the image currentRotation = currentRotation - standardRotation for layer in graphicFile.layers: pdb.gimp_rotate(layer, FALSE, currentRotation) left, top = layer.offsets pdb.gimp_layer_resize(layer, size, size, left, top)

# save and close the file if len(graphicFile.layers) > 1: finalLayer = pdb.gimp_image_merge_visible_layers(graphicFile, CLIP_TO_IMAGE)
else:
finalLayer = graphicFile.layers[0] finalName = "n_%s.png" % os.path.splitext(file)[0] pdb.file_png_save(graphicFile, finalLayer, finalName, finalName, \
FALSE, 6, TRUE, TRUE, TRUE, TRUE, TRUE) pdb.gimp_image_delete(graphicFile) # If you want to display the image, instead of closing it, comment the # above line, and un-comment the line below # pdb.gimp_display_new(graphicFile)

except: traceback.print_exc()

# change back to the default directory os.chdir(oldDir)

register(
"python_fu_rotate",
"Rotate all images in a directory", "",
"Joel Hatch",
"",
"16 June 2002",
"/Xtns/Python-Fu/Animation/Rotate", "RGB*, GRAY*",
[
(PF_STRING, "Directory", "Directory containing files to rotate", ""),
(PF_INT, "degrees", "Degrees to rotate the final image", "") ],
[],
rotateImages)

main()

------------------------------------------------------

Joel
2002-06-20 08:52:44 UTC (almost 22 years ago)

rotate image script-fu

On Wednesday 19 June 2002 07:41 pm, Andrei Thomaz wrote:

is this available only for Linux? i am using a windows version of GIMP... (please, don't kill me. I share my computer with my family, so no linux for now...)

andrei

doh! This might get tricky... ;-)

I don't have a Windows box at all, so can't really test this, or tell if it works under Windows, or compile Windows programs, or anything like that.

I do know, however, that Gimp works under Windows. I've installed it for friends, and played with it for a bit. Gimp includes the GTK libraries, so *they* work under Linux.

Gimp-Python uses the pygtk package... PyGTK's homepage is: http://www.daa.com.au/~james/pygtk/

There's a FAQ at: http://www.async.com.br/faq/pygtk/index.py?req=index; the fourth question is "Where can I get PyGTK for Windows?" The answer is:

(Assuming you really want to do this, you should be aware that PyGTK works reasonably well on Windows, much to the credit of GTK+, Python and PyGTK developers and porters) Cédric Gustan has the latest stable version wrapped in an installer, based on Hans Breuer's work: http://www.pcpm.ucl.ac.be/~gustin/win32_ports/PyGtk-0.6.9.win32-py2.1.exe

... all of which amazes me to no end!

It then links to Hans Breuer's website, http://hans.breuer.org/ports/, where we can find that he *has* ported Gimp Python to Windows. Wahoo! He has even included a binary there.

Wow! And other stuff...

/me gets distracted, catching a glimpse of the Grail.

So, right now, I'm not sure how difficult it will be to get it working on your system, but I am absolutely convinced that it's possible.

Good luck!

--Joel

btw, I'm really interested in hearing about how it works. Very, very curious. Very much so. ;-)