Resize Multiple Images with a G-Script
jay
Summary
scale_image_to_sizes is a quick and easy G-Script that can convert multiple images with a single Right-Click in Nautlius. It's very simple to use and very easy to modify to your needs.
Introduction
Being the in-house techie my wife employed me to create and maintain her High School Class Web site. (It shall remain annon because the design is really tacky. Like circa 1997 tacky.) And as things go most people do not get the concept that when they take a digital photo on a 4+mb camera that the photo file is quite large. Have you ever tried to explain that a photo that's 1152x864 is to large to display in a web page? Not to mention that the file size is pushing 1.5+MB. So every time my wife gets sent some photos to be posted on the site she'd send me the zip file with 10 or so photos all of which are pushing the 1152x864 / 1.5MB limit. I'd try to explain to her, for the billionth time, how to resize the photos (on her WinXP box) before sending them to me using the MS Picture Manager. This would result in her getting frustrated because I go to fast when explaining things. In the end I usually kick her out of her chair and convert the photos my self. If you want something done right.....
![]()
I have always found that doing these types tasks on a Windows box is easy because there is so much Windows software out there. But when it comes to Linux these tasks are still just as easy. The hard part is finding the tool to do it.
G-Script: scale_image_to_sizes
If you haven't got G-Scripts installed go here. Once you've got G-Scripts installed you'll see in scale_image_to_sizes the context menu:
Right-Click-> Nautlius Scripts-> Multimedia-> scale_image_to_sizes
You'll see another script, scale_image which is for a single image and works quite similar to scale_image_to_sizes.
Resize Images
Now that you know where the script lives let's resize some images.
- Using Nautilus navigate to an images directory
- Select 1 or more images by holding the Ctrl key while selecting each image
- Right-Click on the selected images and then
Nautlius Scripts-> Multimedia-> scale_image_to_sizes - A dialog box will pop up with a list of pre-defined image sizes (1600x1400 ,1280x1024, 1024x768, 800x600, 640x480) and choose the 6040x480
- Click OK and in a few seconds you'll new inage files appear with the image size pre-pended to the filr name (640x480ImageName.jpg)
When it's done double click one of the new resized images to see the result.
See very simple.
But 640x480 that's still kind of large.
No problem.
Hacking the G-Script
The thing I am loving about Nautilus and G-Scripts is the fact that I can adjust an application (a bash script) with out having to know any C/C++. I view G-Scripts like I view the web; in the end it's all just text. So with this G-Script scale_image_to_sizes we are going to add a new size to resize images to.
In Nautilus navigate to the hidden folder /.gnome2/Nautilus-Scripts/Multimedia. In the Multimedia folder you'll see the file scale_image_to_sizes.
Right-Click on it and then open it in gedit(or what ever text editor you like) .
You should see this:
*I've omitted the Language Selection for readability.*
-
#!/bin/bash
-
title="Scale image"
-
scale="Choose which sizes to scale to"
-
imgsize=`gdialog --title "$title" --checklist "$scale" 200 100 6 1600x1400 " " off 1280x1024 " " off 1024x768 " " off 800x600 " " off 640x480 " " off 2>&1`
-
-
while [ $# -gt 0 ]; do
-
picture=$1
-
for i in $imgsize; do
-
i=`echo $i | sed 's/"//g'`
-
/usr/bin/convert -scale $i "$picture" "$i-$picture"
-
done
-
shift
-
done
I can't go into a detailed explanation of this script because quite frankly I don't know bash that well. (But after 8 years at web development and programming one can look at almost any language and get the gist of it.)
What I do know is that this G-Script is a wrapper for the bash command convert and is passed the -scale parameter to indicate that this is an image. The new image size is a guideline that measures the image to determine if it is a landscape or portrait and then scales the picture accordingly.
The item we want to look at is the variable imgsize which will holds the value we selected from the list when resizing the images. For the sake of not breaking any thing we are going to change the 1280x1024 value to 400x350 and that's it.
-
imgsize=`gdialog --title "$title" --checklist "$scale" 200 100 6 1600x1400 " " off 400x350 " " off 1024x768 " " off 800x600 " " off 640x480 " " off 2>&1`
Now save the document and go back to Resize Images instructions but this time select the new image size.
Conclusion
As you can see this little script can save you time when you need to convert a lot of images at once. Sure there are GUI apps that do the same thing but this sweet baby is very simple, light weight and you can hack it up!!
Now when my wife sends me a zip file of images I just unpack it and then run scale_image_to_sizes. Once the images are ready I just upload them to the site and I'm done.
G Scripts GNOME HOWTO Tips N TricksPosted in Linux, HOWTO, Tips N Tricks, GNOME, G-Scripts |











October 25th, 2006 at 4:21 am
Mate.. There's a faster way for your wife to resize pictures..
I've written one here http://www.fishingkaki.com/forum/viewtopic.php?t=15620 and basically involves(in summary) installing a Windows XP Powertoy known as Image Resizer from Microsoft. After that, it's just a simple right click and "Resize Image".
November 1st, 2006 at 9:22 pm
This is for Linux, more specifically Gnome, not Windows.... I think everyone knows about the powertoys add on
December 27th, 2006 at 2:18 pm
Ha,ha. Windows. Yea. Where the REAL power lies we both know buddy ey ????
February 20th, 2007 at 10:49 pm
late to the game here, but is there a similar feature that will simply let me re-scale the pixels per inch without re-sizing the picture?
May 11th, 2007 at 4:47 am
Another useful article on the subject: http://polishlinux.org/apps/graphics/enchanting-pictures-with-imagemagick/
(massive resizing, adding text or frames to images, etc, all with ImageMagick)
June 4th, 2007 at 7:34 pm
Hi Jim. Photos i received. Thanks