Question

You know when you open up an image in notepad or a text editor, you get a lot of random illegible text that looks like a bunch of foreign letters.

For instance, this image: ...

results in:

‰PNG


IHDR           szzô   gAMA  ¯È7Šé   tEXtSoftware Adobe ImageReadyqÉe<  ÉIDATxÚbüÿÿ?Ã@€ bŒŒŒD)>ÎÀ t®Ûÿc` ±4¾ ¤? ñAÛa1æ<@Œ`NA,* âx 
 ð©æ€XÇ_€ø7Cô H/Ò|€Ãç € Âë  å@j>È·   b~yy[[& b؇Ÿfx}éà ÿ;Ä1€ŽHôÇ" »§N30ôƒ|’b‰°0ÖÈHf¼ÁúïÑ#†?Ë—3Ü›5‹áÞ§O¿ ™ÌÀPˆÍ „Õ@Ëç-O`²å54xkj˜-,HJ\ÿ?~døPVÆpfï^†OG,†º ÃÀ`ïR|@BÚÎŽ»±‘‘——ìTþméR†ýýO !‰ »ÅÐ8_ò¹²•OSÂ$> “>}"ÎV4µßwì`ØßÓÃðâˆÀhš Ù
@p@Sû}& ­,*Ê ÐÝÍÀÈÍ
1AQ‘Áؘ¿§Ná·ÜÌŒANŽáìY i÷áÂï¦LaØsð (M€²«b<(í &xp@²š (ÁñÅÅ10þ*}ÿžALb9€60€ˆcà 9 éé…Ê   2¨sr2@˘½ „ì€xPVSRb`º˜}Ù€‘L(@E…=`ydÉ!^@y‡´||8!ÑS@,°TÈÙl††Wƒ ˆ%,`@[›B«WCø¡¡1t ÔûX.ü}ü˜áÏ­[_¾d …Ï ]³!ém@ ±@}*^x€®eF»wCf•þü   ñ!2 9$c£¿k×2ü®­eø}ý:Š¸_†„‚È v cŠn„ï‘ÁĉËQÅq”
¿,`ø‘˜ˆUN ì@ÓìA|€ ‚…€ ¨lgááÁî ho‡»»;ÞL€Ïràâ·0 ,ÀµÃ¨Áª«!!áçG¶åP†€`! Æß¿ãøó‡â6 Ô` @°¸ Jˆ`àk LŸÎÀ„Sš5!Lÿ"
P_ ±æ€_APð‚â˜7!"‚ ï@Ž %èßxñâ p; €˜ .:²ö+Ð÷ÿ°àÿ Ëãã1«^`œƒ0:`:‚mþ|f
ƒ"øÄÓAj\!ì
;€î¸ÄÿÐñüùÿ± 8LÍjþ!©ác@ÜĽ æÐn€ b€5J·«Ž} ÃØÙØԻ勣ªa6 2IÝ =@»`ž x] jÃÒÁ=& ¨á»wrsQÃwÅ
†ü|„‰äH/Ȩšs@³?@¢|!L    @ Á«ãÍÀ‚èˆû,LLÀʈ‹…a¨¬ïÚš5EEøSa0€CBŠ‹u|fßEÀºàû¿ 7(–A«c€ Bil€TJëùØÙì€NV&&„Áššhå:N€¦öç¿+>dx   ©;Ë$ „Ñ$[mŒÊ    1 ëvVä üú|?°!sX‚šéåhM2€ ÂÚ(]   m”òãÍXÍrsr’eù'`Á¶áêU†—_¿‚,_PŽ¥Q
@8›åË !Á]UUMP³ŒpØ;vû6Ãw` ûÙ „·c²’&@¡!ÀÅÅÅ Lr22‚‚XÕ¿Ö#wŸ<a¸
Œïß¾KX pbžŽ @ ìš-€¶áþ!uÍX
! #þ!Ud¯€–ÿ ãЊÜ52'”èšA ƒY@þáèœþ‡vN‹Ièœã@wÏ Ç}úWF,3    IEND®B`‚

I am very sorry for that :-)

Is there a way to use this wierd sequence of characters to recreate the image in php or in javascript (if you can even do that in javascript) by getting it from a mysql database?

Thanks.

EDIT: My question is: Can I say get that value of the image and put it in a database value, later to retrieve it?

And why, you might say? It is one of those things that is realy bugging me to find out, but I don't know how.

Was it helpful?

Solution

You can use the LONGBLOB MySQL data type to store it.

With PHP, you just have to send a image header when displaying it:

header("Content-Type: image/png");
// print image contents

OTHER TIPS

Javascript allows pixel manipulation http://beej.us/blog/2010/02/html5s-canvas-part-ii-pixel-manipulation/

You can put images as base64 encoded data in img src attributes http://websemantics.co.uk/online_tools/image_to_data_uri_convertor/

You could easily open an image in php with file_get_contents and base64 encode it to do the same thing as that converter.

You can use imagemagick to apply runtime transformations to the image http://php.net/manual/en/book.imagick.php

Yes! This is what Data URIs are for!

Yes, you can store binary data in SQL database.
For MySQL this field type is called blob, and represents non-fixed size of binary data.

Reference with some ready-to-use examples.

you can use Base64 Encoding/Decoding and store or transform the binary data as text.

In my case, I had to consume images from specific URLs. When tried to open these URLs I got a bunch of text similar to what you show here. I just placed the URL in an img tag and it worked.

<img src="URL" alt="HELLO">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top