bitaqa 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bitaqa-0.1.0/LICENSE +21 -0
- bitaqa-0.1.0/PKG-INFO +107 -0
- bitaqa-0.1.0/README.md +73 -0
- bitaqa-0.1.0/pyproject.toml +63 -0
- bitaqa-0.1.0/setup.cfg +4 -0
- bitaqa-0.1.0/src/bitaqa/__init__.py +7 -0
- bitaqa-0.1.0/src/bitaqa/assets/Cairo-OFL.txt +93 -0
- bitaqa-0.1.0/src/bitaqa/assets/Cairo.ttf +0 -0
- bitaqa-0.1.0/src/bitaqa/cli.py +68 -0
- bitaqa-0.1.0/src/bitaqa/core.py +255 -0
- bitaqa-0.1.0/src/bitaqa/py.typed +0 -0
- bitaqa-0.1.0/src/bitaqa.egg-info/PKG-INFO +107 -0
- bitaqa-0.1.0/src/bitaqa.egg-info/SOURCES.txt +16 -0
- bitaqa-0.1.0/src/bitaqa.egg-info/dependency_links.txt +1 -0
- bitaqa-0.1.0/src/bitaqa.egg-info/entry_points.txt +2 -0
- bitaqa-0.1.0/src/bitaqa.egg-info/requires.txt +3 -0
- bitaqa-0.1.0/src/bitaqa.egg-info/top_level.txt +1 -0
- bitaqa-0.1.0/tests/test_bitaqa.py +105 -0
bitaqa-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mahmoud El-Beheiry
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
bitaqa-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bitaqa
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Turn Arabic text into beautiful, shareable image cards — correct Arabic shaping and RTL layout, ready for social media
|
|
5
|
+
Author: Mahmoud El-Beheiry
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/baselprof2020/bitaqa
|
|
8
|
+
Project-URL: Repository, https://github.com/baselprof2020/bitaqa
|
|
9
|
+
Project-URL: Issues, https://github.com/baselprof2020/bitaqa/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/baselprof2020/bitaqa/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: arabic,image,card,social-media,pillow,rtl,text-to-image
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Natural Language :: Arabic
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
25
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: Pillow>=9.0
|
|
31
|
+
Requires-Dist: arabic-reshaper>=3.0
|
|
32
|
+
Requires-Dist: python-bidi>=0.4
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# bitaqa (بطاقة)
|
|
36
|
+
|
|
37
|
+
Turn Arabic text — a quote, an announcement, a shop offer — into a
|
|
38
|
+
**beautifully designed PNG card**, ready to share on Facebook, WhatsApp,
|
|
39
|
+
Instagram or anywhere else. Arabic letters are shaped and laid out
|
|
40
|
+
right-to-left correctly, every time.
|
|
41
|
+
|
|
42
|
+

|
|
43
|
+
|
|
44
|
+
[اقرأني بالعربية](README.ar.md)
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
pip install bitaqa
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from bitaqa import make_card
|
|
56
|
+
|
|
57
|
+
make_card(
|
|
58
|
+
"خصم ٢٥٪ على كل منتجات الألبان",
|
|
59
|
+
output="offer.png",
|
|
60
|
+
theme="midnight",
|
|
61
|
+
size="post",
|
|
62
|
+
subtitle="البحيرى ماركت",
|
|
63
|
+
)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`make_card()` returns a PIL `Image` and saves it when `output` is given.
|
|
67
|
+
|
|
68
|
+
## Command line
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
bitaqa "خصم ٢٥٪ على كل منتجات الألبان" -o offer.png --theme midnight --subtitle "البحيرى ماركت"
|
|
72
|
+
bitaqa "خير الكلام ما قلّ ودلّ" -o quote.png --theme teal --subtitle "حكمة عربية"
|
|
73
|
+
bitaqa "أهلاً وسهلاً بكم" -o story.png --theme sunset --size story
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Sizes
|
|
77
|
+
|
|
78
|
+
| Name | Dimensions | Good for |
|
|
79
|
+
|---------|------------|------------------------------|
|
|
80
|
+
| `post` | 1080×1080 | Feed posts (Facebook, X, …) |
|
|
81
|
+
| `story` | 1080×1920 | Stories / status |
|
|
82
|
+
| `wide` | 1200×627 | Link previews, covers |
|
|
83
|
+
|
|
84
|
+
## Themes
|
|
85
|
+
|
|
86
|
+
| Name | Look |
|
|
87
|
+
|------------|----------------------------------------|
|
|
88
|
+
| `midnight` | Deep navy gradient, gold text |
|
|
89
|
+
| `teal` | Deep teal gradient, cream text |
|
|
90
|
+
| `sunset` | Purple-to-orange gradient, white text |
|
|
91
|
+
| `sand` | Light beige, dark brown text |
|
|
92
|
+
|
|
93
|
+
## Features
|
|
94
|
+
|
|
95
|
+
- Correct Arabic shaping (`arabic-reshaper`) and RTL layout (`python-bidi`)
|
|
96
|
+
- Bundled [Cairo](https://github.com/Gue3bara/Cairo) font (SIL OFL 1.1) —
|
|
97
|
+
no font setup needed
|
|
98
|
+
- Automatic word wrapping and font-size shrink so long text always fits
|
|
99
|
+
- Optional subtitle line (shop name, author, …) with an accent divider
|
|
100
|
+
- Vertical gradient backgrounds with a soft decorative touch
|
|
101
|
+
- Library API + CLI, typed, Python ≥ 3.9
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT — see [LICENSE](LICENSE). Copyright (c) 2026 Mahmoud El-Beheiry.
|
|
106
|
+
The bundled Cairo font is licensed under the SIL Open Font License 1.1
|
|
107
|
+
(see `src/bitaqa/assets/Cairo-OFL.txt`).
|
bitaqa-0.1.0/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# bitaqa (بطاقة)
|
|
2
|
+
|
|
3
|
+
Turn Arabic text — a quote, an announcement, a shop offer — into a
|
|
4
|
+
**beautifully designed PNG card**, ready to share on Facebook, WhatsApp,
|
|
5
|
+
Instagram or anywhere else. Arabic letters are shaped and laid out
|
|
6
|
+
right-to-left correctly, every time.
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
[اقرأني بالعربية](README.ar.md)
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
pip install bitaqa
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from bitaqa import make_card
|
|
22
|
+
|
|
23
|
+
make_card(
|
|
24
|
+
"خصم ٢٥٪ على كل منتجات الألبان",
|
|
25
|
+
output="offer.png",
|
|
26
|
+
theme="midnight",
|
|
27
|
+
size="post",
|
|
28
|
+
subtitle="البحيرى ماركت",
|
|
29
|
+
)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`make_card()` returns a PIL `Image` and saves it when `output` is given.
|
|
33
|
+
|
|
34
|
+
## Command line
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
bitaqa "خصم ٢٥٪ على كل منتجات الألبان" -o offer.png --theme midnight --subtitle "البحيرى ماركت"
|
|
38
|
+
bitaqa "خير الكلام ما قلّ ودلّ" -o quote.png --theme teal --subtitle "حكمة عربية"
|
|
39
|
+
bitaqa "أهلاً وسهلاً بكم" -o story.png --theme sunset --size story
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Sizes
|
|
43
|
+
|
|
44
|
+
| Name | Dimensions | Good for |
|
|
45
|
+
|---------|------------|------------------------------|
|
|
46
|
+
| `post` | 1080×1080 | Feed posts (Facebook, X, …) |
|
|
47
|
+
| `story` | 1080×1920 | Stories / status |
|
|
48
|
+
| `wide` | 1200×627 | Link previews, covers |
|
|
49
|
+
|
|
50
|
+
## Themes
|
|
51
|
+
|
|
52
|
+
| Name | Look |
|
|
53
|
+
|------------|----------------------------------------|
|
|
54
|
+
| `midnight` | Deep navy gradient, gold text |
|
|
55
|
+
| `teal` | Deep teal gradient, cream text |
|
|
56
|
+
| `sunset` | Purple-to-orange gradient, white text |
|
|
57
|
+
| `sand` | Light beige, dark brown text |
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
|
|
61
|
+
- Correct Arabic shaping (`arabic-reshaper`) and RTL layout (`python-bidi`)
|
|
62
|
+
- Bundled [Cairo](https://github.com/Gue3bara/Cairo) font (SIL OFL 1.1) —
|
|
63
|
+
no font setup needed
|
|
64
|
+
- Automatic word wrapping and font-size shrink so long text always fits
|
|
65
|
+
- Optional subtitle line (shop name, author, …) with an accent divider
|
|
66
|
+
- Vertical gradient backgrounds with a soft decorative touch
|
|
67
|
+
- Library API + CLI, typed, Python ≥ 3.9
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT — see [LICENSE](LICENSE). Copyright (c) 2026 Mahmoud El-Beheiry.
|
|
72
|
+
The bundled Cairo font is licensed under the SIL Open Font License 1.1
|
|
73
|
+
(see `src/bitaqa/assets/Cairo-OFL.txt`).
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "bitaqa"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Turn Arabic text into beautiful, shareable image cards — correct Arabic shaping and RTL layout, ready for social media"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Mahmoud El-Beheiry" },
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"arabic",
|
|
17
|
+
"image",
|
|
18
|
+
"card",
|
|
19
|
+
"social-media",
|
|
20
|
+
"pillow",
|
|
21
|
+
"rtl",
|
|
22
|
+
"text-to-image",
|
|
23
|
+
]
|
|
24
|
+
classifiers = [
|
|
25
|
+
"Development Status :: 4 - Beta",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"Intended Audience :: End Users/Desktop",
|
|
28
|
+
"License :: OSI Approved :: MIT License",
|
|
29
|
+
"Natural Language :: Arabic",
|
|
30
|
+
"Operating System :: OS Independent",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3.9",
|
|
33
|
+
"Programming Language :: Python :: 3.10",
|
|
34
|
+
"Programming Language :: Python :: 3.11",
|
|
35
|
+
"Programming Language :: Python :: 3.12",
|
|
36
|
+
"Programming Language :: Python :: 3.13",
|
|
37
|
+
"Topic :: Multimedia :: Graphics",
|
|
38
|
+
"Topic :: Text Processing :: Linguistic",
|
|
39
|
+
"Typing :: Typed",
|
|
40
|
+
]
|
|
41
|
+
dependencies = [
|
|
42
|
+
"Pillow>=9.0",
|
|
43
|
+
"arabic-reshaper>=3.0",
|
|
44
|
+
"python-bidi>=0.4",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[project.urls]
|
|
48
|
+
Homepage = "https://github.com/baselprof2020/bitaqa"
|
|
49
|
+
Repository = "https://github.com/baselprof2020/bitaqa"
|
|
50
|
+
Issues = "https://github.com/baselprof2020/bitaqa/issues"
|
|
51
|
+
Changelog = "https://github.com/baselprof2020/bitaqa/blob/main/CHANGELOG.md"
|
|
52
|
+
|
|
53
|
+
[project.scripts]
|
|
54
|
+
bitaqa = "bitaqa.cli:main"
|
|
55
|
+
|
|
56
|
+
[tool.setuptools.packages.find]
|
|
57
|
+
where = ["src"]
|
|
58
|
+
|
|
59
|
+
[tool.setuptools.package-data]
|
|
60
|
+
bitaqa = ["py.typed", "assets/*.ttf", "assets/*.txt"]
|
|
61
|
+
|
|
62
|
+
[tool.pytest.ini_options]
|
|
63
|
+
testpaths = ["tests"]
|
bitaqa-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2009 The Cairo Project Authors (https://github.com/Gue3bara/Cairo)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Command-line interface for bitaqa."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
from .core import SIZES, THEMES, make_card
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
12
|
+
parser = argparse.ArgumentParser(
|
|
13
|
+
prog="bitaqa",
|
|
14
|
+
description="Turn Arabic text into a beautifully designed PNG card.",
|
|
15
|
+
)
|
|
16
|
+
parser.add_argument("text", help="the Arabic text to put on the card")
|
|
17
|
+
parser.add_argument(
|
|
18
|
+
"-o",
|
|
19
|
+
"--output",
|
|
20
|
+
default="card.png",
|
|
21
|
+
help="output PNG path (default: card.png)",
|
|
22
|
+
)
|
|
23
|
+
parser.add_argument(
|
|
24
|
+
"--theme",
|
|
25
|
+
default="midnight",
|
|
26
|
+
choices=sorted(THEMES),
|
|
27
|
+
help="colour theme (default: midnight)",
|
|
28
|
+
)
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
"--size",
|
|
31
|
+
default="post",
|
|
32
|
+
choices=sorted(SIZES),
|
|
33
|
+
help="card size (default: post)",
|
|
34
|
+
)
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
"--subtitle",
|
|
37
|
+
default=None,
|
|
38
|
+
help="optional smaller line under the main text (e.g. a shop name)",
|
|
39
|
+
)
|
|
40
|
+
parser.add_argument(
|
|
41
|
+
"--font-size",
|
|
42
|
+
type=int,
|
|
43
|
+
default=None,
|
|
44
|
+
help="starting font size (still shrinks automatically to fit)",
|
|
45
|
+
)
|
|
46
|
+
return parser
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def main(argv=None) -> int:
|
|
50
|
+
args = build_parser().parse_args(argv)
|
|
51
|
+
try:
|
|
52
|
+
img = make_card(
|
|
53
|
+
args.text,
|
|
54
|
+
output=args.output,
|
|
55
|
+
theme=args.theme,
|
|
56
|
+
size=args.size,
|
|
57
|
+
subtitle=args.subtitle,
|
|
58
|
+
font_size=args.font_size,
|
|
59
|
+
)
|
|
60
|
+
except (ValueError, OSError) as exc:
|
|
61
|
+
print(f"bitaqa: error: {exc}", file=sys.stderr)
|
|
62
|
+
return 1
|
|
63
|
+
print(f"Saved {args.output} ({img.size[0]}x{img.size[1]})")
|
|
64
|
+
return 0
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"""Core rendering engine for bitaqa — Arabic text cards.
|
|
2
|
+
|
|
3
|
+
Turns Arabic text into a polished PNG card with correct letter shaping and
|
|
4
|
+
right-to-left layout — natively via libraqm/HarfBuzz when Pillow provides
|
|
5
|
+
it, otherwise via arabic-reshaper + python-bidi — drawn with Pillow using
|
|
6
|
+
the bundled Cairo font.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import io
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from importlib import resources
|
|
14
|
+
|
|
15
|
+
import arabic_reshaper
|
|
16
|
+
from bidi.algorithm import get_display
|
|
17
|
+
from PIL import Image, ImageDraw, ImageFilter, ImageFont, features
|
|
18
|
+
|
|
19
|
+
#: True when Pillow was built with libraqm: HarfBuzz then shapes Arabic and
|
|
20
|
+
#: applies the bidi algorithm natively, which modern fonts (that ship no
|
|
21
|
+
#: legacy presentation-form glyphs) require. Without raqm we fall back to
|
|
22
|
+
#: arabic-reshaper + python-bidi.
|
|
23
|
+
_HAS_RAQM = features.check("raqm")
|
|
24
|
+
_TEXT_KWARGS = {"direction": "rtl", "language": "ar"} if _HAS_RAQM else {}
|
|
25
|
+
|
|
26
|
+
__all__ = ["SIZES", "THEMES", "Theme", "make_card", "shape_text", "wrap_text"]
|
|
27
|
+
|
|
28
|
+
#: Named canvas sizes as (width, height) in pixels.
|
|
29
|
+
SIZES = {
|
|
30
|
+
"post": (1080, 1080),
|
|
31
|
+
"story": (1080, 1920),
|
|
32
|
+
"wide": (1200, 627),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass(frozen=True)
|
|
37
|
+
class Theme:
|
|
38
|
+
"""A card colour theme (all colours are RGB tuples)."""
|
|
39
|
+
|
|
40
|
+
top: tuple
|
|
41
|
+
bottom: tuple
|
|
42
|
+
text: tuple
|
|
43
|
+
subtitle: tuple
|
|
44
|
+
accent: tuple
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
#: Built-in themes: vertical gradient background + text/accent colours.
|
|
48
|
+
THEMES = {
|
|
49
|
+
"midnight": Theme(
|
|
50
|
+
top=(10, 15, 38),
|
|
51
|
+
bottom=(27, 42, 82),
|
|
52
|
+
text=(245, 214, 123),
|
|
53
|
+
subtitle=(232, 227, 213),
|
|
54
|
+
accent=(212, 175, 55),
|
|
55
|
+
),
|
|
56
|
+
"teal": Theme(
|
|
57
|
+
top=(4, 47, 46),
|
|
58
|
+
bottom=(10, 104, 98),
|
|
59
|
+
text=(247, 243, 232),
|
|
60
|
+
subtitle=(217, 232, 226),
|
|
61
|
+
accent=(123, 211, 192),
|
|
62
|
+
),
|
|
63
|
+
"sunset": Theme(
|
|
64
|
+
top=(59, 17, 85),
|
|
65
|
+
bottom=(232, 93, 61),
|
|
66
|
+
text=(255, 255, 255),
|
|
67
|
+
subtitle=(255, 236, 220),
|
|
68
|
+
accent=(255, 209, 102),
|
|
69
|
+
),
|
|
70
|
+
"sand": Theme(
|
|
71
|
+
top=(247, 234, 210),
|
|
72
|
+
bottom=(236, 217, 184),
|
|
73
|
+
text=(74, 50, 32),
|
|
74
|
+
subtitle=(107, 79, 53),
|
|
75
|
+
accent=(176, 125, 60),
|
|
76
|
+
),
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_MIN_FONT_SIZE = 20
|
|
80
|
+
_FONT_WEIGHTS = {"main": 700, "subtitle": 600}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def shape_text(text: str) -> str:
|
|
84
|
+
"""Reshape Arabic letters and apply the bidi algorithm for display.
|
|
85
|
+
|
|
86
|
+
With libraqm available Pillow/HarfBuzz does this natively at draw time,
|
|
87
|
+
so the logical text is returned unchanged; otherwise the classic
|
|
88
|
+
arabic-reshaper + python-bidi pipeline is applied.
|
|
89
|
+
"""
|
|
90
|
+
if _HAS_RAQM:
|
|
91
|
+
return text
|
|
92
|
+
return get_display(arabic_reshaper.reshape(text))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _font_bytes() -> bytes:
|
|
96
|
+
return resources.files("bitaqa").joinpath("assets", "Cairo.ttf").read_bytes()
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _load_font(size: int, weight: int = 700) -> ImageFont.FreeTypeFont:
|
|
100
|
+
"""Load the bundled Cairo variable font at ``size`` and ``weight``."""
|
|
101
|
+
font = ImageFont.truetype(io.BytesIO(_font_bytes()), size)
|
|
102
|
+
try:
|
|
103
|
+
axes = font.get_variation_axes()
|
|
104
|
+
values = [axis["default"] for axis in axes]
|
|
105
|
+
for i, axis in enumerate(axes):
|
|
106
|
+
if axis["name"] in (b"Weight", "Weight"):
|
|
107
|
+
values[i] = weight
|
|
108
|
+
font.set_variation_by_axes(values)
|
|
109
|
+
except Exception:
|
|
110
|
+
pass # static-weight fallback: the default instance is fine
|
|
111
|
+
return font
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def wrap_text(draw: ImageDraw.ImageDraw, text: str, font, max_width: int) -> list:
|
|
115
|
+
"""Word-wrap logical-order ``text`` so every shaped line fits ``max_width``.
|
|
116
|
+
|
|
117
|
+
Explicit newlines in ``text`` are honoured. Returns shaped (display-order)
|
|
118
|
+
lines ready to draw.
|
|
119
|
+
"""
|
|
120
|
+
lines: list = []
|
|
121
|
+
for paragraph in text.split("\n"):
|
|
122
|
+
words = paragraph.split()
|
|
123
|
+
if not words:
|
|
124
|
+
continue
|
|
125
|
+
current = words[0]
|
|
126
|
+
for word in words[1:]:
|
|
127
|
+
candidate = f"{current} {word}"
|
|
128
|
+
if draw.textlength(shape_text(candidate), font=font) <= max_width:
|
|
129
|
+
current = candidate
|
|
130
|
+
else:
|
|
131
|
+
lines.append(shape_text(current))
|
|
132
|
+
current = word
|
|
133
|
+
lines.append(shape_text(current))
|
|
134
|
+
return lines
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _draw_text(draw, xy, line, font, fill):
|
|
138
|
+
"""Draw one prepared line, letting raqm shape/bidi it when available."""
|
|
139
|
+
draw.text(xy, line, font=font, fill=fill, anchor="ma", **_TEXT_KWARGS)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _gradient(size, top, bottom) -> Image.Image:
|
|
143
|
+
"""A vertical linear gradient image."""
|
|
144
|
+
width, height = size
|
|
145
|
+
img = Image.new("RGB", size)
|
|
146
|
+
draw = ImageDraw.Draw(img)
|
|
147
|
+
for y in range(height):
|
|
148
|
+
ratio = y / max(height - 1, 1)
|
|
149
|
+
color = tuple(round(top[i] + (bottom[i] - top[i]) * ratio) for i in range(3))
|
|
150
|
+
draw.line([(0, y), (width, y)], fill=color)
|
|
151
|
+
return img
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _decorate(img: Image.Image, theme: Theme) -> Image.Image:
|
|
155
|
+
"""Add soft translucent circles in the corners (subtle, blurred)."""
|
|
156
|
+
width, height = img.size
|
|
157
|
+
overlay = Image.new("RGBA", img.size, (0, 0, 0, 0))
|
|
158
|
+
draw = ImageDraw.Draw(overlay)
|
|
159
|
+
accent = theme.accent + (26,)
|
|
160
|
+
r = int(width * 0.32)
|
|
161
|
+
draw.ellipse([-r // 2, -r // 2, r, r], fill=accent)
|
|
162
|
+
draw.ellipse([width - r, height - r, width + r // 2, height + r // 2], fill=accent)
|
|
163
|
+
r2 = int(width * 0.16)
|
|
164
|
+
draw.ellipse([width - r2, -r2 // 2, width + r2 // 2, r2], fill=theme.accent + (18,))
|
|
165
|
+
overlay = overlay.filter(ImageFilter.GaussianBlur(radius=width * 0.03))
|
|
166
|
+
return Image.alpha_composite(img.convert("RGBA"), overlay)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _fit_text(draw, text, max_width, max_height, start_size):
|
|
170
|
+
"""Shrink the font from ``start_size`` until the wrapped text fits."""
|
|
171
|
+
size = start_size
|
|
172
|
+
while True:
|
|
173
|
+
font = _load_font(size, _FONT_WEIGHTS["main"])
|
|
174
|
+
lines = wrap_text(draw, text, font, max_width)
|
|
175
|
+
advance = int(size * 1.6)
|
|
176
|
+
if len(lines) * advance <= max_height or size <= _MIN_FONT_SIZE:
|
|
177
|
+
return font, lines, size, advance
|
|
178
|
+
size = max(_MIN_FONT_SIZE, size - 4)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def make_card(
|
|
182
|
+
text: str,
|
|
183
|
+
output=None,
|
|
184
|
+
*,
|
|
185
|
+
theme: str = "midnight",
|
|
186
|
+
size: str = "post",
|
|
187
|
+
subtitle: str = None,
|
|
188
|
+
font_size: int = None,
|
|
189
|
+
):
|
|
190
|
+
"""Render ``text`` as a designed card and return a PIL ``Image``.
|
|
191
|
+
|
|
192
|
+
Args:
|
|
193
|
+
text: Main Arabic text (may contain newlines and mixed digits).
|
|
194
|
+
output: Optional path to also save the PNG to.
|
|
195
|
+
theme: One of ``midnight``, ``teal``, ``sunset``, ``sand``.
|
|
196
|
+
size: One of ``post`` (1080×1080), ``story`` (1080×1920),
|
|
197
|
+
``wide`` (1200×627).
|
|
198
|
+
subtitle: Optional smaller line under the main text (e.g. a shop
|
|
199
|
+
name or an author).
|
|
200
|
+
font_size: Optional starting font size; it still shrinks to fit.
|
|
201
|
+
|
|
202
|
+
Raises:
|
|
203
|
+
ValueError: If the text is empty or theme/size names are unknown.
|
|
204
|
+
"""
|
|
205
|
+
if not text or not text.strip():
|
|
206
|
+
raise ValueError("text must not be empty")
|
|
207
|
+
if theme not in THEMES:
|
|
208
|
+
raise ValueError(f"unknown theme {theme!r}; choose from {sorted(THEMES)}")
|
|
209
|
+
if size not in SIZES:
|
|
210
|
+
raise ValueError(f"unknown size {size!r}; choose from {sorted(SIZES)}")
|
|
211
|
+
|
|
212
|
+
colors = THEMES[theme]
|
|
213
|
+
canvas = SIZES[size]
|
|
214
|
+
width, height = canvas
|
|
215
|
+
|
|
216
|
+
img = _decorate(_gradient(canvas, colors.top, colors.bottom), colors)
|
|
217
|
+
draw = ImageDraw.Draw(img)
|
|
218
|
+
|
|
219
|
+
max_text_width = int(width * 0.84)
|
|
220
|
+
max_text_height = int(height * (0.52 if subtitle else 0.62))
|
|
221
|
+
start_size = font_size or int(width * 0.105)
|
|
222
|
+
font, lines, main_size, advance = _fit_text(
|
|
223
|
+
draw, text, max_text_width, max_text_height, start_size
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
main_block_h = len(lines) * advance
|
|
227
|
+
gap = int(main_size * 0.45)
|
|
228
|
+
line_h = max(4, int(main_size * 0.07))
|
|
229
|
+
sub_size = max(24, int(main_size * 0.42))
|
|
230
|
+
sub_font = _load_font(sub_size, _FONT_WEIGHTS["subtitle"]) if subtitle else None
|
|
231
|
+
sub_block_h = (gap + line_h + gap + int(sub_size * 1.6)) if subtitle else 0
|
|
232
|
+
|
|
233
|
+
total_h = main_block_h + sub_block_h
|
|
234
|
+
y = (height - total_h) // 2
|
|
235
|
+
cx = width // 2
|
|
236
|
+
|
|
237
|
+
for line in lines:
|
|
238
|
+
_draw_text(draw, (cx, y), line, font, colors.text)
|
|
239
|
+
y += advance
|
|
240
|
+
|
|
241
|
+
if subtitle:
|
|
242
|
+
y += gap
|
|
243
|
+
line_w = int(width * 0.18)
|
|
244
|
+
draw.rounded_rectangle(
|
|
245
|
+
[cx - line_w // 2, y, cx + line_w // 2, y + line_h],
|
|
246
|
+
radius=line_h // 2,
|
|
247
|
+
fill=colors.accent,
|
|
248
|
+
)
|
|
249
|
+
y += line_h + gap
|
|
250
|
+
_draw_text(draw, (cx, y), shape_text(subtitle), sub_font, colors.subtitle)
|
|
251
|
+
|
|
252
|
+
result = img.convert("RGB")
|
|
253
|
+
if output is not None:
|
|
254
|
+
result.save(str(output), format="PNG")
|
|
255
|
+
return result
|
|
File without changes
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bitaqa
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Turn Arabic text into beautiful, shareable image cards — correct Arabic shaping and RTL layout, ready for social media
|
|
5
|
+
Author: Mahmoud El-Beheiry
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/baselprof2020/bitaqa
|
|
8
|
+
Project-URL: Repository, https://github.com/baselprof2020/bitaqa
|
|
9
|
+
Project-URL: Issues, https://github.com/baselprof2020/bitaqa/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/baselprof2020/bitaqa/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: arabic,image,card,social-media,pillow,rtl,text-to-image
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Natural Language :: Arabic
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
25
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: Pillow>=9.0
|
|
31
|
+
Requires-Dist: arabic-reshaper>=3.0
|
|
32
|
+
Requires-Dist: python-bidi>=0.4
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# bitaqa (بطاقة)
|
|
36
|
+
|
|
37
|
+
Turn Arabic text — a quote, an announcement, a shop offer — into a
|
|
38
|
+
**beautifully designed PNG card**, ready to share on Facebook, WhatsApp,
|
|
39
|
+
Instagram or anywhere else. Arabic letters are shaped and laid out
|
|
40
|
+
right-to-left correctly, every time.
|
|
41
|
+
|
|
42
|
+

|
|
43
|
+
|
|
44
|
+
[اقرأني بالعربية](README.ar.md)
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
pip install bitaqa
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from bitaqa import make_card
|
|
56
|
+
|
|
57
|
+
make_card(
|
|
58
|
+
"خصم ٢٥٪ على كل منتجات الألبان",
|
|
59
|
+
output="offer.png",
|
|
60
|
+
theme="midnight",
|
|
61
|
+
size="post",
|
|
62
|
+
subtitle="البحيرى ماركت",
|
|
63
|
+
)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`make_card()` returns a PIL `Image` and saves it when `output` is given.
|
|
67
|
+
|
|
68
|
+
## Command line
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
bitaqa "خصم ٢٥٪ على كل منتجات الألبان" -o offer.png --theme midnight --subtitle "البحيرى ماركت"
|
|
72
|
+
bitaqa "خير الكلام ما قلّ ودلّ" -o quote.png --theme teal --subtitle "حكمة عربية"
|
|
73
|
+
bitaqa "أهلاً وسهلاً بكم" -o story.png --theme sunset --size story
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Sizes
|
|
77
|
+
|
|
78
|
+
| Name | Dimensions | Good for |
|
|
79
|
+
|---------|------------|------------------------------|
|
|
80
|
+
| `post` | 1080×1080 | Feed posts (Facebook, X, …) |
|
|
81
|
+
| `story` | 1080×1920 | Stories / status |
|
|
82
|
+
| `wide` | 1200×627 | Link previews, covers |
|
|
83
|
+
|
|
84
|
+
## Themes
|
|
85
|
+
|
|
86
|
+
| Name | Look |
|
|
87
|
+
|------------|----------------------------------------|
|
|
88
|
+
| `midnight` | Deep navy gradient, gold text |
|
|
89
|
+
| `teal` | Deep teal gradient, cream text |
|
|
90
|
+
| `sunset` | Purple-to-orange gradient, white text |
|
|
91
|
+
| `sand` | Light beige, dark brown text |
|
|
92
|
+
|
|
93
|
+
## Features
|
|
94
|
+
|
|
95
|
+
- Correct Arabic shaping (`arabic-reshaper`) and RTL layout (`python-bidi`)
|
|
96
|
+
- Bundled [Cairo](https://github.com/Gue3bara/Cairo) font (SIL OFL 1.1) —
|
|
97
|
+
no font setup needed
|
|
98
|
+
- Automatic word wrapping and font-size shrink so long text always fits
|
|
99
|
+
- Optional subtitle line (shop name, author, …) with an accent divider
|
|
100
|
+
- Vertical gradient backgrounds with a soft decorative touch
|
|
101
|
+
- Library API + CLI, typed, Python ≥ 3.9
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT — see [LICENSE](LICENSE). Copyright (c) 2026 Mahmoud El-Beheiry.
|
|
106
|
+
The bundled Cairo font is licensed under the SIL Open Font License 1.1
|
|
107
|
+
(see `src/bitaqa/assets/Cairo-OFL.txt`).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/bitaqa/__init__.py
|
|
5
|
+
src/bitaqa/cli.py
|
|
6
|
+
src/bitaqa/core.py
|
|
7
|
+
src/bitaqa/py.typed
|
|
8
|
+
src/bitaqa.egg-info/PKG-INFO
|
|
9
|
+
src/bitaqa.egg-info/SOURCES.txt
|
|
10
|
+
src/bitaqa.egg-info/dependency_links.txt
|
|
11
|
+
src/bitaqa.egg-info/entry_points.txt
|
|
12
|
+
src/bitaqa.egg-info/requires.txt
|
|
13
|
+
src/bitaqa.egg-info/top_level.txt
|
|
14
|
+
src/bitaqa/assets/Cairo-OFL.txt
|
|
15
|
+
src/bitaqa/assets/Cairo.ttf
|
|
16
|
+
tests/test_bitaqa.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bitaqa
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""Tests for bitaqa."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from PIL import Image, ImageDraw
|
|
5
|
+
|
|
6
|
+
from bitaqa import SIZES, THEMES, make_card, shape_text, wrap_text
|
|
7
|
+
from bitaqa.cli import main as cli_main
|
|
8
|
+
from bitaqa.core import _load_font
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_shape_text_produces_display_form():
|
|
12
|
+
from bitaqa.core import _HAS_RAQM
|
|
13
|
+
|
|
14
|
+
shaped = shape_text("سلام")
|
|
15
|
+
assert isinstance(shaped, str)
|
|
16
|
+
assert shaped # non-empty
|
|
17
|
+
if _HAS_RAQM:
|
|
18
|
+
# HarfBuzz shapes at draw time; logical text passes through.
|
|
19
|
+
assert shaped == "سلام"
|
|
20
|
+
else:
|
|
21
|
+
# Fallback pipeline maps letters to presentation forms (U+FExx).
|
|
22
|
+
assert any("\ufe80" <= ch <= "\ufefc" for ch in shaped)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_shape_text_handles_mixed_digits():
|
|
26
|
+
shaped = shape_text("خصم ٢٥٪ اليوم")
|
|
27
|
+
assert shaped
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_wrap_text_wraps_long_text():
|
|
31
|
+
img = Image.new("RGB", (400, 400))
|
|
32
|
+
draw = ImageDraw.Draw(img)
|
|
33
|
+
font = _load_font(60)
|
|
34
|
+
lines = wrap_text(draw, "هذا نص عربي طويل يحتاج إلى التفاف على أكثر من سطر واحد", font, 300)
|
|
35
|
+
assert len(lines) > 1
|
|
36
|
+
for line in lines:
|
|
37
|
+
assert draw.textlength(line, font=font) <= 300 + 1
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_wrap_text_respects_newlines():
|
|
41
|
+
img = Image.new("RGB", (1080, 1080))
|
|
42
|
+
draw = ImageDraw.Draw(img)
|
|
43
|
+
font = _load_font(60)
|
|
44
|
+
lines = wrap_text(draw, "سطر أول\nسطر ثانٍ", font, 900)
|
|
45
|
+
assert len(lines) == 2
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@pytest.mark.parametrize("size_name", sorted(SIZES))
|
|
49
|
+
def test_make_card_dimensions_for_each_size(size_name):
|
|
50
|
+
img = make_card("أهلاً وسهلاً بكم", size=size_name)
|
|
51
|
+
assert isinstance(img, Image.Image)
|
|
52
|
+
assert img.size == SIZES[size_name]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@pytest.mark.parametrize("theme_name", sorted(THEMES))
|
|
56
|
+
def test_make_card_each_theme(theme_name):
|
|
57
|
+
img = make_card("خير الكلام ما قلّ ودلّ", theme=theme_name)
|
|
58
|
+
assert img.size == (1080, 1080)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_make_card_saves_file(tmp_path):
|
|
62
|
+
out = tmp_path / "card.png"
|
|
63
|
+
img = make_card("عرض خاص", output=out, subtitle="البحيرى ماركت")
|
|
64
|
+
assert out.exists()
|
|
65
|
+
assert out.stat().st_size > 10_000
|
|
66
|
+
with Image.open(out) as saved:
|
|
67
|
+
assert saved.size == img.size
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_make_card_with_subtitle_and_long_text():
|
|
71
|
+
long_text = "هذا إعلان طويل جداً عن عروض كبيرة في المحل على جميع المنتجات الغذائية والألبان والأجبان بمناسبة الافتتاح الكبير"
|
|
72
|
+
img = make_card(long_text, subtitle="البحيرى ماركت")
|
|
73
|
+
assert img.size == (1080, 1080)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_make_card_rejects_empty_text():
|
|
77
|
+
with pytest.raises(ValueError):
|
|
78
|
+
make_card(" ")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_make_card_rejects_unknown_theme():
|
|
82
|
+
with pytest.raises(ValueError):
|
|
83
|
+
make_card("نص", theme="nope")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def test_make_card_rejects_unknown_size():
|
|
87
|
+
with pytest.raises(ValueError):
|
|
88
|
+
make_card("نص", size="huge")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_cli_smoke(tmp_path):
|
|
92
|
+
out = tmp_path / "cli.png"
|
|
93
|
+
rc = cli_main(["أهلاً وسهلاً بكم", "-o", str(out), "--theme", "teal", "--subtitle", "البحيرى ماركت"])
|
|
94
|
+
assert rc == 0
|
|
95
|
+
assert out.exists()
|
|
96
|
+
with Image.open(out) as saved:
|
|
97
|
+
assert saved.size == (1080, 1080)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_cli_story_size(tmp_path):
|
|
101
|
+
out = tmp_path / "story.png"
|
|
102
|
+
rc = cli_main(["أهلاً وسهلاً بكم", "-o", str(out), "--size", "story", "--theme", "sunset"])
|
|
103
|
+
assert rc == 0
|
|
104
|
+
with Image.open(out) as saved:
|
|
105
|
+
assert saved.size == (1080, 1920)
|