[PIL]: Image size in runtime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrea Gavana

    #1

    [PIL]: Image size in runtime

    Hello NG,

    sorry if the message is not strictly Python-related, but it is
    fantastically impossible to send post to Image-SIG.
    I am using PIL to load and display some pictures (via wxPython) in a
    GUI. I have added the ability for the user to change the linear
    dimensions of the image (in pixels) and the quality of the image in
    order for the image to be saved in another file.
    I was wondering if is there a way to know in advance, based on the
    pixel dimensions specified by the user and by the image quality, which
    file size (in
    bytes) I will obtain for the new image (approximativel y). Is there a
    way to obtain such result without actually saving the image?

    Thanks for any hint.

    Andrea.

    "Imaginatio n Is The Only Weapon In The War Against Reality."

  • Scott David Daniels

    #2
    Re: [PIL]: Image size in runtime

    Andrea Gavana wrote:[color=blue]
    > I am using PIL to load and display some pictures (via wxPython) in a
    > GUI. I have added the ability for the user to change the linear
    > dimensions of the image (in pixels) and the quality of the image in
    > order for the image to be saved in another file.
    > I was wondering if is there a way to know in advance, based on the
    > pixel dimensions specified by the user and by the image quality, which
    > file size (in
    > bytes) I will obtain for the new image (approximativel y). Is there a
    > way to obtain such result without actually saving the image?[/color]

    The answer is really no, since it depends on the complexity of the
    picture. A solid square of one color is highly compressible, and a
    photo of a tall ship's rigging is relatively hard to compress. You
    can compress to a cStringIO file (and so not have to actually hit
    the disk) to get a size, ten discard the cStringIO object.

    --
    --Scott David Daniels
    scott.daniels@a cm.org

    Comment

    Working...