将字符转换为元组并返回

时间:2018-07-14 00:56:32

标签: python base64 python-imaging-library rgb

我正在尝试更改此编码器的输出:
https://github.com/akapila011/Text-to-Image/blob/master/text_to_image/encode.py
从灰度到三色方案,例如此处显示的方案:Tricolor
我需要从编码器更改的主要代码行是:

img = Image.new("L", size)  # grayscale, blank black image

ind = 0

for row in range(0, size[0]):

    for col in range(0, size[1]):

        if ind < text_length:  # only change pixel value for length of text

            pixel_value = convert_char_to_int(text[ind], limit=limit)

            img.putpixel((row, col), pixel_value)

            ind += 1

        else:  # end of text, leave remaining pixel(s) black to indicate null

            break

img.save(result_path)

return result_path

我仅以base64文本形式加载,因此我只能严格使用64个字符。
有人告诉我,我需要更改convert_char_to_int以将元组作为RGB值返回。但是我不确定该怎么做?是否可以将int转换为rgb,如何转换?
为了使我也Decode变回文本,我需要颠倒这个过程。

2 个答案:

答案 0 :(得分:0)

看起来PIL是他们正在使用的库。要回答您的问题,实际上取决于您如何将rgb值编码为chars。一种方法是让一个字符代表一种颜色的亮度-因此,需要三个字符代表一个像素。另一点可以确定的是,您的字符只会代表0到63之间的值,而不是通常的0到255。因此,您需要将每个值乘以4,以使图像不会变得非常暗。

这是我重写<body class="font-root"> ... <div class="null"> /* removes all weird offsets for children */ <div class="font-root column">Hi</div> /* restores base size for relative emulation */ <div class="font-root column">Hi</div> <div class="font-root column">Hi</div> </div> ... </body> 函数的方式:

encode

答案 1 :(得分:0)

我怀疑您要将不同的字符编码为不同的颜色通道:

<mega-menu :grouped-categories="{{ $categories->toJson() }}"></mega-menu>
相关问题