duannaozhao4626 2013-09-03 13:13
浏览 66
已采纳

PHP 5 imagesetpixel参数

I have a quick question regarding PHP's function imagesetpixel. According to the documentation here, the final parameter is a color identifier created with imagecolorallocate. This makes sense. However I found a typo in my program where I was passing hex values directly to imagesetpixel, and it was still working just fine. Is this expected behavior? It's not mentioned in the documentation, so I'm inclined to just stick to using color identifiers, but I figured I'd ask just in case.

  • 写回答

2条回答 默认 最新

  • douzhi2988 2013-09-03 13:22
    关注

    Here is what imagecolorallocate() does: https://bitbucket.org/libgd/gd-libgd/src/de7acbfe3e9e43b6b74b740e192915aff4e45a5d/src/gd.c?at=master#cl-518

    Basically, it spits out an RGBA value compressed to an int. You can do this because and int has 4 bytes and you need one byte to represent each color.

    Now when you pass any value into imagesetpixel() that PHP can convert to an integer, it will work.

    You could even do this yourself (not tested, may not work with truecolor contexts):

    $im_color = pack('SSSS', $r, $g, $b, $a);
    

    Of course this entire behaviour is subject to change in any future version of GD, which is probably why it's not documented.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 虚心请教几个问题,各位DS,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题