Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 458ccda

Browse files
author
k
committedDec 12, 2024
Add tesseract support for docker container deployments. Add dockerfile with tesseract and languages installed.
1 parent 29b5124 commit 458ccda

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed
 

‎Dockerfile-tesseract

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ARG VERSION=latest
2+
3+
FROM b3log/siyuan:${VERSION}
4+
5+
RUN apk update && apk add --no-cache --update tesseract-ocr
6+
7+
RUN cd /usr/share/tessdata \
8+
&& wget https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata \
9+
&& wget https://github.com/tesseract-ocr/tessdata/raw/main/chi_sim.traineddata \
10+
&& wget https://github.com/tesseract-ocr/tessdata/raw/main/chi_tra.traineddata
11+
# Add more langs if needed
12+
13+
ENTRYPOINT ["/opt/siyuan/entrypoint.sh"]
14+
15+
CMD ["/opt/siyuan/kernel"]

‎kernel/util/ocr.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func IsTesseractExtractable(p string) bool {
187187
var tesseractOCRLock = sync.Mutex{}
188188

189189
func Tesseract(imgAbsPath string) (ret []map[string]interface{}) {
190-
if ContainerStd != Container || !TesseractEnabled {
190+
if !TesseractEnabled {
191191
return
192192
}
193193

@@ -343,8 +343,23 @@ func filterTesseractLangs(langs []string) (ret []string) {
343343
return ret
344344
}
345345

346+
func isContainerTesseractSupported(container string) bool {
347+
supportedContainers := []string{
348+
ContainerStd,
349+
ContainerDocker,
350+
}
351+
352+
for _, v := range supportedContainers {
353+
if v == container {
354+
return true
355+
}
356+
}
357+
358+
return false
359+
}
360+
346361
func getTesseractVer() (ret string) {
347-
if ContainerStd != Container {
362+
if !isContainerTesseractSupported(Container) {
348363
return
349364
}
350365

0 commit comments

Comments
 (0)
Please sign in to comment.