[Image-SIG] Embedding text in image files

Bernd Preusing b.preusing at web.de
Sun Apr 25 12:19:47 EDT 2004


On Sun, 25 Apr 2004 05:04:08 -0500, Kent Tenney <kent at springfed.com> wrote:

Ok, sorry....

in that case I have the exact same problem, plus
losless rotation (no loss of EXIF, IPTC and
image information itself). JPEG images opened and saved
with PIL tend to be much smaller than the originals,
I believe according higher compression.

> Sorry, I didn't make myself clear.
>
> By "options" I mean things like
> EXIF, IPTC, jpeg comments ...
>
> I want to store text (data) in the file,
> not the image.
>
> Thanks,
> Kent
>
>
>
> Bernd Preusing wrote:
>
>> On Sat, 24 Apr 2004 14:43:56 -0500, Kent Tenney <kent at springfed.com> 
>> wrote:
>>
>>> Howdy,
>>>
>>> I'm using PIL 1.1.5a1 with Python 2.3.3 on Windows,
>>> and would like to put textual information in
>>> image files.
>>>
>>> What options are available for writing
>>> text to jpeg, gif and png ?
>>
>>
>> Hiho,
>>
>> what do you mean by "options"?
>>
>> IMHO the simplest way is something like this:
>>
>>  from PIL import ImageDraw, ImageFont
>> # input: img, fontPath, text1
>> font1 = ImageFont.load(fontPath)
>> draw1 = ImageDraw.Draw(img)
>> tSizeX, tSizeY = draw1.textsize(text, font=font1)
>> # calculate x and y...
>> draw.text((x, y), text1, font=font1, fill='#000000')
>> ... save img
>>
>> I have used this with PIL 1.1.4 only.
>> To my experience text looks nicer on RGB images
>> (jpeg), so I convert palette images to RGB before
>> placing objects.
>>
>> If you want more complex effects like shadow text
>> or transparent text, take a look at the filters page
>> and source code of PyAlbum http://pyalbum.sourceforge.net/Filters.html
>>
>> Best regards
>>    Bernd
>>
>> _______________________________________________
>> Image-SIG maillist  -  Image-SIG at python.org
>> http://mail.python.org/mailman/listinfo/image-sig
>>
>>
>
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>



-- 
Bernd Preusing
mailto://b.preusing@web.de



More information about the Image-SIG mailing list