madspof Posted April 18, 2008 Share Posted April 18, 2008 I was wondering if there is a way of converting a Jpeg to binary within php ? Link to comment https://forums.phpfreaks.com/topic/101789-jpeg-to-binary/ Share on other sites More sharing options...
dptr1988 Posted April 18, 2008 Share Posted April 18, 2008 What do you mean by 'binary'? Are you wanting to decode/edit a raw jpeg file? Link to comment https://forums.phpfreaks.com/topic/101789-jpeg-to-binary/#findComment-520807 Share on other sites More sharing options...
madspof Posted April 18, 2008 Author Share Posted April 18, 2008 I am not realy sure i was thinkin of storing images in text files so i was thought i would need some kinda of function that would change the Jpeg into a string that could be inserted into a text files. any idea of a function that could do that ? Link to comment https://forums.phpfreaks.com/topic/101789-jpeg-to-binary/#findComment-520808 Share on other sites More sharing options...
hitman6003 Posted April 18, 2008 Share Posted April 18, 2008 A jpeg is in "binary" format. Why do you need / why would you want to store a jpeg as a text file? Link to comment https://forums.phpfreaks.com/topic/101789-jpeg-to-binary/#findComment-520815 Share on other sites More sharing options...
dptr1988 Posted April 18, 2008 Share Posted April 18, 2008 Yes, you can do that with the 'base64_encode' function. The base 64 ecodeing will convert binary data into printable characters that can be put into a string. It is an encoding type that is used for encoding email attachments. http://us3.php.net/base64_encode http://en.wikipedia.org/wiki/Base64 Link to comment https://forums.phpfreaks.com/topic/101789-jpeg-to-binary/#findComment-520819 Share on other sites More sharing options...
discomatt Posted April 18, 2008 Share Posted April 18, 2008 Or just rename the jpg to txt Link to comment https://forums.phpfreaks.com/topic/101789-jpeg-to-binary/#findComment-520821 Share on other sites More sharing options...
dptr1988 Posted April 18, 2008 Share Posted April 18, 2008 No, just renaming would not work! Most '.txt' formats requre a 0x00 character at the end of the string, but jpeg file could possibly contain more then one 0x00 character. So if you did that, the text file would be cut off after the first 0x00 character that it encountered Link to comment https://forums.phpfreaks.com/topic/101789-jpeg-to-binary/#findComment-520825 Share on other sites More sharing options...
discomatt Posted April 18, 2008 Share Posted April 18, 2008 Has nothing to do with the .txt format, it has to do with the text editor. Renaming it to .txt will not change its contents. Link to comment https://forums.phpfreaks.com/topic/101789-jpeg-to-binary/#findComment-520828 Share on other sites More sharing options...
dptr1988 Posted April 19, 2008 Share Posted April 19, 2008 Yes, but renaming it to '.txt' will usally cause it to be opened by text editors, which will cause trouble Link to comment https://forums.phpfreaks.com/topic/101789-jpeg-to-binary/#findComment-520842 Share on other sites More sharing options...
discomatt Posted April 19, 2008 Share Posted April 19, 2008 Assuming the file is saved after.. which I'm assuming will cause trouble as it is. Link to comment https://forums.phpfreaks.com/topic/101789-jpeg-to-binary/#findComment-520863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.