Automated GIMP Processing of Web Site Images
Listing 11. Save any image The GIMP can load as a JPEG image with given compression parameters.
sub monkeyiq_gimp_convert {
my( $inputimagename, $outfilename, $qual,
$smoothing, $comment ) = @_;
$img = gimp_file_load( $inputimagename,
$inputimagename );
$layer = getMergedLayer( $img );
file_jpeg_save( $img, $layer,
$outfilename, $outfilename,
$qual, $smoothing, 1, 1,
$comment, 0, 1, 0, 1 );
return $img;
}
register
...
"*",
[
[PF_STRING, "inputimage",
"Name of image to export", ""],
[PF_STRING, "outputimage",
"Name of image to save to", ""],
[PF_FLOAT, "quality",
"0-100 quality of JPG", ""],
[PF_FLOAT, "smoothing",
"0-1 smoothing", ""],
[PF_STRING, "comment",
"Comment for image", ""],
],
\&monkeyiq_gimp_convert;
exit main();
A slightly more complex script is the gimp-monkeyiq-append-layer-from-image-file, which is designed to act like the command-line cat img1 img2 >| bar command sequence. We are “appending” a layer from one image file to another. From the image from which we are reading a new layer, getMergedLayer() is called to grab all the visible layers as a single layer. As there are other scripts to hide and show layers in images, the input image can be prepared in a temporary image file to have only the desired layer(s) visible. The output image will be resized to the larger size of both input images. The code for the append layer is shown in Listing 12.
Listing 12. Append a layer from one image to another.
#!/usr/bin/perl -w
use Gimp ":auto";
use Gimp::Fu;
use lib '/usr/local/bin/';
use MonkeyIQGIMP;
sub monkeyiq_gimp_append_layer_from_image_file {
my($inputimagename, $outfilename,
$inputimagenameSecond) = @_;
print "cat $inputimagename";
print " $inputimagenameSecond >> $outfilename\n";
$img = gimp_file_load( $inputimagename,
$inputimagename );
$img2 = gimp_file_load( $inputimagenameSecond,
$inputimagenameSecond );
$layer = getMergedLayer( $img2 );
if (!$layer->has_alpha)
{
$layer->add_alpha;
}
$img2->selection_all;
$layer->edit_copy;
$newlayer = Gimp->layer_new(
$img,
Gimp->image_width( $img2 ),
Gimp->image_height( $img2 ),
RGBA_IMAGE,
"appended image data",
100,
NORMAL_MODE );
$newlayer->drawable_fill(TRANSPARENT_FILL);
Gimp->image_add_layer( $img, $newlayer, -1 );
Gimp->image_lower_layer( $img, $newlayer );
$floater = $newlayer->edit_paste( 1 );
$floater->anchor;
$imgw = Gimp->image_width( $img );
$imgh = Gimp->image_height( $img );
$img2w = Gimp->image_width( $img2 );
$img2h = Gimp->image_height( $img2 );
$img->resize( $imgw >= $img2w ? $imgw : $img2w,
$imgh >= $img2h ? $imgh : $img2h,
0, 0 );
imageOutput( $img, $outfilename );
}
register
...
[
[PF_STRING, "inputimage",
"Name of image to load", ""],
[PF_STRING, "outputimage",
"Name of image to save to", ""],
[PF_STRING, "newlayerimage",
"Name of image to append to inputimage", ""],
],
\&monkeyiq_gimp_append_layer_from_image_file;
if( $#ARGV <= 0 ) {
print "Usage: $0 -inputimage imagepath";
print " -outputimage full_dst_path ";
print " -newlayerimage imagepath2 \n\n";
exit;
}
# Handle over control to gimp
exit main();
Layers can be moved around with given x,y deltas using gimp-monkeyiq-move-visible-layers, as shown in Listing 13.
Listing 13. Move a layer around a little.
...
sub monkeyiq_gimp_move_visible_layers {
my($inputimagename, $outfilename,
$xoffset, $yoffset ) = @_;
$img = gimp_file_load( $inputimagename,
$inputimagename );
@layers = Gimp->image_get_layers( $img );
foreach $l (@layers) {
if( $l->get_visible ) {
$l->translate ( $xoffset, $yoffset );
}
}
imageOutput( $img, $outfilename );
}
...
[
[PF_STRING, "inputimage",
"Name of image to load", ""],
[PF_STRING, "outputimage",
"Name of image to save to", ""],
[PF_INT, "xoffset",
"X offset to move layers by", ""],
[PF_INT, "yoffset",
"Y offset to move layers by", ""],
],
...
The dimensions of images also can be set aside for use in PHP Web pages. The gimp-monkeyiq-get-dimension creates a bunch of PHP variables set to interesting image metadata (Listing 14). The writedata() function sets the PHP variables in the output file for the desired input layer.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- Designing Electronics with Linux
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Validate an E-Mail Address with PHP, the Right Way
- Linux Systems Administrator
- Why Python?
- Tech Tip: Really Simple HTTP Server with Python
- Build a Skype Server for Your Home Phone System
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




12 min 23 sec ago
1 hour 10 min ago
2 hours 1 min ago
6 hours 3 min ago
9 hours 50 min ago
9 hours 58 min ago
12 hours 12 min ago
14 hours 42 min ago
1 day 45 min ago
1 day 5 hours ago