File: test.pl

package info (click to toggle)
exactimage 1.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,040 kB
  • sloc: cpp: 35,940; ansic: 1,952; xml: 1,447; makefile: 338; perl: 138; sh: 110; python: 45; php: 37; ruby: 12
file content (148 lines) | stat: -rw-r--r-- 3,839 bytes parent folder | download | duplicates (4)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# ExactImage Perl Example
# Copyright (C) 2006 - 2010 Rene Rebe, ExactCODE GmbH

use strict;

# the ExactImage module
use lib './objdir/api/perl';

use ExactImage;

# create an ExactImage
my $image = ExactImage::newImage ();

# easy use, use on-disc files:

if (ExactImage::decodeImageFile ($image, "testsuite/281-4.2.04.tif"))
{
	print "image decoded all fine.\n";
} else {
	print "something went wrong ...\n";
	exit;
}

if (ExactImage::encodeImageFile ($image, "test.jpg", 80, ""))
{
        print "image written all fine.\n";
} else {
        print "something went wrong writing the image ...\n";
        exit;
}

# advanced use, use in memory locations
my $image_bits=`cat testsuite/281-4.2.04.tif`;

if (ExactImage::decodeImage ($image, $image_bits))
{
        print "image read from RAM.\n";
} else {
        print "something went wrong decoding the RAM\n";
        exit;
}

# image properties

print "Width: " . ExactImage::imageWidth ($image) . "\n";
print "Height: " . ExactImage::imageHeight ($image) . "\n";
print "Xres: " . ExactImage::imageXres ($image) . "\n";
print "Yres: " . ExactImage::imageYres ($image) . "\n";

print "Channels: " . ExactImage::imageChannels ($image) . "\n";
print "Channel depth: " . ExactImage::imageChannelDepth ($image). "\n";

# setable as well

ExactImage::imageSetXres ($image, 144);
ExactImage::imageSetYres ($image, 144);

print "Xres: " . ExactImage::imageXres ($image) . "\n";
print "Yres: " . ExactImage::imageYres ($image) . "\n";

# image data manipulation
ExactImage::imageRotate ($image, 90);
ExactImage::imageScale ($image, 4);
ExactImage::imageBoxScale ($image, .5);

$image_bits = ExactImage::encodeImage ($image, "jpeg", 80, "");
print "size: " . length($image_bits) . "\n";

if (length($image_bits) > 0)
{
        print "image encoded all fine.\n";
} else {
        print "something went wrong encoding the image into RAM\n";
        exit;
}

# write the file to disc using Perl
open (IMG, ">perl.jpg");
print IMG $image_bits;
close IMG;

# complex all-in-one function
if (ExactImage::decodeImageFile ($image, "testsuite/281-4.2.04.tif"))
  {
    my $image_copy = ExactImage::copyImage ($image);

    ExactImage::imageOptimize2BW ($image, 0, 0, 170, 3, 2.1);
    ExactImage::encodeImageFile ($image, "optimize.tif", 0, "");

    my $is_empty = ExactImage::imageIsEmpty ($image, 0.02, 16);
    if ($is_empty) {
      print "Image is empty\n";
    } else {
      print "Image is not empty, too many pixels ...\n";
    }

    # the image is bw, now - but we still have a copy
    ExactImage::encodeImageFile ($image_copy, "copy.tif", 0, "");
    # and do not forget the free the copy, otherwise it is leaked
    ExactImage::deleteImage ($image_copy);
  }
else
  {
    printf "Error loading testsuite/deskew/01.tif\n";
  }

if (ExactImage::decodeImageFile ($image, "testsuite/empty-page/empty.tif"))
  {
    my $is_empty = ExactImage::imageIsEmpty ($image, 0.02, 16);
    if ($is_empty) {
      print "Image is empty\n";
    } else {
      print "Image is not empty, too many pixels ...\n";
    }
  }
else
  {
    printf "Error loading testsuite/empty-page/empty.tif\n";
  }

# barcode decoding

while (<testsuite/barcodes/Scan-001-4.tif>)
  {
    printf "looking for barcodes in $_\n";
    
    if (ExactImage::decodeImageFile ($image, "$_"))
      {
	my $barcodes =
          ExactImage::imageDecodeBarcodes ($image,
	  				   "code39|CODE128|CODE25|EAN13|EAN8|UPCA|UPCE",
					   3, # min length
					   10); # max length
          for (my $i;$i< scalar(@$barcodes);$i+=2) {
            print "@$barcodes[$i] @$barcodes[$i+1]\n";
          }
      }
    else
      {
	printf "Error loading $_\n";
      }
  }

# we do not want to leak memory, always delete the image
# when you are done with it!
ExactImage::deleteImage ($image);

print "ok, here the example ends (for now) ...\n";