我在数据库中有这个字符串:
http://jsfiddle.net/ebore/NUYTu/
这基本上是一个Flag图像,我想用PHP显示这个图像,我已经尝试过在这里给出的各种选项,以及谷歌搜索它。
$image = imagecreatefromstring($FlagImage);
// start buffering
ob_start();
imagegif($image);
$contents = ob_get_contents();
ob_end_clean();
echo "<img src='data:image/gif;base64,".base64_encode($contents)."' />";
imagedestroy($image);
但未找到解决方案,如何将此字符串转换为图像?
[编辑]
这就是我在.NET中的表现,我是PHP新手。
Dim cRdr As SqlDataReader = com.ExecuteReader
While cRdr.Read
Dim img() As Byte = CType(cRdr("FlagImage"), Byte())
Dim ms As New MemoryStream
ms.Write(img, 0, img.Length)
ForexCtrl.picFlag.Image = Image.FromStream(ms)
'ForexCtrl.lblCurrency.Text = cRdr("Currency").ToString
ForexCtrl.lblSymbol.Text = cRdr("Symbol").ToString
End While
cRdr.Close()
答案 0 :(得分:1)
好吧,它似乎已经从二进制形式转换为十六进制形式,将其转换回来:
<?php
header("Content-Type: image/gif");
//Notice the removed "0x", you can do this with code using substr()
$FlagImage = "47494638396184010401F70031FFFFFFF7F7F7E7E7E7DEDEDEDE1018D6D6D6D62121CECECEC63131BDBDBDBD3139B5B5B5B54242A5A5A59494945A845A52845A52845242946B399C6B319C6B318C5A21945A1094520000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002C00000000840104010008FF0001081C48B0A0C18308132A5CC8B0A1C38710234A9C48B1A2C58B18336ADCB8B081838F20438A1C49B2A4C9932853AA5CC9B2A5CB973063CA9C49B3A6CD9B38472610E84000C79F40830A1D4AB4A8D1A348270ED809C041D2A750A34A9D4AB5AAD4A53CAD6ADDCAB5ABD7AF43B136054BB6ACD9B368A78A759AB6ADDBB770E31E5C2BB7AEDDBB78AF32659BB7AFDFBF8021D20D4CB8B0E1BE830F2B5ECC986CE2C690234B46FA78B2E5CB982B56CECCB9B367829B3F8B1E1D3934E9D3A8039B4ECDBAB5DCD5AE63CB2E0B7BB6EDDB556BE3DECDDBA8EEDEC0836BFC2DBCB871C17B8F2B5F4E9138F3E7CB9D439F2E5C3AF5EBBBAD63DF2E5B3BF7EFA9BD83FF1F2F5A3CF9F399CDA35F2F593DFBF78BDDC39F4F583EFDFB8893E3DF8FD93EFFFF6FF907E080670948E0815F1988E0825A29C8E0837A6505E184753948E185445988E1863F69C8E187187908E2884AE947E289B99988E28A5089C8E28B06B908E38C00C848E38B36DEB8628E3A9EC8638F23FE08E487420EB96191465E886492132EC9E4834E3EB96094521E486595035E89E57F5A6EB95F975EDE076698F38D49E67B669EB95E9A6A9EC7669BE3BD09E77772CEB95D9D765E87679ED3EDC9E7737EFE199D8A82F61868A1C61D8A6875842E3AA3A28EF60669A4D9354AE98E965EEA63A69A06C969A7447E0AEA91A28EAAE45E13A4AAEAAAACB6EAEAABB0C6FF2AEBACB4D66AEBADB8E6AAEBAEBCF6EAEBAFC0062B2CAB12EC65C105C826ABECB2CC36EBECB3D0462BEDB4D4566BEDB5D866ABEDB6DC76EBEDB7E086AB6C05C68A6BEEB9E8A6ABEEBAECB6EBEEBBD992CBD3B1F0D66BEFBDF8E6ABEFBEF6CADB14BDFC062CF0C004176CF0B9FE3A00F0C10C37ECF0C310D79BF0C211576CF1C518679CECC41A77ECF1C720DFCB71C824976CF2C9D68E8CF2CA2CB70CB2CA2EC72CF3CC06C34CF3CD38E7DCAECD3AF7ECF3CFF1960BF4D04417DD2CCF4627ADF4CD482FEDF4D327370DF5D454672C75D55867CDF0D55A77EDB5BE5C7F2DF6D8EC864DF6D9687F6B76DA6CB75DEDDA6EC72DF7B270CF6DB7DB75DFADF7D979EFFFEDB7D77DFF2D78D5810F6EB8D3851FAE78D1892FEEB8CF8D3F2E39D3424F6EF9D3915FAE39CA996FEE79C89D7F2EBAC6A18F6E7AC5A59FAE7AC3A9AFEE3AC1ADBF2EFBBEB1CF6E7BBF95DFAE3BC6B5EFEE7BBABDFF2E7CB8C10F6F3CB7C51FAFFCB5C92FEFBCB4CD3F2FFDD1B94F6F7DD9D55FAF3DC2D96FEFBDDADD7F2FBEB6D18FAF7CF9E61B8F7EFAC2AFCFBEEFEEBFAF7BFCF2DB4E7FFDB2DF8FBFEBFAEFAF7AFFFE331D000328BA0112D073063CA0E612A840CB31B081927B20041D27C1092AAE8216341C063328B80D72D06F1EFCA0DE422842BB91B084723B210AF116BE154E4F852E4C1B0C63C8B716D2707933BCA1D872A843C0D9B087C3E32110FFB326C42112EE8746DC5DC21EC0C4263AF189508CA214A748C52A5AF18A58CCA216B7C8C52E7AF18B600CA318C748C63242712F0620801AD7C8C636BAF18D708CA31CE748C73ADAF18E78CCA31EF7C8C73EFAF18F800CA42007C94604A09190884CA42217C9C8463AF291908CE41E0DC993344AF29298CCA42637C9C94E6292924DB1A4274749CA529AF294A84C24281D20CA54BAF295B08CA52C2FB9CA56CEF296B8CCA52E77B9C65AF2F297C00CA63033E9CB611AF398C84C261E8BA9CC663AF399C2642634A749CD6AA2529AD6CCA636B7F9486C72F39BE00CE7240F29CE729AF39C6FF4263AD7C9CE6CAAB39DF08C6732DF29CF7ADA7397F4BCA73EF7E9FFCA7CF2F39F00E5A43F034AD0823A72A0064DA8420389D0853AF4A1776C2844274AD1364AB4A21885E84533CAD1846EB4A32005E847434AD27B8EB4A42885E74953CAD273AEB4A53005E74B634A537792B3A6388DE74C73CA5365EEB4A7401DE64F834A545E0EB5A848BDE55193CAD4572EB5A95035E553A34AD54E4EB5AA58FDE44DB3CA555D5EB5AB605DE457C34AD6418EB5AC68F5E359D3CAD63CAEB5AD70A5E35BE34AD7746EB5AE783DE85DF3CA5755EEB5AF8065E85F034B583ECEB5B06C3D2C62D1AAD8C592B5B18E052B6423CBD5C95216AB96BD2C5533AB59A872B6B34CFD2C68912ADAD112B5B4A6052A6A53CBD3D5B216A7AE7D2D4D632B5B98A3D2B6B62CBD2D6E51AADBDD92B4B7BE05297083CBD1E11217A3C63D2E4593AB5C8D0EB6B975652E74172ADDE97AF4B9D66D6B75B34BD0ED7257A4D8FD6E59BD2BDE7D92B7BC260D2F7ABBBA4A0520E0BDF08DAF7CE74BDFFADAF7BEF8CDAF7EF7CBDFFEFAF7BF000EB080074CE0021BF8C0088E2F03989280063BF8C1108EB084274CE10A5BF8C218CEB08637CCE10E7BF8C3200EB188474CE2129B58C20730D58D0202003B00";
echo hex2bin($FlagImage);
如果你没有至少PHP 5.4 hex2bin
不存在,那么你将不得不使用它:
pack("H*", $FlagImage);