Open DouglasLapsley opened 5 years ago
Please provide self-contained example code, including imports and data, so that other contributors can just run it and reproduce your issue. Ideally your example code should be minimal.
The results link goes to a jpeg with substantial compression artifacts, I'm not entirely sure what you're referring to.
Sure no problem. Here is the whole code
Ignore the background image in the image I sent as that is artifacty, but that's not the issue. If you look at the pale blue text of the "P" you'll see that there is what looks like JPG artifacting, but I think is actually greying coming from the premultiplication of the alpha on black. If I were to change the premultiplication colour to a salmon colour, this would be reduced because the background colour would then be a closer match to the premultiplication colour. At least that's my understanding of it. I may be wrong of course.
Would be great to see a vector output option as this would solve the problem too.
Great generator by the way :) Thanks!
This is still a problem which renders the library almost useless for my usecase. I tried to come up with a solution, but the only workaround I've found is using a background color during initial rendering and replacing it later with transparency. This only works if the wordcloud is supposed to be used on a uniform background of which I know the color beforehand.
Sorry for the slow reply. Can you give a small example where this is severe? It's also likely an issue with PIL, not wordcloud. @DouglasLapsley RGBA is not using premultiplication. You can use RGBa for using a premultiplied alpha channel.
Here is what I get with the example above, where I guess there is a bit of a subtle dark border:
using white text it's a bit more pronounced:
Here's a minimum example btw:
from wordcloud import WordCloud
def get_color_func(word, **kwargs):
return '#ffffff'
wc = WordCloud(
max_words=50,
margin=10,
random_state=1,
background_color=None,
mode='RGBA',
repeat=True
).generate('Hello world hello hello world')
wc.recolor(color_func=get_color_func)
wc.to_file('wordCloudOutput.png')
You can easily solve the problem by setting the background to a different transparent color, so the problem goes away if you do
from wordcloud import WordCloud
def get_color_func(word, **kwargs):
return '#ffffff'
wc = WordCloud(
max_words=50,
margin=10,
random_state=1,
background_color="#FFFFFF00",
mode='RGBA',
repeat=True
).generate('Hello world hello hello world')
wc.recolor(color_func=get_color_func)
wc.to_file('wordCloudOutput.png')
You can also use premultiplied alpha, which would get rid of the problem, but can not be stored in PNG, using mode="RGBA".
Does either of you want to send a PR with additions to the documentation?
There is a dark fringe on text created with alpha channel and saved as png which is most obvious when text is light and background is light.
I assume this to be because the png alpha is premultiplied against black. It is possible to please specify a colour value in the background_color property and use a different property to specify whether the alpha is created?
Thank you.
Result
Deps: