-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added automatic text size selection #15
Conversation
Все статические файлы (не относящиеся к питоновскому коду) должны находиться в папке static. |
src/storage/watermark.py
Outdated
@@ -88,8 +105,18 @@ def add_watermark(image_content: bytes) -> BytesIO | None: | |||
return None | |||
|
|||
buff = BytesIO() | |||
buff.name = 'image.jpeg' | |||
buff.name = 'image_x.jpeg' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
почему поменял?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тестил, забыл убрать
src/storage/watermark.py
Outdated
return buff | ||
return buff#image | ||
|
||
# if __name__ == '__main__': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
закомментрированное нужно убрать
папку fonts там создать или просто шрифт положить? |
Папку fonts, да. |
src/storage/watermark.py
Outdated
d = ImageDraw.Draw(txt) | ||
|
||
width_ratio = .15 # Portion of the image the text width should be (between 0 and 1) | ||
font_path = str(Path(Path.home(), "src", "fonts", font_family)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не уверен, что этот способ работы с путями сработает. Посмотри, как я с путями работаю в localizer, когда считываю yml файлы из папки static.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ага, понял
вообще я через докер поднимал, как в описании, тестил через Ipython и работало.
правильно понял, ты предлагаешь переписать через контекстный менеджер?
with open(localization_file, "r") as f:
localizations |= yaml.safe_load(f)
src/storage/watermark.py
Outdated
if font.getlength(text) < breakpoint: | ||
fontsize += learning_rate | ||
else: | ||
learning_rate = learning_rate // 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если честно я не понимаю, зачем тут бесконечный цикл и такой сложный алгоритм. Разве нельзя по размеру картинки прикинуть размер шрифта?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- шрифт — величина относительная (12, 18, 75 не понятно нифига это много или мало для картинки).
поэтому, в моем видении, этот алгоритм занимается как раз прикидкой размера шрифта под размер картинки. - по поводу
while True
— могу предложить другой вариант:
сделать маленькое значение font и идти только на увеличение текстаwhile font.getlength(text) < breakpoint
будет работать быстрее, если мы как-то ограничены сверху по времени
f691958
to
bbbaa6f
Compare
… into adjusted_font_size
сделаю новый PR |
/src/fonts/Gidole-Regular.ttf
за этим стоит следующая идея:
ImageFont.truetype(font_path, fontsize)
картинка в высоком разрешении
шакальная картинка, честно говоря, так себе работает из-за супернизкого разрешения
картинка для сравнения (справа старая вотермарка)