2

I want to convert this text to jpeg using php. I can convert wit using this site but when I try to convert with imagecreatefromstring library I get Data is not in a recognized format error.

/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 oooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKAC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2/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 Answers 2

5

This string is encoded result of a picture. in order to see the picture, prepend data:image/jpeg;base64 to the encoded string

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

$data is the variable holds encoded data. Then you will be able to see the picture

<?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 igAooooAKKKK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SZX0fywfmjchh9eax 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; ?>" />
Sign up to request clarification or add additional context in comments.

9 Comments

Even if the op wanted to merely display the image, the string is already base64 encoded.
@AmalMurali I use it in this way and works fine. No problem. Do I know something wrong? Please tell me.
@ÖzkanÖZLÜ: this will work, but this won't.
@AmalMurali are the things differend for BLOB? Becuase I have just tried you warned me, while my way is working, yours is not. I am getting image from DB as BLOB which it is encoded base64.
@ÖzkanÖZLÜ: The OP already has the base64 decoded string and I don't really understand why you'd want to re-encode it once again. And where does BLOBs from from? It doesn't matter how you are getting the image. The OP asks convert this text to jpeg using php, not how to display the base64 encoded image fetched from db.
|
2

The string seems to be base64 encoded, use

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.