Hex to image in 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!




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); 
        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?

People are also looking for solutions to the problem: php - User table in database is changed, how to update session?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.