File: test-export-options.py

package info (click to toggle)
gimp 3.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 210,076 kB
  • sloc: ansic: 842,287; lisp: 10,761; python: 10,318; cpp: 7,238; perl: 4,355; sh: 1,043; xml: 963; yacc: 609; lex: 348; javascript: 150; makefile: 43
file content (34 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3

NEW_IMAGE_WIDTH=1920
NEW_IMAGE_HEIGHT=2001

image = Gimp.Image.new(NEW_IMAGE_WIDTH, NEW_IMAGE_HEIGHT, Gimp.ImageBaseType.RGB)
text_layer = Gimp.TextLayer.new(image, "hello world", Gimp.context_get_font(), 20, Gimp.Unit.point())
image.insert_layer(text_layer, None, 0)
text_layer = Gimp.TextLayer.new(image, "annyeong uju", Gimp.context_get_font(), 20, Gimp.Unit.point())
image.insert_layer(text_layer, None, 0)

images = Gimp.get_images()
layers = image.get_layers()
gimp_assert('Verify start state', len(images) == 1 and images[0] == image and len(layers) == 2)

options = Gimp.ExportOptions()
options.set_property ("capabilities",
                      Gimp.ExportCapabilities.CAN_HANDLE_RGB |
                      Gimp.ExportCapabilities.CAN_HANDLE_ALPHA)

delete, export_image = options.get_image(image)

gimp_assert('Gimp.ExportOptions.get_image() created a new image', delete == Gimp.ExportReturn.EXPORT and export_image != image)
export_layers = export_image.get_layers()
gimp_assert('The new image has a single layer', len(export_layers) == 1)

merged_layer = image.merge_visible_layers(Gimp.MergeType.CLIP_TO_IMAGE)
merged_layer.resize_to_image_size()

buffer1 = merged_layer.get_buffer()
buffer2 = export_layers[0].get_buffer()
l1 = buffer1.get(buffer1.get_extent(), 1.0, None, Gegl.AbyssPolicy.NONE)
l2 = buffer2.get(buffer2.get_extent(), 1.0, None, Gegl.AbyssPolicy.NONE)
gimp_assert("Compare export buffer with original image's merged buffer", l1 == l2)