sixty-nine / PHP_Word_Cloud

PHP Word Cloud - Deprecated, please use https://github.com/sixty-nine/php-cloud-lib
MIT License
39 stars 16 forks source link

Unable to change background color using WordCloudBuilder #5

Closed borys-p closed 7 years ago

borys-p commented 7 years ago

The WordCloud class' third parameter $backgroundColor is unavailable when using WordCloudBuilder, which is the easiest way to initialize the cloud. I'd suggest adding this parameter to the $config variable.

sixty-nine commented 7 years ago

Hello @borys-p and thank you for your interest in this small project.

The easiest way to achieve this is to add an entry $config['bgColor'] = '#123456' to the parameters you pass to WordCloudBuilder, then change the line 31 of the builder to:

$this->cloud = new WordCloud($config['size'][0], $config['size'][1], $config['bgColor']);

As I don't work actively on this repo anymore, it would be great if you could propose a PR to do this.

You might be interested in this other project doing the same but tightly coupled with Symfony and Imagine: sixty-nine/php-cloud.

lucasmancini commented 7 years ago

Hello, i implement your script in my site .. but i have an issue., when the image is created, sometimes generate black background portion in the image, and sometimes the words overflow the box. Is normal that behaviour?? Thanks in advance.. Sorry my english.

pdf 848x612

sixty-nine commented 7 years ago

Hello Lucas,

As stated before I am not maintaining this script anymore, please refer to the repo sixty-nine/php-cloud-lib for a more up-to-date version.

This said, I guess the problem with the black background occurs when the image is cropped in WordCloudRenderer::cropImage. It can occur if the old image size is smaller than the new image. You probably have to fill the new image with the background of the cloud, otherwise it will be black.

For the problem with the words being out of the cloud you'll have to investigate DefaultWordUsher::searchPlace and make sure the place that is found is in the clip area.

There are TODOs in the code for both problems.

Of course a PR is welcome if you fix those problems.

sixty-nine commented 7 years ago

Please have a look at sixty-nine/php-cloud-lib