[Zope-dev] Binary Image File in Hexadecimal Format
Juan Javier Carrera Obrero
jcarrera@uco.es
Thu, 15 Nov 2001 15:25:51 +0100
This is a multi-part message in MIME format.
------=_NextPart_000_0007_01C16DE9.CF2376E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hello,
I am generating a RTF file from Python 2.1 with Zope 2.4, using the =
"Rich Text Format (RTF) Version 1.6 Specification" =
(http://msdn.microsoft.com/library/specs/rtfspec.htm).
But I can not include a "jpg" image in the RTF file. For including the =
"jpg" image file, firstly, I have obtainted the hexadecimal =
representation of the image with Image.encode("hex") from PIL library:
Import Image
img =3D Image.open("photo.jpg")
file =3D open("filename","wb")
file.write(img.encode("hex"))
file.close()
However, this hexadecimal representation is no good, because when, for =
example, I save the same image with Microsoft Word in RTF format, these =
representations no match.
Anybody can help me ?
Thank you very much.
------=_NextPart_000_0007_01C16DE9.CF2376E0
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 generating a RTF file from Python =
2.1 with=20
Zope 2.4, u</FONT><FONT face=3DArial size=3D2>sing the "Rich Text =
Format (RTF)=20
Version 1.6 Specification" (<A=20
href=3D"http://msdn.microsoft.com/library/specs/rtfspec.htm">http://msdn.=
microsoft.com/library/specs/rtfspec.htm</A>).</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>But I can not include a "jpg" =
image in the RTF=20
file. For including the "jpg" image file, firstly, I have obtainted the=20
hexadecimal representation of the image with Image.encode("hex") from =
PIL=20
library:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Import Image</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>img =3D =
Image.open("photo.jpg")</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>file =3D =
open("filename","wb")</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>file.write(img.encode("hex"))</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>file.close()</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>However, this hexadecimal =
representation is no=20
good, because when, for example, I save the same image with Microsoft =
Word in=20
RTF format, these representations no match.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Anybody can help me ?</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Thank you very much.</FONT></DIV>
<DIV> </DIV></BODY></HTML>
------=_NextPart_000_0007_01C16DE9.CF2376E0--