compatible image type

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

    compatible image type

    hi
    in my application a file selection by user returns a pathname string
    like F:/images/png/my.png or F:/docs/text/somedoc.txt ....etc.
    I can get the extension using
    extn=string.spl it(os.path.base name(pathname), '.' )[1]

    then later on i want to create a Photoimage using

    ImageTk.PhotoIm age(file=pathna me) and display it on a canvas.

    the extn can be anything ..even zip or bat ,doc whatever depending on
    user selection...I want to put someway to raise an error message to
    the user if he selects a file with extension not of a compatible image
    type for PhotoImage.How should i do this? should i check 'extn' to a
    list of compatible image type extensions(some thing like
    [''jpg','jpeg',' png','gif'...] ) or is there a better way?

    gordon
  • Marc 'BlackJack' Rintsch

    #2
    Re: compatible image type

    On Fri, 04 Jul 2008 01:15:30 -0700, gordon wrote:

    then later on i want to create a Photoimage using
    >
    ImageTk.PhotoIm age(file=pathna me) and display it on a canvas.
    >
    the extn can be anything ..even zip or bat ,doc whatever depending on
    user selection...I want to put someway to raise an error message to
    the user if he selects a file with extension not of a compatible image
    type for PhotoImage.How should i do this? should i check 'extn' to a
    list of compatible image type extensions(some thing like
    [''jpg','jpeg',' png','gif'...] ) or is there a better way?
    Just catch the exception raised by `PhotoImage` if a non compatible file
    was selected!?

    Ciao,
    Marc 'BlackJack' Rintsch

    Comment

    • Larry Bates

      #3
      Re: compatible image type

      gordon wrote:
      hi
      in my application a file selection by user returns a pathname string
      like F:/images/png/my.png or F:/docs/text/somedoc.txt ....etc.
      I can get the extension using
      extn=string.spl it(os.path.base name(pathname), '.' )[1]
      >
      then later on i want to create a Photoimage using
      >
      ImageTk.PhotoIm age(file=pathna me) and display it on a canvas.
      >
      the extn can be anything ..even zip or bat ,doc whatever depending on
      user selection...I want to put someway to raise an error message to
      the user if he selects a file with extension not of a compatible image
      type for PhotoImage.How should i do this? should i check 'extn' to a
      list of compatible image type extensions(some thing like
      [''jpg','jpeg',' png','gif'...] ) or is there a better way?
      >
      gordon
      You do know that there is a method for getting extensions easily?

      extn = os.path.splitex t(pathname)[1]

      Note: It does include the '.' separator (e.g. it returns .txt) but that's easy
      to handle.

      If you just catch the exception (as Mark suggested), you don't even have to look
      at the extension.

      -Larry

      Comment

      Working...