十六进制到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); 
        $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?