2

我有一个从图像生成的十六进制代码,我想从该十六进制代码中绘制该图像。代码来自如下示例的 Web 服务,问题是

1-如何从十六进制代码中绘制图像?我试过这个但不起作用:

    $hexpic="";
    $data = pack("H" . strlen($hexpic), $hexpic);

    file_put_contents("sample.png", $data);

*我尝试了另一个使用“imagecreatefromstring($data);”的例子 但它也不起作用。

十六进制代码示例:00000005089474e0a0d0a1a00000d0048495244000002000000c0000000c000608000056005c75000004000e70000741958455374666f77747261000006000656441626f20656d4967615265616500001007964c9713c6500002203546974584d5800001203a4c6f632e6d6461626f2e656d7800700000140000000003f3c70786361656b20746562000016069673d6eef22bfbb20226469223d35570000200304d704d654369687a4865727a53544e00002207a63636b64393f22203e783c783a706d0000240656d617478206c6d736e783a223d64610000260626f3a65736e6d3a74652f6120223a7800003006d7874703d6b41226f6465625820504d00003204320726f20652e352d3330633131362000003402e36343136353136202c30323231302f00003602f323630312d3a343635323a203720200000400202020202220203e723c6664523a4644000042078206c6d736e723a6664223d7468707400004402f3a772f7777772e2e33726f2f67393100004603939302f2f323232722d6664732d6e79000050061742d78736e2223203e723c6664443a000052073657263706969746e6f72206664613a00005406f627475223d20226d786e6c3a736d7800005603d70682274743a702f2f736e612e6f6400006006562632e6d6f782f7061312f302e222f000062078206c6d736e783a706d4d4d223d7468000064070742f3a6e2f2e736461626f2e656f6300006602f6d61782f702e312f306d6d222f782000007006c6d736e733a52746665223d7468707400007202f3a6e2f2e736461626f2e656f632f6d000074061782f702e312f30547370792f65655200007606f73727565636552236620226d783a700001000724361656f7454726f6f3d6c41226f640001020656250206f686f746873706f43203653000104028206957646e776f297320226d784d7000010603a4d6e4974736e6165634449223d6d7800011002e7069693a6430413034464533353444000112036453131324544413246393931334335000114034344539434120226d784d703a4d6f4400011607563656d746e4449223d6d782e70696400012003a643041303446453435344436453131000122032454441324639393133433534344539000124043413e223c206d784d703a4d654469720001260657646646f72206d747365523a666e69000130074736e6165634449223d6d782e70696900013203a643041303446453135344436453131000134032454441324639393133433534344539000136043412022747365523a666f647563656d0001400746e4449223d6d782e7069643a643041000142030344645323534443645313132454441000144032463939313343353434453943412f220001460203e2f3c64723a66654463736972747000015006f693e6e3c20722f6664523a4644203e00015202f3c3a786d786d7074653e613c20783f000154061706b6374656520646e223d22723e3f00015605c55296e0000c00044495441da78646200016003e2892f081811b81998898800191f83b0001620c40f80ff2bf8900b03e00e62fe2080c10001640301b0d4266650a81148083cbc04c01a10001660f8a4882182c1f8247fe93d8f5b564b180001700fe0eb185909999c438f11989069b00a20001720c34ca07f70739fb92a011ff707e6a80e0001740f73ba903403f11fc3d4d543f271dc34c0001760201243660892d34617b07f88f102206a0002000c5fefff87fffd0e40560ef52c1a100c80002020660da0417e932223f8a400405e90648e000204007220d9aa0b00f5e18d482c50925c57c0002060301224f01003006064551e30159d61040002100000000004549444e42ae82600002114

有人能帮我吗?

4

1 回答 1

0

将 HEX 字符串转换为二进制:

$binary = pack("H*", $hex);

pack("H*", ...) 相当于 hex2bin,从 PHP 5.4 开始可用。将其写入磁盘:

file_put_contents("file.png", $binary);

于 2013-07-22T17:33:09.223 回答