File: pixel-fx.pl

package info (click to toggle)
imagemagick 8%3A6.8.9.9-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 66,572 kB
  • sloc: ansic: 328,748; cpp: 21,132; sh: 12,706; xml: 9,266; perl: 5,193; makefile: 2,820; tcl: 459
file content (53 lines) | stat: -rwxr-xr-x 1,516 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
#
# Example of modifying all the pixels in an image (like -fx).
#
# Currently this is slow as each pixel is being lokedup one pixel at a time.
# The better technique of extracting and modifing a whole row of pixels at
# a time has not been figured out, though perl functions have been provided
# for this.
#
# Also access and controls for Area Re-sampling (EWA), beyond single pixel
# lookup (interpolated unscaled lookup), is also not available at this time.
#
# Anthony Thyssen   5 October 2007
#
use strict;
use Image::Magick;

# read original image
my $orig = Image::Magick->new();
my $w = $orig->Read('rose:');
warn("$w")  if $w;
exit  if $w =~ /^Exception/;


# make a clone of the image (preserve input, modify output)
my $dest = $orig->Clone();

# You could enlarge destination image here if you like.
# And it is posible to modify the existing image directly
# rather than modifying a clone as FX does.

# Iterate over destination image...
my ($width, $height) = $dest->Get('width', 'height');

for( my $j = 0; $j < $height; $j++ ) {
  for( my $i = 0; $i < $width; $i++ ) {

    # read original image color
    my @pixel = $orig->GetPixel( x=>$i, y=>$j );

    # modify the pixel values (as normalized floats)
    $pixel[0] = $pixel[0]/2;      # darken red

    # write pixel to destination
    # (quantization and clipping happens here)
    $dest->SetPixel(x=>$i,y=>$j,color=>\@pixel);
  }
}

# display the result (or you could save it)
$dest->Write('win:');
$dest->Write('pixel-fx.gif');