Skip to content

Commit dbd7c50

Browse files
author
Evgeniy Sidenko
committed
Updated upto 23.8
1 parent f984472 commit dbd7c50

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

Examples/data/jpeg/input.jpg

370 KB
Loading

Examples/data/png/src.png

1.6 MB
Loading

Examples/src/drawingandformattingimages/GraphicsMeasureString.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def get_data_root_dir_local():
1616

1717
# Example code:
1818
print("Running example GraphicsMeasureString")
19-
data_dir = os.path.join(get_data_root_dir(), "gif")
20-
filepath = os.path.join(data_dir, "ezgif.com-gif-maker(1)___.gif")
19+
data_dir = os.path.join(get_data_root_dir(), "jpeg")
20+
filepath = os.path.join(data_dir, "input.jpg")
2121
with Image.load(filepath) as backgound_image:
2222
gr = Graphics(backgound_image)
2323
format_ = StringFormat()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from aspose.imaging import Image, RasterImage
2+
from aspose.imaging.magicwand import *
3+
from aspose.imaging.magicwand.imagemasks import *
4+
from aspose.pycore import as_of
5+
import os
6+
7+
# Initialization
8+
def get_data_root_dir_local():
9+
if 'BASE_DIR' in os.environ:
10+
return os.environ["BASE_DIR"]
11+
return "."
12+
13+
14+
if 'get_data_root_dir' not in dir():
15+
get_data_root_dir = get_data_root_dir_local
16+
17+
if 'get_output_dir' not in dir():
18+
get_output_dir = get_data_root_dir_local
19+
20+
# Example code:
21+
# The path to the documents directory.
22+
data_dir = os.path.join(get_data_root_dir(), 'png')
23+
output_path = os.path.join(get_output_dir(), "result.png")
24+
25+
with as_of(Image.load(os.path.join(data_dir, "src.png")), RasterImage) as image:
26+
wand_settings = MagicWandSettings(1482, 346)
27+
wand_settings.threshold = 69
28+
feather_settings = FeatheringSettings()
29+
feather_settings.size = 3
30+
31+
# Create a new mask using magic wand tool based on tone and color of pixel {845, 128}
32+
wand_tool = MagicWandTool.select(image, MagicWandSettings(845, 128))
33+
# Union the existing mask with the specified one created by magic wand tool
34+
wand_tool.union(MagicWandSettings(416, 387))
35+
# Invert the existing mask
36+
wand_tool.invert()
37+
# Subtract the specified mask created by magic wand tool from the existing one
38+
wand_tool.subtract(wand_settings)
39+
# Subtract four specified rectangle masks from the existing mask one by one
40+
wand_tool.subtract(RectangleMask(0, 0, 800, 150))\
41+
.subtract(RectangleMask(0, 380, 600, 220))\
42+
.subtract(RectangleMask(930, 520, 110, 40))\
43+
.subtract(RectangleMask(1370, 400, 120, 200))
44+
# Feather mask with specified settings
45+
wand_tool.get_feathered(feather_settings)
46+
# Apply mask to the image
47+
wand_tool.apply()
48+
image.save(output_path)
49+
50+
if 'SAVE_OUTPUT' not in os.environ:
51+
os.remove(output_path)

Examples/src/modifyingandconvertingimages/PixelPerfectTextAlignment.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def get_data_root_dir_local():
1919

2020
# Example code:
2121
# The path to the documents directory.
22-
data_dir = os.path.join(get_data_root_dir(), 'cdr')
22+
data_dir = os.path.join(get_output_dir(), 'cdr')
2323

2424
print("Running example PixelPerfectTextAlignment")
2525

@@ -55,13 +55,13 @@ def draw_string(base_folder, align):
5555

5656
if align == "Left":
5757
alignment = StringAlignment.NEAR
58-
line_x = round(x)
58+
line_x = int(x)
5959
elif align == "Center":
6060
alignment = StringAlignment.CENTER
61-
line_x = round(x + w / 2.0)
61+
line_x = int(x + w // 2)
6262
elif align == "Right":
6363
alignment = StringAlignment.FAR
64-
line_x = x + w
64+
line_x = int(x + w)
6565

6666
string_format = StringFormat(StringFormatFlags.EXACT_ALIGNMENT)
6767
string_format.alignment = alignment
@@ -74,9 +74,9 @@ def draw_string(base_folder, align):
7474
RectangleF(x, y, w, s.height), string_format)
7575
y += s.height
7676

77-
graphics.draw_line(pen, Point(x, y), Point(x + w, y))
77+
graphics.draw_line(pen, Point(int(x), int(y)), Point(int(x + w), int(y)))
7878

79-
graphics.draw_line(pen, Point(line_x, 0), Point(line_x, y))
79+
graphics.draw_line(pen, Point(line_x, 0), Point(line_x, int(y)))
8080
# save all changes.
8181
image.save(output_file_name)
8282

0 commit comments

Comments
 (0)