comic-ocr-reader 0.0.2__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.
- comic_ocr_reader-0.0.2/.gitignore +95 -0
- comic_ocr_reader-0.0.2/.idea/comic-ocr.iml +7 -0
- comic_ocr_reader-0.0.2/.idea/inspectionProfiles/Project_Default.xml +40 -0
- comic_ocr_reader-0.0.2/.idea/inspectionProfiles/profiles_settings.xml +6 -0
- comic_ocr_reader-0.0.2/.idea/misc.xml +7 -0
- comic_ocr_reader-0.0.2/.idea/vcs.xml +6 -0
- comic_ocr_reader-0.0.2/LICENSE.MD +21 -0
- comic_ocr_reader-0.0.2/LICENSE.md +21 -0
- comic_ocr_reader-0.0.2/PKG-INFO +56 -0
- comic_ocr_reader-0.0.2/README.md +37 -0
- comic_ocr_reader-0.0.2/pyproject.toml +30 -0
- comic_ocr_reader-0.0.2/readme.md +37 -0
- comic_ocr_reader-0.0.2/requirements.txt +4 -0
- comic_ocr_reader-0.0.2/src/comic_ocr_reader/__init__.py +0 -0
- comic_ocr_reader-0.0.2/src/comic_ocr_reader/filepaths.py +3 -0
- comic_ocr_reader-0.0.2/src/comic_ocr_reader/functions/__init__.py +58 -0
- comic_ocr_reader-0.0.2/src/comic_ocr_reader/html_utils/__init__.py +111 -0
- comic_ocr_reader-0.0.2/src/comic_ocr_reader/html_utils/html_template.html +789 -0
- comic_ocr_reader-0.0.2/src/comic_ocr_reader/img_utils/__init__.py +64 -0
- comic_ocr_reader-0.0.2/src/comic_ocr_reader/main.py +103 -0
- comic_ocr_reader-0.0.2/tests/test.py +24 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Covers JetBrains IDEs: IntelliJ, GoLand, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
|
2
|
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
|
3
|
+
|
|
4
|
+
# User-specific stuff
|
|
5
|
+
.idea/**/workspace.xml
|
|
6
|
+
.idea/**/tasks.xml
|
|
7
|
+
.idea/**/usage.statistics.xml
|
|
8
|
+
.idea/**/dictionaries
|
|
9
|
+
.idea/**/shelf
|
|
10
|
+
|
|
11
|
+
# AWS User-specific
|
|
12
|
+
.idea/**/aws.xml
|
|
13
|
+
|
|
14
|
+
# Generated files
|
|
15
|
+
.idea/**/contentModel.xml
|
|
16
|
+
|
|
17
|
+
# Sensitive or high-churn files
|
|
18
|
+
.idea/**/dataSources/
|
|
19
|
+
.idea/**/dataSources.ids
|
|
20
|
+
.idea/**/dataSources.local.xml
|
|
21
|
+
.idea/**/sqlDataSources.xml
|
|
22
|
+
.idea/**/dynamic.xml
|
|
23
|
+
.idea/**/uiDesigner.xml
|
|
24
|
+
.idea/**/dbnavigator.xml
|
|
25
|
+
|
|
26
|
+
# Gradle
|
|
27
|
+
.idea/**/gradle.xml
|
|
28
|
+
.idea/**/libraries
|
|
29
|
+
|
|
30
|
+
# Gradle and Maven with auto-import
|
|
31
|
+
# When using Gradle or Maven with auto-import, you should exclude module files,
|
|
32
|
+
# since they will be recreated, and may cause churn. Uncomment if using
|
|
33
|
+
# auto-import.
|
|
34
|
+
# .idea/artifacts
|
|
35
|
+
# .idea/compiler.xml
|
|
36
|
+
# .idea/jarRepositories.xml
|
|
37
|
+
# .idea/modules.xml
|
|
38
|
+
# .idea/*.iml
|
|
39
|
+
# .idea/modules
|
|
40
|
+
# *.iml
|
|
41
|
+
# *.ipr
|
|
42
|
+
|
|
43
|
+
# CMake
|
|
44
|
+
cmake-build-*/
|
|
45
|
+
|
|
46
|
+
# Mongo Explorer plugin
|
|
47
|
+
.idea/**/mongoSettings.xml
|
|
48
|
+
|
|
49
|
+
# File-based project format
|
|
50
|
+
*.iws
|
|
51
|
+
|
|
52
|
+
# IntelliJ
|
|
53
|
+
out/
|
|
54
|
+
|
|
55
|
+
# mpeltonen/sbt-idea plugin
|
|
56
|
+
.idea_modules/
|
|
57
|
+
|
|
58
|
+
# JIRA plugin
|
|
59
|
+
atlassian-ide-plugin.xml
|
|
60
|
+
|
|
61
|
+
# Cursive Clojure plugin
|
|
62
|
+
.idea/replstate.xml
|
|
63
|
+
|
|
64
|
+
# SonarLint plugin
|
|
65
|
+
.idea/sonarlint/
|
|
66
|
+
# see https://community.sonarsource.com/t/is-the-file-idea-idea-idea-sonarlint-xml-intended-to-be-under-source-control/121119
|
|
67
|
+
.idea/sonarlint.xml
|
|
68
|
+
|
|
69
|
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
70
|
+
com_crashlytics_export_strings.xml
|
|
71
|
+
crashlytics.properties
|
|
72
|
+
crashlytics-build.properties
|
|
73
|
+
fabric.properties
|
|
74
|
+
|
|
75
|
+
# Editor-based HTTP Client
|
|
76
|
+
.idea/httpRequests
|
|
77
|
+
http-client.private.env.json
|
|
78
|
+
|
|
79
|
+
# Android studio 3.1+ serialized cache file
|
|
80
|
+
.idea/caches/build_file_checksums.ser
|
|
81
|
+
|
|
82
|
+
# Apifox Helper cache
|
|
83
|
+
.idea/.cache/.Apifox_Helper
|
|
84
|
+
.idea/ApifoxUploaderProjectSetting.xml
|
|
85
|
+
|
|
86
|
+
# Github Copilot persisted session migrations, see: https://github.com/microsoft/copilot-intellij-feedback/issues/712#issuecomment-3322062215
|
|
87
|
+
.idea/**/copilot.data.migration.*.xml
|
|
88
|
+
|
|
89
|
+
# ------------------------------------------------------
|
|
90
|
+
/src/test-pics
|
|
91
|
+
/src/outputs
|
|
92
|
+
/test-pics
|
|
93
|
+
/outputs
|
|
94
|
+
/temporary
|
|
95
|
+
/dist
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
|
2
|
+
<profile version="1.0">
|
|
3
|
+
<option name="myName" value="Project Default" />
|
|
4
|
+
<inspection_tool class="HtmlUnknownTag" enabled="true" level="WARNING" enabled_by_default="true">
|
|
5
|
+
<option name="myValues">
|
|
6
|
+
<value>
|
|
7
|
+
<list size="7">
|
|
8
|
+
<item index="0" class="java.lang.String" itemvalue="nobr" />
|
|
9
|
+
<item index="1" class="java.lang.String" itemvalue="noembed" />
|
|
10
|
+
<item index="2" class="java.lang.String" itemvalue="comment" />
|
|
11
|
+
<item index="3" class="java.lang.String" itemvalue="noscript" />
|
|
12
|
+
<item index="4" class="java.lang.String" itemvalue="embed" />
|
|
13
|
+
<item index="5" class="java.lang.String" itemvalue="script" />
|
|
14
|
+
<item index="6" class="java.lang.String" itemvalue="div" />
|
|
15
|
+
</list>
|
|
16
|
+
</value>
|
|
17
|
+
</option>
|
|
18
|
+
<option name="myCustomValuesEnabled" value="true" />
|
|
19
|
+
</inspection_tool>
|
|
20
|
+
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
|
21
|
+
<option name="ignoredPackages">
|
|
22
|
+
<list>
|
|
23
|
+
<option value="typing_extensions" />
|
|
24
|
+
<option value="cffi" />
|
|
25
|
+
<option value="attrs" />
|
|
26
|
+
<option value="beautifulsoup4" />
|
|
27
|
+
<option value="soupsieve" />
|
|
28
|
+
<option value="google" />
|
|
29
|
+
</list>
|
|
30
|
+
</option>
|
|
31
|
+
</inspection_tool>
|
|
32
|
+
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
|
33
|
+
<option name="ignoredErrors">
|
|
34
|
+
<list>
|
|
35
|
+
<option value="N812" />
|
|
36
|
+
</list>
|
|
37
|
+
</option>
|
|
38
|
+
</inspection_tool>
|
|
39
|
+
</profile>
|
|
40
|
+
</component>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="Black">
|
|
4
|
+
<option name="sdkName" value="Python 3.14 (comic-ocr) (2)" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.14 (comic-ocr)" project-jdk-type="Python SDK" />
|
|
7
|
+
</project>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Haganta R. Ginting
|
|
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.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Haganta R. Ginting
|
|
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.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: comic_ocr_reader
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: A Python package made for processing Japanese manga into a format usable with web-based on-screen dictionaries like Yomitan.
|
|
5
|
+
Project-URL: Homepage, https://github.com/HagantaRG/comic-ocr
|
|
6
|
+
Author-email: HRG <rhaganta@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE.MD
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Requires-Dist: easyocr~=1.7.2
|
|
13
|
+
Requires-Dist: loguru
|
|
14
|
+
Requires-Dist: manga-ocr
|
|
15
|
+
Requires-Dist: numpy~=2.5.1
|
|
16
|
+
Requires-Dist: pillow~=12.3.0
|
|
17
|
+
Requires-Dist: tqdm
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# Jelly's Manga Reading Thingy.
|
|
21
|
+
This is my own rendition of the excellent [Mokuro](https://github.com/kha-white/mokuro) project, made mostly just to do it.
|
|
22
|
+
That being said, if you have any suggestions, please give me a heads-up and I will be happy to implement it. Probably.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
1. Prepare a folder containing the images you would like to process. As of v.0.0.1 the images in this folder must be named the page number you would like that image to be.
|
|
26
|
+
(e.g. the PNG image you would like to use as the second page should be titled "2.png")
|
|
27
|
+
The name of the folder will be the name of the resultant HTML file. (e.g. if your folder is titled "Naruto" the output HTML file will be "Naruto.html" )
|
|
28
|
+
2. Run comic-reader-ocr and enter the "folder" command.
|
|
29
|
+
3. Enter the absolute path of the folder from step 1 and wait for comic-reader-ocr to process all the images.
|
|
30
|
+
4. Once finished, the resulting HTML file will be placed in an outputs folder within the folder from step 1.
|
|
31
|
+
5. Open the resulting HTML using your web browser of choice.
|
|
32
|
+
|
|
33
|
+
## FAQs (as decided by Myself)
|
|
34
|
+
1. Is this a worse version of various other projects (e.g. [Mokuro](https://github.com/kha-white/mokuro))?
|
|
35
|
+
|
|
36
|
+
- Yes.
|
|
37
|
+
|
|
38
|
+
2. Do you know how to like. Write things. That work?
|
|
39
|
+
|
|
40
|
+
- No.
|
|
41
|
+
|
|
42
|
+
3. Why did you do this?
|
|
43
|
+
|
|
44
|
+
- As a learning exercise, mostly. Plus, I like trying to reinvent wheels.
|
|
45
|
+
|
|
46
|
+
4. Can I make suggestions?
|
|
47
|
+
|
|
48
|
+
- Yes.
|
|
49
|
+
|
|
50
|
+
5. Did you use AI for this?
|
|
51
|
+
|
|
52
|
+
- Yes. Most of the HTML and JS was AI generated, as unfortunately I really *really* don't like looking at either of those things.
|
|
53
|
+
|
|
54
|
+
6. Are you going to try to make this a webapp because that probably makes a lot of sense or just. Like. Something that isn't Python so that it's easier to distribute or something?
|
|
55
|
+
|
|
56
|
+
- Yes. I'll probably try to rewrite this in Rust or do something like the [mokuro-reader](https://github.com/Gnathonic/mokuro-reader) project.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Jelly's Manga Reading Thingy.
|
|
2
|
+
This is my own rendition of the excellent [Mokuro](https://github.com/kha-white/mokuro) project, made mostly just to do it.
|
|
3
|
+
That being said, if you have any suggestions, please give me a heads-up and I will be happy to implement it. Probably.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
1. Prepare a folder containing the images you would like to process. As of v.0.0.1 the images in this folder must be named the page number you would like that image to be.
|
|
7
|
+
(e.g. the PNG image you would like to use as the second page should be titled "2.png")
|
|
8
|
+
The name of the folder will be the name of the resultant HTML file. (e.g. if your folder is titled "Naruto" the output HTML file will be "Naruto.html" )
|
|
9
|
+
2. Run comic-reader-ocr and enter the "folder" command.
|
|
10
|
+
3. Enter the absolute path of the folder from step 1 and wait for comic-reader-ocr to process all the images.
|
|
11
|
+
4. Once finished, the resulting HTML file will be placed in an outputs folder within the folder from step 1.
|
|
12
|
+
5. Open the resulting HTML using your web browser of choice.
|
|
13
|
+
|
|
14
|
+
## FAQs (as decided by Myself)
|
|
15
|
+
1. Is this a worse version of various other projects (e.g. [Mokuro](https://github.com/kha-white/mokuro))?
|
|
16
|
+
|
|
17
|
+
- Yes.
|
|
18
|
+
|
|
19
|
+
2. Do you know how to like. Write things. That work?
|
|
20
|
+
|
|
21
|
+
- No.
|
|
22
|
+
|
|
23
|
+
3. Why did you do this?
|
|
24
|
+
|
|
25
|
+
- As a learning exercise, mostly. Plus, I like trying to reinvent wheels.
|
|
26
|
+
|
|
27
|
+
4. Can I make suggestions?
|
|
28
|
+
|
|
29
|
+
- Yes.
|
|
30
|
+
|
|
31
|
+
5. Did you use AI for this?
|
|
32
|
+
|
|
33
|
+
- Yes. Most of the HTML and JS was AI generated, as unfortunately I really *really* don't like looking at either of those things.
|
|
34
|
+
|
|
35
|
+
6. Are you going to try to make this a webapp because that probably makes a lot of sense or just. Like. Something that isn't Python so that it's easier to distribute or something?
|
|
36
|
+
|
|
37
|
+
- Yes. I'll probably try to rewrite this in Rust or do something like the [mokuro-reader](https://github.com/Gnathonic/mokuro-reader) project.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling >= 1.26"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "comic_ocr_reader"
|
|
7
|
+
version = "0.0.2"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="HRG", email="rhaganta@gmail.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "A Python package made for processing Japanese manga into a format usable with web-based on-screen dictionaries like Yomitan."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.9"
|
|
14
|
+
dependencies = [
|
|
15
|
+
"easyocr~=1.7.2",
|
|
16
|
+
"pillow~=12.3.0",
|
|
17
|
+
"numpy~=2.5.1",
|
|
18
|
+
"manga-ocr",
|
|
19
|
+
"tqdm",
|
|
20
|
+
"loguru",
|
|
21
|
+
]
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Operating System :: OS Independent",
|
|
25
|
+
]
|
|
26
|
+
license = "MIT"
|
|
27
|
+
license-files = ["LICENSE.MD"]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/HagantaRG/comic-ocr"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Jelly's Manga Reading Thingy.
|
|
2
|
+
This is my own rendition of the excellent [Mokuro](https://github.com/kha-white/mokuro) project, made mostly just to do it.
|
|
3
|
+
That being said, if you have any suggestions, please give me a heads-up and I will be happy to implement it. Probably.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
1. Prepare a folder containing the images you would like to process. As of v.0.0.1 the images in this folder must be named the page number you would like that image to be.
|
|
7
|
+
(e.g. the PNG image you would like to use as the second page should be titled "2.png")
|
|
8
|
+
The name of the folder will be the name of the resultant HTML file. (e.g. if your folder is titled "Naruto" the output HTML file will be "Naruto.html" )
|
|
9
|
+
2. Run comic-reader-ocr and enter the "folder" command.
|
|
10
|
+
3. Enter the absolute path of the folder from step 1 and wait for comic-reader-ocr to process all the images.
|
|
11
|
+
4. Once finished, the resulting HTML file will be placed in an outputs folder within the folder from step 1.
|
|
12
|
+
5. Open the resulting HTML using your web browser of choice.
|
|
13
|
+
|
|
14
|
+
## FAQs (as decided by Myself)
|
|
15
|
+
1. Is this a worse version of various other projects (e.g. [Mokuro](https://github.com/kha-white/mokuro))?
|
|
16
|
+
|
|
17
|
+
- Yes.
|
|
18
|
+
|
|
19
|
+
2. Do you know how to like. Write things. That work?
|
|
20
|
+
|
|
21
|
+
- No.
|
|
22
|
+
|
|
23
|
+
3. Why did you do this?
|
|
24
|
+
|
|
25
|
+
- As a learning exercise, mostly. Plus, I like trying to reinvent wheels.
|
|
26
|
+
|
|
27
|
+
4. Can I make suggestions?
|
|
28
|
+
|
|
29
|
+
- Yes.
|
|
30
|
+
|
|
31
|
+
5. Did you use AI for this?
|
|
32
|
+
|
|
33
|
+
- Yes. Most of the HTML and JS was AI generated, as unfortunately I really *really* don't like looking at either of those things.
|
|
34
|
+
|
|
35
|
+
6. Are you going to try to make this a webapp because that probably makes a lot of sense or just. Like. Something that isn't Python so that it's easier to distribute or something?
|
|
36
|
+
|
|
37
|
+
- Yes. I'll probably try to rewrite this in Rust or do something like the [mokuro-reader](https://github.com/Gnathonic/mokuro-reader) project.
|
|
File without changes
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from PIL import Image
|
|
5
|
+
from easyocr import Reader
|
|
6
|
+
from manga_ocr import MangaOcr
|
|
7
|
+
|
|
8
|
+
from comic_ocr_reader.html_utils import Textbox, Page
|
|
9
|
+
from comic_ocr_reader.img_utils import merge_textboxes_easyocr
|
|
10
|
+
|
|
11
|
+
def process_page(
|
|
12
|
+
manga: dict[int, Page],
|
|
13
|
+
filepath: Path,
|
|
14
|
+
detector: Reader,
|
|
15
|
+
recogniser: MangaOcr,
|
|
16
|
+
page_num: int
|
|
17
|
+
) -> None:
|
|
18
|
+
|
|
19
|
+
result = detector.detect(str(filepath))
|
|
20
|
+
with Image.open(filepath) as img:
|
|
21
|
+
textboxes: list[Textbox] = []
|
|
22
|
+
width, height = img.size
|
|
23
|
+
|
|
24
|
+
count: int = 0
|
|
25
|
+
page: Page = Page(
|
|
26
|
+
img_filepath=f"{filepath.stem}{filepath.suffix}",
|
|
27
|
+
page_num=page_num,
|
|
28
|
+
page_class="page"
|
|
29
|
+
)
|
|
30
|
+
merged_regions: list[list[int]] = merge_textboxes_easyocr(
|
|
31
|
+
result[0][0],
|
|
32
|
+
padding=1
|
|
33
|
+
)
|
|
34
|
+
for item in merged_regions:
|
|
35
|
+
count += 1
|
|
36
|
+
nums: list[int] = []
|
|
37
|
+
for np_num in item:
|
|
38
|
+
nums.append(int(np_num))
|
|
39
|
+
|
|
40
|
+
box_width: int = nums[1] - nums[0]
|
|
41
|
+
box_height: int = nums[3] - nums[2]
|
|
42
|
+
percent_width: int = round(box_width / width * 100)
|
|
43
|
+
percent_height: int = round(box_height / height * 100)
|
|
44
|
+
|
|
45
|
+
region = img.crop((nums[0], nums[2], nums[1], nums[3]))
|
|
46
|
+
start = datetime.now()
|
|
47
|
+
text: str = recogniser(region)
|
|
48
|
+
end = datetime.now()
|
|
49
|
+
textbox: Textbox = Textbox(
|
|
50
|
+
top=round(nums[2] / height * 100),
|
|
51
|
+
left=round(nums[0] / width * 100),
|
|
52
|
+
height=int(percent_height),
|
|
53
|
+
width=int(percent_width),
|
|
54
|
+
text=text
|
|
55
|
+
)
|
|
56
|
+
textboxes.append(textbox)
|
|
57
|
+
page.textboxes = textboxes
|
|
58
|
+
manga[page_num] = page
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
HTML_UTILS_FOLDER: Path = Path(__file__).parent
|
|
4
|
+
class Textbox:
|
|
5
|
+
"""Class containing details of the textbox on a page
|
|
6
|
+
Attributes:
|
|
7
|
+
top %-age of page down from top of page to place textbox.
|
|
8
|
+
left %-age of page right from left of page to place textbox.
|
|
9
|
+
width %-age width of textbox in terms of containing page.
|
|
10
|
+
height %-age height of textbox in terms of containing page.
|
|
11
|
+
"""
|
|
12
|
+
top: int
|
|
13
|
+
left: int
|
|
14
|
+
width: int
|
|
15
|
+
height: int
|
|
16
|
+
text: str
|
|
17
|
+
btn_class: str
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
top: int,
|
|
21
|
+
left: int,
|
|
22
|
+
width: int,
|
|
23
|
+
height: int,
|
|
24
|
+
text: str
|
|
25
|
+
) -> None:
|
|
26
|
+
self.top = top
|
|
27
|
+
self.left = left
|
|
28
|
+
self.width = width
|
|
29
|
+
self.height = height
|
|
30
|
+
self.text = text
|
|
31
|
+
|
|
32
|
+
class Page:
|
|
33
|
+
textboxes: list[Textbox] = []
|
|
34
|
+
img_filepath: Path
|
|
35
|
+
page_num: int
|
|
36
|
+
page_html: str
|
|
37
|
+
page_class: str
|
|
38
|
+
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
img_filepath: Path|str,
|
|
42
|
+
page_num: int,
|
|
43
|
+
page_class: str
|
|
44
|
+
):
|
|
45
|
+
self.img_filepath = img_filepath
|
|
46
|
+
self.page_num = page_num
|
|
47
|
+
self.page_class = page_class
|
|
48
|
+
|
|
49
|
+
def make_page_html(self) -> None:
|
|
50
|
+
"""
|
|
51
|
+
Constructs the HTML of a page, shoves it into the page_html attribute of this object.
|
|
52
|
+
:return:
|
|
53
|
+
"""
|
|
54
|
+
page_html: str = f"""
|
|
55
|
+
<div class="{self.page_class}" id="page{self.page_num}">
|
|
56
|
+
<button class="page-nav prev" onclick="lastPage()">Prev. Page</button>
|
|
57
|
+
<button class="page-nav next" onclick="nextPage()">Next Page</button>
|
|
58
|
+
<div class="zoom-hint">Ctrl + wheel to zoom</div>
|
|
59
|
+
<div class="page-content">
|
|
60
|
+
<div class="page-content-inner">
|
|
61
|
+
<img src="{self.img_filepath}" alt="Snow">
|
|
62
|
+
"""
|
|
63
|
+
for textbox in self.textboxes:
|
|
64
|
+
page_html += f"""
|
|
65
|
+
<button class="text-btn"
|
|
66
|
+
style="--top:{textbox.top}%;--left:{textbox.left}%;--height:{textbox.height}%;--width:{textbox.width}%;">
|
|
67
|
+
<span>{textbox.text}</span>
|
|
68
|
+
</button>
|
|
69
|
+
"""
|
|
70
|
+
page_html+="""
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
"""
|
|
75
|
+
self.page_html = page_html
|
|
76
|
+
|
|
77
|
+
def set_page_class(self, page_class: str):
|
|
78
|
+
self.page_class = page_class
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def make_html_file(
|
|
82
|
+
pages: dict[int, Page],
|
|
83
|
+
template: str|Path = f"{HTML_UTILS_FOLDER}/html_template.html"
|
|
84
|
+
) -> str:
|
|
85
|
+
html_body: str = ""
|
|
86
|
+
for i in range(1, len(pages.keys())+1):
|
|
87
|
+
if (i - 1) % 2 == 0:
|
|
88
|
+
html_body += """
|
|
89
|
+
<div class="spread">
|
|
90
|
+
<button class="spread-nav prev" onclick="lastPage()">Prev. Page</button>
|
|
91
|
+
<button class="spread-nav next" onclick="nextPage()">Next Page</button>
|
|
92
|
+
<div class="spread-hint">Ctrl + wheel to zoom</div>
|
|
93
|
+
<div class="spread-scroll">
|
|
94
|
+
<div class="spread-content">
|
|
95
|
+
"""
|
|
96
|
+
if i == len(pages):
|
|
97
|
+
pages[i].set_page_class("page last")
|
|
98
|
+
elif i == 1:
|
|
99
|
+
pages[i].set_page_class("page first")
|
|
100
|
+
pages[i].make_page_html()
|
|
101
|
+
html_body += pages[i].page_html
|
|
102
|
+
if (i - 1) % 2 == 1 or i == len(pages):
|
|
103
|
+
html_body += """
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
"""
|
|
108
|
+
with open(template, "r", encoding="utf-8") as html_template:
|
|
109
|
+
template: str = html_template.read()
|
|
110
|
+
template = template.replace("{{BODY}}", html_body)
|
|
111
|
+
return template
|