douzhechi2435 2013-09-20 15:59
浏览 57

十六进制到PHP中的图像

Any other way to create the image from hexadecimal number? I use a signature pad to get the signature and save it as an image and put in a PDF; I have created the image (*.PNG) from the hex code(signiture pad generates the HExadecimal number); the image seems fine (I can open it and see it!), but for some reason this image cannot be put in the PDF by FPDF; however I can put any other images to my PDF by using FPDF; so I guess there is a problem with the image I created (HEX to Image). I created my image by the following code:

$binary = pack("H*", $MyHex);
file_put_contents("../img/Sign_Representative.png", $binary);

Do you know any other way I can create the image from HEX or any way I can handle this problem?

I appreciate your guidance!

  • 写回答

1条回答 默认 最新

  • douzhuang1900 2013-09-20 20:48
    关注

    Are you sure that signature pad provides PNG-data in HEX?

    Check generated file's content if the first row contains letters "PNG" (without quotes).

    Tried yours and following and all provided data correctly back:

    // test 1
    $binary = pack("H" . strlen($MyHex), $MyHex);
    file_put_contents("../img/Sign_Representative-1.png", $binary);
    
    // test 2
    $binary = hextobin($MyHex);
    file_put_contents("../img/Sign_Representative-2.png", $binary);
    // @src http://www.php.net/manual/en/function.hex2bin.php#110973
    function hextobin($hexstr)  
        { 
            $n = strlen($hexstr); 
            $sbin="";   
            $i=0; 
            while($i < $n) {       
            $a =substr($hexstr,$i,2);           
                $c = pack("H*",$a); 
                if ($i == 0) {
                    $sbin = $c;
                } else {
                    $sbin .= $c;
                } 
                $i += 2; 
            } 
            return $sbin; 
        }
    

    btw, what kind/model signature pad you have? i.e. Honeywell TT8500?

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?