While I’m using the python with aspose-psd package, Using Chinese or Japanese will cause garbled characters in psd files’ layers.
Are there any load_options that I missing which caused this error?
from aspose.psd import Image
from aspose.psd.fileformats.psd import PsdImage
from aspose.psd.fileformats.psd.layers import TextLayer
from aspose.pycore import cast
load_options = PsdLoadOptions()
load_options.load_effects_resource = True
load_options.allow_warp_repaint = True
load_options.read_only_mode = False
load_options.ignore_text_layer_width_on_update = False
source_file = "source.psd"
output_file = "output.psd"
NAME_TEXT_MAPPING = {
'tt1_text': 'test_text at tt1_text!!!',
'tt2_text': '中文字測試',
'award1_text': 'text at award1 !'
}
with Image.load(source_file, load_options) as image:
psdImage = cast(PsdImage, image)
for layer in psdImage.layers:
if replace_text := NAME_TEXT_MAPPING.get(layer.name):
text_layer = cast(TextLayer, layer)
text_data = text_layer.text_data
text_layer.update_text(replace_text)
psdImage.save(output_file)
I’m using the following dockerfile to do the experiments with aspose.psd
FROM --platform=linux/amd64 python:3.11-bullseye
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
WORKDIR /usr/src/app
RUN apt-get update && \
apt-get install vim gettext swig python3-dev -y \
unzip
RUN apt-get install libgdiplus libpq-dev graphviz -y
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
# Update the repository
# "/usr/src/app/" is added in the directory to make sure that will always be in that location
COPY . .
CMD ["tail", "-f", "/dev/null"]
the aspose-psd version is 24.4.0
There will be an source and output in the following zip. data.zip (8.5 MB)
@smithjoe
We will investigate the issue and then I’ll text you back. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies. I added .net issue additionally to check it on the base version.
Issue ID(s): PSDPYTHON-56,PSDNET-2105
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Some fonts don’t support Asian characters, please try to change font in this cases
Please check the following code:
请检查此示例是否适合您。
部分字体不支持中文,请尝试更换细字体
source_file = "source.psd"
output_file = "output.psd"
load_options = PsdLoadOptions()
load_options.load_effects_resource = True
load_options.allow_warp_repaint = True
load_options.read_only_mode = False
load_options.ignore_text_layer_width_on_update = False
NAME_TEXT_MAPPING = {
'tt1_text': 'test_text at tt1_text!!!',
'tt2_text': '中文字測試',
'award1_text': 'text at award1 !'
}
with Image.load(source_file, load_options) as image:
psdImage = cast(PsdImage, image)
for layer in psdImage.layers:
if NAME_TEXT_MAPPING.get(layer.name):
replace_text = NAME_TEXT_MAPPING.get(layer.name)
text_layer = cast(TextLayer, layer)
text_data = text_layer.text_data
# This will not work for Asian Fonts because Arial hasn't asian characters
#text_layer.update_text(replace_text)
textData = text_layer.text_data
for i in range(text_data.items.length - 1, 0, -1):
textData.remove_portion(i)
portion = textData.items[0]
portion.text = replace_text
# It's important to change the font to one which supports Asian Characters
font_name = FontSettings.get_adobe_font_name("Microsoft YaHei")
portion.style.font_name = font_name
textData.update_layer_data()
psdImage.save(output_file)
Could please write me back if it helped. Thank you