php string to image imagecreatefromstring fault

时间:2013-09-29 21:47:50

标签: php image binary

我想使用php将此文本转换为jpeg。 我可以使用this site进行转换,但是当我尝试使用imagecreatefromstring库进行转换时,我得到的数据不是可识别的格式错误。

/9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg SlBFRyB2NjIpLCBkZWZhdWx0IHF1YWxpdHkK/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMP FB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEc ITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgA ZAGQAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMC BAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYn KCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeY mZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5 +v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwAB AgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpD REVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ip qrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMR AD8A6qiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAo oooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACii igAooooAKKKKACiitzQNFt9VjmeeSRfLYABCBnP1FAGHRXcjwppg6iY/V6H8J6aw485PcP8A4igD hqK6PUPCc0EbSWcpmA5MZGGx7etc4Rg4PWgAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKK KACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAoooo AK67wb/x73X++v8AI1yNdd4N/wCPe6/31/kaAKni2aVNTiRJXVfJB2hiBnc1Ycd7dQsGjuZUPs5r oPFVndXGpxPBbTSqIQCUQsM7m9KyIdD1OdgFs5Fz3cbf50Add4e1KTUrBjOcyxttZgMbh2Nct4ig SDW5wgwGw+Pcjn9a6nTrWHw/pTG5mUEnc7ds+g9a4vUbxr+/muSMbzwPQDgfpQBVorc8N2NndyXD 3ihkiVSNzYAznrW8b7w9aHaDagj/AJ5xbv1AoA4Wiu9hvNC1BxEgt3c8BXiwT9MisnxDoENrAby0 UqqkeZH1Az3FAHMUUV31lpdlLo9uxtIDI9up3FBkkr1zQBwNFdnBpOlaLAsuovHJKe7jI/Be9Xba 40bUyYolt5Dj7jR4P4AigDz+iuh8R6JHYhbq1BELNtZOu0+3tXPUAFFehXmi2c1nLHBa28crLhX2 AYPrVJLLRdCjQXbRvMRndIu4n6LzgUAcVRXoUB0fVkZYkt5cdRsww/TNcr4g0ddMuFeHJglztB52 n0oAx6KdHG8sixopZ2OFA6k12mn+HLKxt/OvQksgGWL/AHF/D/GgDiaK7n+19AVvKzDjpxAdv8qT UfD9lqFt51ksccpGUaP7j/0/GgDh6KV0aN2RwVZTgg9jXW+FrG1udMkee2ilYTEAugJxtWgDkaK6 mbw4b3XLnYot7NCoG1cZ+UZCj+taS6ZoNgNkotw3czSAk/gTQBwlFXdX8j+1Z/s3l+TkbfLxt6Dp iqVABRRRQAUUUUAFFFFABRRRQAU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B8tpKT7sBQBc0DRTpcbyTMrTyAA7ei j0rE8WXyXF7HbRnIgB3Ef3j2/DFR3viq8uUKQqtuh6lTlvzrCJycnrQB3PhSZX0fywfmjchh9eax de0a8GpyzwwSTRyncCi5IPcHFZmnalcaZcebARg8MjdGFdGnjGAoN9pIG7gMCKAKei+HLhrpLi9j 8qKM7gjdWI6cdhXUagQdKuiDkGB8Ef7prkNT8S3N/EYYkEETcMAcsw9M1PJ4r8ywe1+xY3RGPd5v tjOMUAc5XpWl/wDIJsv+uCf+givNa6W18W/ZrSGD7Du8qNU3ebjOBjPSgDmqkg/4+Iv98fzqOnRt skV8Z2kHFAHoeuf8gS7/AOudedV0d94q+22U1t9i2eYuN3m5x+GK5ygD0rVP+QTe/wDXB/8A0E15 rXS3Xi37TaTQfYdvmxsm7zc4yMZ6VzVAF/Rf+Q1af9dRXV+Kv+QI3/XRa4yyufsd7DcbN/lsG25x mtbVfEf9p2Rtvsnl5YNu8zPT2xQBS0W+Gn6pFM/+rPyv9D3/AK12WtaaNWsAsbL5infG2eD7fQ15 7WtpviG705BFxNCOiP2+hoAqTaZfQOVktJgfZCR+Yp9vo2o3LAR2koB/icbR+ZroV8ZQEfPaSA+z A1HN4yGMQ2Zz6u/9AKAOVZSjsp6g4Ndp4Q/5BMv/AF3P/oK1xjtvdmPViTWzo/iD+ybR4Psvm7pC +7zNvYDHQ+lADfFH/Ick/wBxf5VjVd1S/wD7SvmufK8vcANu7PT3xVKgAooooAKKKKACiiigAooo oAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiig AooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAC iiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKK KKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9k= ­

2 个答案:

答案 0 :(得分:5)

此字符串是图片的编码结果。为了查看图片,请将data:image/jpeg;base64添加到编码字符串

之前
<img src="data:image/jpeg;base64,<?php echo $data; ?>" />

$data是变量保存编码数据。然后你就可以看到图片了

<?php 

$str = "/9j/4AAQSkZJRgABAQAAAQABAAD//gA+Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg SlBFRyB2NjIpLCBkZWZhdWx0IHF1YWxpdHkK/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMP FB0aHx4dGhwcICQuJyAiLCMcHCg3KSwwMTQ0NB8nOT04MjwuMzQy/9sAQwEJCQkMCwwYDQ0YMiEc ITIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy/8AAEQgA ZAGQAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMC BAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYn KCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeY mZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5 +v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwAB AgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpD REVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ip qrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMR AD8A6qiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAo oooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACii igAooooAKKKKACiitzQNFt9VjmeeSRfLYABCBnP1FAGHRXcjwppg6iY/V6H8J6aw485PcP8A4igD hqK6PUPCc0EbSWcpmA5MZGGx7etc4Rg4PWgAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKK KACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAoooo AK67wb/x73X++v8AI1yNdd4N/wCPe6/31/kaAKni2aVNTiRJXVfJB2hiBnc1Ycd7dQsGjuZUPs5r oPFVndXGpxPBbTSqIQCUQsM7m9KyIdD1OdgFs5Fz3cbf50Add4e1KTUrBjOcyxttZgMbh2Nct4ig SDW5wgwGw+Pcjn9a6nTrWHw/pTG5mUEnc7ds+g9a4vUbxr+/muSMbzwPQDgfpQBVorc8N2NndyXD 3ihkiVSNzYAznrW8b7w9aHaDagj/AJ5xbv1AoA4Wiu9hvNC1BxEgt3c8BXiwT9MisnxDoENrAby0 UqqkeZH1Az3FAHMUUV31lpdlLo9uxtIDI9up3FBkkr1zQBwNFdnBpOlaLAsuovHJKe7jI/Be9Xba 40bUyYolt5Dj7jR4P4AigDz+iuh8R6JHYhbq1BELNtZOu0+3tXPUAFFehXmi2c1nLHBa28crLhX2 AYPrVJLLRdCjQXbRvMRndIu4n6LzgUAcVRXoUB0fVkZYkt5cdRsww/TNcr4g0ddMuFeHJglztB52 n0oAx6KdHG8sixopZ2OFA6k12mn+HLKxt/OvQksgGWL/AHF/D/GgDiaK7n+19AVvKzDjpxAdv8qT UfD9lqFt51ksccpGUaP7j/0/GgDh6KV0aN2RwVZTgg9jXW+FrG1udMkee2ilYTEAugJxtWgDkaK6 mbw4b3XLnYot7NCoG1cZ+UZCj+taS6ZoNgNkotw3czSAk/gTQBwlFXdX8j+1Z/s3l+TkbfLxt6Dp iqVABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFF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rTyAA7ei j0rE8WXyXF7HbRnIgB3Ef3j2/DFR3viq8uUKQqtuh6lTlvzrCJycnrQB3PhSZX0fywfmjchh9eax de0a8GpyzwwSTRyncCi5IPcHFZmnalcaZcebARg8MjdGFdGnjGAoN9pIG7gMCKAKei+HLhrpLi9j 8qKM7gjdWI6cdhXUagQdKuiDkGB8Ef7prkNT8S3N/EYYkEETcMAcsw9M1PJ4r8ywe1+xY3RGPd5v tjOMUAc5XpWl/wDIJsv+uCf+givNa6W18W/ZrSGD7Du8qNU3ebjOBjPSgDmqkg/4+Iv98fzqOnRt skV8Z2kHFAHoeuf8gS7/AOudedV0d94q+22U1t9i2eYuN3m5x+GK5ygD0rVP+QTe/wDXB/8A0E15 rXS3Xi37TaTQfYdvmxsm7zc4yMZ6VzVAF/Rf+Q1af9dRXV+Kv+QI3/XRa4yyufsd7DcbN/lsG25x mtbVfEf9p2Rtvsnl5YNu8zPT2xQBS0W+Gn6pFM/+rPyv9D3/AK12WtaaNWsAsbL5infG2eD7fQ15 7WtpviG705BFxNCOiP2+hoAqTaZfQOVktJgfZCR+Yp9vo2o3LAR2koB/icbR+ZroV8ZQEfPaSA+z A1HN4yGMQ2Zz6u/9AKAOVZSjsp6g4Ndp4Q/5BMv/AF3P/oK1xjtvdmPViTWzo/iD+ybR4Psvm7pC +7zNvYDHQ+lADfFH/Ick/wBxf5VjVd1S/wD7SvmufK8vcANu7PT3xVKgAooooAKKKKACiiigAooo oAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiig AooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAC iiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKK KKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAP/9k=";
?>


<img src="data:image/jpeg;base64,<?php echo $str; ?>" />

答案 1 :(得分:1)

字符串似乎是base64编码的,使用

$str = '...';
$image = imagecreatefromstring(base64_decode($str));