Tuesday, May 25, 2010

Auto Convert and Resize Images

 
I just found this script which
apparently uses Gimp to automatically
resize images:

Auto convert ad resize images (new)

Looks like it comes with a tutorial:

Resize Image Tutorial

The tutorial is in Italian. I do
not know Italian. However, I've
gathered from what I can see that
the way this thing works is as follows:

  1. Create a text file, one image
    filename per line
  2. Run the script
  3. Look for a dialog
    that comes up
  4. In the dialog, specify
    the name of the text file
  5. In the dialog, specify the
    size you wish all your images to
    resize to.

This is not exactly what I was
looking for. However, I may try
it anyway. It may be worth a
try.

Some time later . . .

OK. I"m back. I just did a search on
the name of this tutorial with
Google. Google offered to translate
it into English for me and I accepted
their offer. Amazing technology!

Actually, I think I can use this script.
I'm going to try it now.

OK. I'm back again after having tried
the script.

This script worked better than I thought
it would. The hardest thing about it is
getting the idea.

Since I wanted to use it to scale an image
downward, I used the scale option.

First thing I did was to build a text file
that had all the names of the images I
wished to process. I called this file,
work.txt as it seems that a .txt
is recommended (required?).

The script provides you with a file dialog
that allows you to navigate to the text file.

The documentation seems to be saying that each
image filename inside the text file needs a full
path name. In addition, each full path must be
on a separate line and surrounded by double quotes.

I did that. I gave each image its own line in
the text file. I made sure that each image had
a full path starting at the root directory. In
addition, I surrounded each full path with double
quotes.

After having picked the scale option, I
left the preserve aspect ratio checkmarked.
Next, I was asked to put a height and width in.

This is where I got confused. Height and width
in terms of what? Percentages? Pixels?

It turns out that the height and width are both
in pixels. This makes sense.

Another thing that confused me on first glance
was the fact that I had to give both a height and
a width. Since I'm preserving the aspect ratio,
shouldn't I only give just one these parameters?
Why give both?

This was cleared up for me when I realized that
height and width are really maximum height
and maximum width. Once I realized this,
it was simple. Just choose one parameter as the
active parameter and make the other parameter,
the inactive parameter, ridiculously big.

For example, lets say I wish to make all the images
100 pixels wide. That being the case, I would
choose 100 pixels for the width and 1,000 or more
pixels for the height.

The ridiculous parameter, the one that will inevitably
be ignored, is the parameter that is 1,000 pixels
(or greater). Therefore, all the images will be scaled
to a 100 pixel width. The fact that the aspect ratio is
preserved means that the height will be calculated based
on the width and will be considerably less than 1,000
pixels.

In other words, when you are scaling images and preserving
aspect ratio at the same time, only the small number really
counts. That is to say, only the smallest number in terms
of the aspect ratio really counts.

Is height smaller than width? Then height matters. Is
width smaller than height? Then width matters.

In other words, each parameter is a maximum, and generally
speaking, only one of the parameters matters when scaling
images.

Of course, you want to choose an output format. I choose
.gif just to make a choice.

Where in Gimp is the script found? What menu is it in?

Here's where I found it:

Xtns > Script-Fu > ATG > Auto convert and resize

Oddly enough, there are two menus called
Script-Fu located under the Xtns menu.
I'm not sure why this is. In any case, it
is the second Script-Fu menu that matters.

How did I install the script? I followed these
simple steps:

  1. Download the script
  2. Unzip it
  3. Place it in the proper place
  4. Restart Gimp

The proper place to place the script
will probably vary depending on your
operating system. In my case, I'm
using the script under Linux.

I placed it such that it was my personal
script rather than a system-wide script.
I placed it here:

~/.gimp-2.4/scripts

In other words, I placed it in my home
directory which contains a hidden directory
(folder) called .gimp-2.4. Underneath
the hidden directory is something called
scripts. If you place it there, Gimp
automatically finds it upon restart.

My initial impression was that I would not find
this script particularly useful. In fact, I found
it to be quite useful.

The lesson? Investigate a little bit before coming
to a conclusion.

Ed Abbott

Sunday, May 23, 2010

Gimp Script-Fu Versus
Python-Fu Versus Perl-Fu

 
I have to resize several images.
I'd like to automate Gimp to do
this. My question: Which one
of Gimp's scripting capabilities
do I use?

Years ago, I used Script-Fu and
liked it. However it did require
me to learn a little bit of Scheme,
a programming language I'm unlikely
to use anywhere else.

Generally, I like to stick to a small
handful of programming languages because
it lets me leverage what I already know.
Otherwise, I'm always studying some
new programming language.

It turns out someone with more experience
with Gimp scripting than me has written
about this:

If you're going to write your first GIMP plugin...

The above article would seem to indicate
that Python-Fu is the way to go. However,
after making the following chart, I'm not
so sure:



Script-Fu, Python-Fu, and Gimp-Python Number of Web Pages Returned by Google
YearNumber of Web Pages Returned
Script-Fu
Pages
Python-Fu
Pages
Gimp-Python
Pages
200514,2001,3302,380
200627,9009,3403,190
200732,40012,9004,160
200830,3002,4404,000
200936,7002,9503,770

To make the above chart, I followed these
steps:

  1. Go to Google Home Page
  2. Search on "script-fu" 2005
  3. Search on "python-fu" 2005
  4. Search on "gimp-python" 2005
  5. Repeat above searches for each year

The chart above would seem to indicate that
Script-Fu is still more popular than Python-Fu.
I write these words on May 24, 2010.

More and more, I'm inclined to think that
learning Script-Fu is the way to go. Why?
Well, it is the older technology and so often,
the older technology is the one to learn first.

At least, I've never regretted learning the
old technology first. I learned C Language
before I learned C++. Knowing C only
made learning C++ easier.

OF course, C and C++ are not particularly
good analogs to Scheme and Python. C++
is a superset of C whereas Python basically has
nothing to do with Scheme, to the best of my
knowledge.

I don't know Python at all and my encounter with
Scheme has been brief. So, my remarks about Python
and Scheme may not be very accurate.

This article here, has shown me that I already
have a number of scheme scripts installed
under Gimp:

Gimp Scripts

Here's where the article says pre-installed Scheme
scripts are kept:

/usr/share/gimp/2.0/scripts

Here's where I put these scripts
if I wish to copy a script, modify
it, and make it my own:

~/.gimp-2.2/scripts

I see many many Scheme scripts that
I can copy and modify. Another reason
for me to use Scheme.

Here's a post by someone who describes
where Python-Fu scripts are placed and
also warns that you need to make Python
scripts executable:

What Happened to pyGIMP?

From what I see and read, it seems that
Scheme is the language that has the most
Gimp extensions.

So, I think I'll learn Script-Fu (Scheme)
first. After this, I can consider learning
Python.

Actually, it may not make that much difference.
Since I can download and modify any script I
choose from the Internet, I may not care that
much which language it is written in.

It may turn out that the language the script
is written in is not all that important.

The lesson? Do your homework first and you
will know what to do. If you don't know,
you need to do more homework.

Ed Abbott

Friday, May 21, 2010

The Poor Man's Gimp Macro

 
If I understand correctly, Gimp does
not let you save macros. It does
not let you save macros as keystrokes
that you type, save and immediately
repeat. At least, not at the time of
this writing.

It is something I sorely miss. The
only way to do macros in Gimp is to
use a full-fledged scripting facility
called Script-Fu.

Not that I'm complaining. I've used
Script-Fu in the past. It is wonderful.
It is far more powerful than the mere
ability to save keystrokes and turn
them into a macro.

Therein lies the problem. Sometimes I
need a lighter-weight way of saving keystrokes.
Sometimes Script-Fu is too much for me,
but a facility for gathering gimp keystrokes
and commands into one macro would be just
right.

This is more a problem of scale than anything
else. Scale the solution to the size of the
problem. In other words, don't make a big deal
about a little thing.

While I've not discovered a macro-saving capability
in Gimp, I have discovered a near-substitute. By
near-substitute, I mean something that will do for
now.

Tear-Off Menus


In Gimp there is something called a Tear-Off Menu.
It's a way to save a menu for later re-use. You tear
the menu off by clicking on the dashed line at the top
of the menu .

Tear-off menus are great. Instead of having to
go 3 menus deep to find a menu that you just
used a moment ago, you can save that menu by
tearing it off. Tear-off menus save a lot repeat
pointing and clicking.

The essence of my poor man's Gimp macro facility
is tear-off menus.

Here are a series of operations I did on a series
of images I was working on. First, I loaded the
images to Gimp in this manner. I typed the following
on the Linux command line:

gimp *jpg

The above command loaded 13 .jpg images into
Gimp. After loading the 13 images, I did the following
steps:

  1. Give each image an alpha channel
  2. Type Shift-O to select by color
  3. Click on the black background of
    the image with the intent of turning
    the black background into a transparency
  4. Hit the delete key on my keyboard
    to remove the black background
  5. Apply the unsharp mask to the image
    to sharpen up the image and reduce the
    number of colors
  6. Save the image by the same name but
    with a .gif file extension instead
    of a .jpg file extension

Since the images were line diagrams that
had been shrunk to fit into a smaller space,
the unsharp mask did wonders! It not only
made the line drawings appear to be cleaner
and clearer, it also reduced the number of
colors dramatically. In some cases the number
of colors went from over 1,000 colors to 7
colors.

Gif Versus Jpeg


Since I only needed 7 colors, I was better
off with a .gif than a .jpg. Jpegs
are great for representing lots of colors,
say, in a photograph, for example. Gifs are
great for line drawings that really don't
benefit from the overuse of color.

An additional benefit of the Gif format is that
you can turn the image into a transparency. Thus
you can remove the background of the image and
then layer the image on top of another image. In
my case, this got rid of ugly black-background
corners that would otherwise have appeared in the
topmost image in the image stack.

In a sense, I was using Gif's ability to be
transparent to round-off corners.

The Poor Man's Gimp Macro


So how does the poor man's Gimp macro
work? Basically, you save the tear-off
menus and place them on your screen in
a fixed order. For example, place them
on the right-hand side of your screen going
top to bottom.

If the tear-off menus belong on the right
side of the screen, then the image that has
the current focus belongs on the left side of
the screen. If the current focus image is
blocking the tear-off menus on the right,
drag the focus image to the left. In other
words, put the image you are working on the
left side of your screen to reveal the tear-off
menus that you have organized from top to bottom
on the right side of your screen.

By segregating the images that you are working
on from the tear-off menus you use to manipulate
these images, you are ready to start using the
poor man's Gimp macro
.

The next step is fairly obvious. At least, it
is obvious if you have it right in front of you
on your screen. You manipulate the image by
applying each tear-off menu, one after the other,
from top to bottom.

That's the poor man's Gimp macro. That's it in
a nutshell. All it really is is traversing tear-off
menus in an established order.

Not as good a real macro facility, but it will do
for now.

The thing it saves me from doing is having to start
writing something in Script-Fu before I'm ready to
do so. In others words, its nice to work a procedure
out manually before turning it into a script.

Many many activities are not repetitious enough to
justify writing a script. Some things you are only
going to done maybe once a year, maybe less.

For something like this, something that is mildly
repetitious, the poor man's macro may fill the gap
nicely.

In Gimp, I feel there is a gap. There's a gap between
having to grind something out by pointing and clicking
too much and using Script-Fu.

I use the poor man's Gimp Macro to fill that gap.

That said, I'd like to acknowledge that there's nothing
quite like Gimp out there. It's easy to think of ways
to improve something when it is great already. Gimp is
a great thing.

Ed Abbott

Tuesday, March 30, 2010

Importing PDF Files
Into the Gimp Image Editor

 
I've just rediscovered the fact that
PDf Files can be loaded into the Gimp.

Here's the procedure I use to do so:

  1. Type gimp filename.pdf
    at the command line
  2. If the PDF file has more
    than one image in it, you will
    be given a choice
  3. Import the PDF image of
    your choice into Gimp

That's it! That's all it takes
to load the image of your choice
into Gimp from a PDF file.

Ed Abbott

Saturday, October 24, 2009

Love the Gimp Gradient Tool

This is new blog where I write
about my favorite Gimp tools.

For those who do not know, Gimp
is an image editing tool.

A common use for Gimp is
creating logos and other graphics
for the web and for websites.

Today, I was working with the
gradient tool. Just love this
guy!

As far as I can tell, the gradient
tool really consists of 3 parts:

  1. A foreground color
  2. A background color
  3. A way to bridge the two

Actually, I'm simplifying things
here somewhat.

The foreground and background colors
are really not integrated into the
gradient tool. Rather, they are
integrated into Gimp itself.

That is to say, the foreground and
background colors have a global nature
to them.

Here's the essence of the gradient tool.
The essence consists of two parts:

  1. Stretch a line between two points.
  2. Gradually transition from one color to
    another.

OK. Next, I'll be uploading an image that
I created with the gradient tool. However,
first I need to learn how to upload images
to blogger. I'll be editing this post as
soon as I learn. That's the plan.


Ed Abbott