Skip to content

Bitmap ".eps" image have incorrect size and mode #6382

@mlove4u

Description

@mlove4u
  • OS: OSX 11.6
  • Python: 3.7.4
  • Pillow: 9.1.1
eps_file_path = "EPS_Bitmap.eps" # File was attached.
img = Image.open(eps_file_path)
print(img.mode, img.size)  # RGB (90, 60) --> correct: L, (500,333)

Am I doing it the wrong way? This is how I'm using it for now (getting data from %ImageData).Thank you.

def get_eps_info(eps_file_path):
    """
    https://mail.python.org/pipermail/image-sig/2005-September/003575.html
    Photoshop 6.0 SDK
    EPS Parameters for ImageData (Photoshop 3.0 and later)
    columns      Width of the image in pixels
    rows         Height of the image in pixels
    depth        Number of bits per channel. Must be 1 or 8
    mode         Image mode. Bitmap/grayscale = 1; Lab = 2; RGB = 3; CMYK = 4
    pad channels Number of other channels stored in the file.
                Ignored when reading...
    block size   Number of bytes per row per channel.
                 Will be either 1 or formula (below):
                 1 = Data is interleaved
                 (columns*depth+7)/8 = Data is stored in line interleaved format
                 or there is only one channel
    binary/ascii 1 = Data is in binary format
                 2 = Data is in hex ascii format
    data start   Entire PostScriptline immediately preceding the image data.
                This entire line should not occur elewhere in the PostScript
                header code, but it may occur at part of line
    """
    p = re.compile(rb'%ImageData:\s(\d.+)\s"beginimage"')
    with open(eps_file_path, "rb") as f:
        for line in f.readlines():
            info = re.match(p, line)
            if info:
                columns, rows, depth, mode, pad_channels, block_size, data_format = map(
                    lambda x: int(x), info.group(1).decode().split(" "))
                return columns, rows, mode
print(get_eps_info(eps_file_path))  # (500, 333, 1)

EPS_Bitmap.eps.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions