File: test.py

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 (71 lines) | stat: -rw-r--r-- 1,700 bytes parent folder | download | duplicates (3)
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
# ExactImage Python Example
# Copyright (C) 2008 - 2010 Rene Rebe, ExactCODE GmbH

import sys
sys.path.append('./objdir/api/python')

import ExactImage
image = ExactImage.newImage()

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

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

# advanced use, use in memory locations
f = open("testsuite/281-4.2.04.tif", "rb")
try:
    image_bits = f.read()

finally:
    f.close()

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


# image properties

print("Width: %u" % ExactImage.imageWidth (image))
print("Height: %u" % ExactImage.imageHeight (image))
print("Xres: %u" % ExactImage.imageXres (image))
print("Yres: %u" % ExactImage.imageYres (image))

print("Channels: %u" % ExactImage.imageChannels (image))
print("Channel depth: %u" % ExactImage.imageChannelDepth (image))

# setable as well

ExactImage.imageSetXres (image, 144);
ExactImage.imageSetYres (image, 144);

print("Xres: %u" % ExactImage.imageXres (image))
print("Yres: %u" % ExactImage.imageYres (image))

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

image_bits = ExactImage.encodeImage (image, "jpeg", 80, "")
print("size: %u" % len(image_bits))

f = open("python.jpg", "wb")
try:
    image_bits = f.write(image_bits)

finally:
    f.close()


ExactImage.deleteImage(image)