Skip to content

Commit 4a95af1

Browse files
author
Evgeniy Sidenko
committed
Updated upto 23.9
Added the watermark removing example
1 parent dbd7c50 commit 4a95af1

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Examples/data/png/ball.png

539 KB
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from aspose.pycore import as_of
2+
from aspose.imaging import Image, GraphicsPath, Figure, RectangleF
3+
from aspose.imaging.shapes import EllipseShape
4+
from aspose.imaging.fileformats.png import PngImage
5+
from aspose.imaging.watermark import WatermarkRemover
6+
from aspose.imaging.watermark.options import ContentAwareFillWatermarkOptions
7+
import os
8+
9+
# Initialization
10+
def get_data_root_dir_local():
11+
if 'BASE_DIR' in os.environ:
12+
return os.environ["BASE_DIR"]
13+
return "."
14+
15+
16+
if 'get_data_root_dir' not in dir():
17+
get_data_root_dir = get_data_root_dir_local
18+
19+
20+
if 'get_output_dir' not in dir():
21+
get_output_dir = get_data_root_dir_local
22+
23+
24+
# Example code:
25+
# The path to the documents directory.
26+
data_dir = os.path.join(get_data_root_dir(), 'png')
27+
28+
imageFilePath = os.path.join(data_dir, "ball.png")
29+
output_path = os.path.join(get_output_dir(), "result.png")
30+
with Image.load(imageFilePath) as image:
31+
pngImage = as_of(image, PngImage)
32+
mask = GraphicsPath()
33+
firstFigure = Figure()
34+
firstFigure.add_shape(EllipseShape(RectangleF(350, 170, 570 - 350, 400 - 170)))
35+
mask.add_figure(firstFigure)
36+
options = ContentAwareFillWatermarkOptions(mask)
37+
options.max_painting_attempts = 4
38+
result = WatermarkRemover.paint_over(pngImage, options)
39+
result.save(output_path)
40+
41+
if 'SAVE_OUTPUT' not in os.environ:
42+
os.remove(output_path)

0 commit comments

Comments
 (0)