[Zope-dev] Hexadecimal-sequence of a jpeg-image from Python
Juan Javier Carrera Obrero
jcarrera@uco.es
Mon, 19 Nov 2001 12:49:01 +0100
This is a multi-part message in MIME format.
------=_NextPart_000_0005_01C170F8.908C5200
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hello,
I am trying to generate a RTF (Rich Text Format) file with images from =
Python 2.1.
Firstly with MS-Word 97, I have saved a file with RTF format which =
contained a jpeg-image. I have edited this RTF file with a text editor, =
and I have seen as MS-Word converts the jpeg-image in a hexadecimal =
sequence.
I would like to do the same process for converting a binary jpeg-image =
in a hexadecimal-sequence from Python. For it, I have maked the next =
process (using Python 2.1 and PIL library, in Windows):
import Image
im =3D Image.open("photo.jpg")
file =3D open("filename.txt", "wb")
file.write ( im.tostring ( "hex") )
file.close()
With this process, I obtain a hexadecimal-sequence of the jpeg-image (in =
"filename.txt"). However, I am trying to work with this sequence but I =
can not do anything with it. I think this sequence is no valid, because =
I have replaced from a text editor the hexadecimal-sequence of MS-Word =
to the hexadecimal-sequence obtained by me, however when I open this =
file, MS-Word do not show the jpeg-image.=20
Also, the hexadecimal-sequence generates by MS-Word is not equal to the =
hexadecimal-sequence generates by the previous process.
Anybody could help me about this ?
Thank you very much.
------=_NextPart_000_0005_01C170F8.908C5200
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hello,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I am trying to generate a RTF (Rich =
Text Format)=20
file with images from Python 2.1.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Firstly with MS-Word 97, I have saved a =
file with=20
RTF format which contained a jpeg-image. I have edited this RTF =
file with a=20
text editor, and I have seen as MS-Word converts the jpeg-image in a =
hexadecimal=20
sequence.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>I would like to do the same process for =
converting=20
a binary jpeg-image in a hexadecimal-sequence from Python. For it, I =
have maked=20
the next process (using Python 2.1 and PIL library, in =
Windows):</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>import Image</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>im =3D =
Image.open("photo.jpg")</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>file =3D open("filename.txt", =
"wb")</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>file.write ( im.tostring ( "hex") =
)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>file.close()</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>With this process, I obtain a =
hexadecimal-sequence=20
of the jpeg-image (in "filename.txt"). However, I am trying to work with =
this=20
sequence but I can not do anything with it. I think this sequence is no =
valid,=20
because I have replaced from a text editor the hexadecimal-sequence =
of=20
MS-Word to the hexadecimal-sequence obtained by me, however when I open =
this=20
file, MS-Word do not show the jpeg-image. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Also, the hexadecimal-sequence =
generates by MS-Word=20
is not equal to the hexadecimal-sequence generates by the previous=20
process.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Anybody could help me about this =
?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Thank you very =
much.</FONT></DIV></BODY></HTML>
------=_NextPart_000_0005_01C170F8.908C5200--