Skip to content

Commit 21cde74

Browse files
author
Evgeniy Sidenko
committed
Updated upto 24.12
1 parent 6a83c20 commit 21cde74

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# GROUP: MODIFYING_AND_CONVERTING_IMAGES
2+
3+
import aspose.pycore as aspycore
4+
from aspose.imaging import Image, TextRenderingHint, SmoothingMode, SizeF, Rectangle
5+
from aspose.imaging.fileformats.opendocument import OdImage
6+
from aspose.imaging.imageoptions import VectorRasterizationOptions, PngOptions
7+
import os
8+
9+
10+
# Initialization
11+
def get_data_root_dir_local():
12+
if 'BASE_DIR' in os.environ:
13+
return os.environ["BASE_DIR"]
14+
return "."
15+
16+
17+
if 'get_data_root_dir' not in dir():
18+
get_data_root_dir = get_data_root_dir_local
19+
20+
if 'get_output_dir' not in dir():
21+
get_output_dir = get_data_root_dir_local
22+
23+
# Example code:
24+
print("Running example UnifyUsageOfCommonOperations")
25+
data_dir = os.path.join(get_data_root_dir(), 'cdr')
26+
file_name = "test.cdr"
27+
input_file_name = os.path.join(data_dir, file_name)
28+
output_file_name_png = os.path.join(get_output_dir(), "output.png")
29+
with Image.load(input_file_name) as image:
30+
if aspycore.is_assignable(image, OdImage):
31+
image.crop(Rectangle(92, 179, 260, 197))
32+
else:
33+
image.crop(Rectangle(88, 171, 250, 190))
34+
35+
vector_options = VectorRasterizationOptions()
36+
vector_options.page_size = aspycore.cast(SizeF, image.size)
37+
vector_options.text_rendering_hint = TextRenderingHint.SINGLE_BIT_PER_PIXEL
38+
vector_options.smoothing_mode = SmoothingMode.NONE
39+
png_options = PngOptions()
40+
png_options.vector_rasterization_options = vector_options
41+
image.save(output_file_name_png, png_options)
42+
43+
if 'SAVE_OUTPUT' not in os.environ:
44+
os.remove(output_file_name_png)
45+
46+
print("Finished example UnifyUsageOfCommonOperations")

0 commit comments

Comments
 (0)