Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions mathbot/modules/latex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,16 @@ async def handle(self, message, source, *, is_inline, centre=True, wide=False, n
message,
latex,
colour_back,
oversampling=(1 if wide else 2)
)

async def render_and_reply(self, message, latex, colour_back, *, oversampling):
async def render_and_reply(self, message, latex, colour_back):
with MessageEditGuard(message, message.channel, self.bot) as guard:
async with message.channel.typing():
sent_message = None
try:
render_result = await generate_image_online(
latex,
colour_back,
oversampling=oversampling
)
except asyncio.TimeoutError:
sent_message = await guard.send(LATEX_TIMEOUT_MESSAGE)
Expand Down Expand Up @@ -169,12 +167,12 @@ async def get_colours(self, user):
return '36393F', 'f0f0f0'


async def generate_image_online(latex, colour_back, *, oversampling):
async def generate_image_online(latex, colour_back):
payload = {
'format': 'png',
'code': latex.strip(),
'density': 220 * oversampling,
'quality': 100
'density': 770,
'quality': 75
}
async with aiohttp.ClientSession() as session:
try:
Expand All @@ -196,13 +194,12 @@ async def generate_image_online(latex, colour_back, *, oversampling):
if image.width <= 2 or image.height <= 2:
print('Image is empty')
raise RenderingError(None)
border_size = 5 * oversampling
border_size = 5
colour_back = imageutil.hex_to_tuple(colour_back)
width, height = image.size
backing = imageutil.new_monocolour((width + border_size * 2, height + border_size * 2), colour_back)
backing = backing.resize((backing.width // 3, backing.height // 3), resample = PIL.Image.BICUBIC)
backing.paste(image, (border_size, border_size), image)
if oversampling != 1:
backing = backing.resize((backing.width // oversampling, backing.height // oversampling), resample = PIL.Image.BICUBIC)
fobj = io.BytesIO()
backing.save(fobj, format='PNG')
fobj = io.BytesIO(fobj.getvalue())
Expand Down