mpcabd / python-arabic-reshaper

Reconstruct Arabic sentences to be used in applications that don't support Arabic
MIT License
395 stars 81 forks source link

Package Not working when code is deployed using docker #49

Closed askprateek closed 3 years ago

askprateek commented 3 years ago

I'm building an application using this package. The objective of the app is to write Arabic text on images. My app works fine on my local machine but once deployed via docker, it breaks. Characters appear isolated/disjointed.

Code running inside Inside Docker Image image

Correct Image (Working Locally) image

requirements.txt

arabic-reshaper==2.1.0
certifi==2020.6.20
cffi==1.14.0
click==7.1.2
cryptography==2.9.2
Flask==1.1.2
Flask-Cors==3.0.8
fonttools==4.12.1
fpdf==1.7.2
future==0.18.2
gunicorn==20.0.4
img2pdf==0.3.6
itsdangerous==1.1.0
Jinja2==2.11.2
olefile==0.46
Pillow==7.2.0
pycodestyle==2.6.0
pycparser==2.20
pyOpenSSL==19.1.0
python-bidi==0.4.2
six==1.15.0

Werkzeug==1.0.1
FROM nethacker/ubuntu-18-04-python-3:latest

RUN apt-get update -y
RUN apt-get upgrade -y

RUN apt-get install -y libtiff5-dev libjpeg62-turbo-dev libopenjp2-7-dev zlib1g-dev \
    libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk \
    libharfbuzz-dev libfribidi-dev libxcb1-dev

COPY ./src/requirements.txt /root

RUN pip install -r /root/requirements.txt && useradd -m ubuntu

ENV HOME=/home/ubuntu

USER ubuntu

COPY ./src /home/ubuntu/

COPY ./src/fonts/* /usr/share/fonts/

RUN fc-cache -f -v

RUN pip install --upgrade arabic-reshaper[with-fonttools]

WORKDIR /home/ubuntu

EXPOSE 5000

CMD ["gunicorn", "-c", "gunicorn_config.py", "wsgi:app"]
mpcabd commented 3 years ago

It's really weird, most of my tests are actually run in Docker, so it's not about dockerising the app or anything, you need to double check your app source code, maybe there's something that's being done differently; without seeing the code where you use the reshaper it will be difficult for me to help.

askprateek commented 3 years ago

Thanks for the speedy reply. I found the issue.

It was happening because I was splitting the output get_display method and then write the text on image.

I changed the order of things and it works

Step 1: User arabic_reshaper method to reshape text. Step 2: Split the paragraph into multiple lines. Step 3: Apply the get_display method just before writing the text on the image.

Swapping steps 2 and 3 was the root cause.