Re: [Image-SIG] Converting to zebra (ZPL) format

2005-06-17 Thread Joao S. O. Bueno Calligaris
Hi Peter,

despite Fredik's lengthy and carefull answer, I think that is not what 
you were asking for - his program is suitable to print images inpout 
inline inside a Python program as sequences of 0 and 1's. 

But I think you were asking for a way to print a generic image read 
from a disk file.

I can code that for you, if you wish so - just write me if no one else 
mailed yu a complete answer, and tell me more details about the 
images you want to print, maximum width of the printer, and stuff 
like that.

I also did nt understand if the Hexadecimal data you send to the  
printer is actual ASCII - i.e. You send a real  "F" character to get 
four dots "", or if you send a 15 decimal value standing for 0x0F

ANd please, do confirm that you have PIL installed (call a interactive 
Python shell and type 'import Image' there if you are not sure).

Regards,
JS
-><-



On Friday 17 June 2005 01:22, Peter Dempsey wrote:
> Hi folks, I'm a newbie to python so please be gentle.
>
> I want to convert an image to a format suitable for use in a Zebra
> label printer. The data sent to the printer consists of a string of
> hex characters. Each byte converts to a binary set of dots on the
> label.
>
> FF becomes 
> A5 becomes 10100101
>
> So a string like this becomes a right-angle triangle...
>
> 18,3^m
> F0FFFFF00000F0FF
>
> The 18 says how many bytes in the image, 3 says how many bytes wide
> the image is. So the string above becomes...
>
> F0->  
> FF->  
> FFF000->  
> 00->  
> F0->  
> FF->  
>
> I'm sure it's a simple task, I mean, the image is converted to a
> hex representation of the raw image.
>
> I've had some success doing it the hard way with python, importing
> a pcx image and going through it byte by byte but I'm sure there's
> an easier way.
>
> Any suggestions would be super.
>
> I don't have my code here at home. I can post it tomorrow if it
> helps.
>
> Thanks,
>
> Peter
> ___
> Image-SIG maillist  -  Image-SIG@python.org
> http://mail.python.org/mailman/listinfo/image-sig
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] Converting CMYK JPG image to RGB

2005-06-17 Thread kevin
I know the problem you mention, but I also thought that a recent version of 
PIL fixed it... I could be wrong though.

However - the other option would be to use ICC profiles to do color 
conversion.  If you want REALLY accurate conversion, this is the way to go. 
I wrote a wrapper module called pyCMS that uses the littleCMS library to do 
ICC conversions.  See:  http://www.cazabon.com/pyCMS

Kevin.
- Original Message - 
From: "marc birot" <[EMAIL PROTECTED]>
To: 
Sent: Friday, June 17, 2005 6:01 AM
Subject: [Image-SIG] Converting CMYK JPG image to RGB


> Hello,
>
> I'm trying  to convert CMYK Jpg  files to RGB Jpg  files using
> (Image.open("cmyk_image.jpg").convert("RGB"))...
> The result shows very wrong colours.
>
> After checking the Image-SIG archives (Aug 2004) i found the following :
>
> "...Older versions of Photoshop generated broken CMYK files, and PIL
> attempts to compensate for this. try commenting out the following lines
> in PIL/JpegImagePlugin.py, and let me know if it helps:
> if self.mode == "CMYK" and self.info.has_key("adobe"):
>rawmode = "CMYK;I" # Photoshop 2.5 is broken! ..."
>
> Well, i tried and it does not work. The result i get is close to a
> 'negative' of the original picture ( not too close).
>
> Any suggestion to help on this problem ?  :)
>
> Marc
> ___
> Image-SIG maillist  -  Image-SIG@python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
> 

___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


[Image-SIG] Converting CMYK JPG image to RGB

2005-06-17 Thread marc birot
Hello,

I'm trying  to convert CMYK Jpg  files to RGB Jpg  files using 
(Image.open("cmyk_image.jpg").convert("RGB"))...
The result shows very wrong colours.

After checking the Image-SIG archives (Aug 2004) i found the following :

"...Older versions of Photoshop generated broken CMYK files, and PIL
attempts to compensate for this. try commenting out the following lines
in PIL/JpegImagePlugin.py, and let me know if it helps:
if self.mode == "CMYK" and self.info.has_key("adobe"):
rawmode = "CMYK;I" # Photoshop 2.5 is broken! ..."

Well, i tried and it does not work. The result i get is close to a 
'negative' of the original picture ( not too close).

Any suggestion to help on this problem ?  :)

Marc
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] Extended Mail

2005-06-17 Thread Microsoft LISTSERV Server (14.3)
> Encrypted message is available.
Unknown command - "ENCRYPTED". Try HELP.

Summary of resource utilization
---
 CPU time:0.000 secDevice I/O:4
 Overhead CPU:0.000 secPaging I/O:0
 CPU model: 933MHz Pentium III 256k (1152M)
 Job origin:  image-sig@PYTHON.ORG
___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig


Re: [Image-SIG] Converting to zebra (ZPL) format

2005-06-17 Thread Fredrik Lundh
Peter Dempsey wrote:

> Hi folks, I'm a newbie to python so please be gentle.
>
> I want to convert an image to a format suitable for use in a Zebra label
> printer. The data sent to the printer consists of a string of hex characters.
> Each byte converts to a binary set of dots on the label.
>
> FF becomes 
> A5 becomes 10100101
>
> So a string like this becomes a right-angle triangle...
>
> 18,3^m
> F0FFFFF00000F0FF
>
> The 18 says how many bytes in the image, 3 says how many bytes wide the image
> is. So the string above becomes...
>
> F0 -> 
> FF -> 
> FFF000 -> 
> 00 -> 
> F0 -> 
> FF -> 
>
> I'm sure it's a simple task, I mean, the image is converted to a hex
> representation of the raw image.
>
> I've had some success doing it the hard way with python, importing a pcx image
> and going through it byte by byte but I'm sure there's an easier way.
>
> Any suggestions would be super.

how about:

import Image

#
# step 1) convert example to pil image

data = (
"",
"",
"",
"",
"",
"",
)

height = len(data)
width = len(data[0])

im = Image.new("1", (width, height), 0)

# convert data to list of values
pixels = []
for row in data:
pixels.extend([1-int(ch) for ch in row])

im.putdata(pixels)

#
# step 2) convert it back to a hex string

data = im.tostring("raw", "1;I")
size = len(data)
data = ["%02X" % ord(byte) for byte in data]

print "%d,%d^m" % (size, (im.size[0]+7)/8)
print "".join(data)

# end

things to notice:

- step 1 can of course be replaced with some other way
to create a mode "1" image

- mode "1" images treat "1" as white and "0" as black.

- the tostring arguments are a bit magical.  some info can
be found here: http://effbot.org/imagingbook/decoder.htm

- [blah for blah in blah] is a list comprehension.  if you're
using Python 2.4, you can omit the brackets (which turns
it into a generator expression, but the result is the same)

- (blah+7)/8 converts the number of pixels to a number of
bytes, rounding up to the nearest byte.  to be future safe,
you might wish to use "//" instead of "/".





___
Image-SIG maillist  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig