dongmi5177 2019-07-04 14:55
浏览 195

对于某个8位图像,imagecolorallocate()对大多数颜色返回false

I need the "color identifier" for text color which I need to pasted on an image using imagettftext(). I have found that for certain images imagecolorallocate can return false. But nowhere is indicated why this is or which colors will cause this. 8 bit is a good indicator but I can't change to a higher bit value.

Trough trial and error I found a number that works and gives a color I was looking for (between 0 - 255). That isn't really a workable solution because whenever I change the image I will again have to go look for a number that works.

$main_text_font_color = imagecolorallocate($certificate,
        $font_color['red'],
        $font_color['green'],
        $font_color['blue']
);
imagettftext($certificate, $text_size, 0, $text_h, $text_start, $main_text_font_color, $font_url, $text);

So I would like to know if there is a way to predict which colors will cause a false and which colors will work.

Update: So I didn't find an answer to the question but thanks to @misorude I payed attention to the first comment on the imagecolloralocate documentation page and am using a workaround mentioned in the comment. imagecolorclosest() gives a really good approximation of the color I was looking for. jahservant13's comment also gives some nice background information on imagecolloralocate not mentioned in the documentation.

As the color being perfect was not a requirement, this in essence is the answer I was looking for. I'm not posting this as the answer because it is not actually the answer to the question and I am still interested in knowing if there is an actual answer.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 请问这个是什么意思?
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。