[Python] Résolution d'image

Résolu
Bonjour,

j'aimerai récupérer la résolution d'une image avec Python, je suis sur Python 3.3.

J'ai préalablement tester la commande:

from PIL import Image
img = Image.open('test.jpg')
print img.size


Malheuresement, il me dit qu'il y as une erreur...

SyntaxError on line 3, invalid Syntax..

Merci d'avance les forumeurs :)

Cordialement, Mike

5 réponses

  1. Contributeur
    Que te marque "help(Image)" ?
    --
    La vrai soumission c'est quand les esclaves s'inquiètent du cours du coton.
    Char Snipeur
    1. Oulala, enormement de chose x)

          # 1995-09-09 fl   Created
          # 1996-03-11 fl   PIL release 0.0 (proof of concept)
          # 1996-04-30 fl   PIL release 0.1b1
          # 1999-07-28 fl   PIL release 1.0 final
          # 2000-06-07 fl   PIL release 1.1
          # 2000-10-20 fl   PIL release 1.1.1
          # 2001-05-07 fl   PIL release 1.1.2
          # 2002-03-15 fl   PIL release 1.1.3
          # 2003-05-10 fl   PIL release 1.1.4
          # 2005-03-28 fl   PIL release 1.1.5
          # 2006-12-02 fl   PIL release 1.1.6
          # 2009-11-15 fl   PIL release 1.1.7
          #
          # Copyright (c) 1997-2009 by Secret Labs AB.  All rights reserved.
          # Copyright (c) 1995-2009 by Fredrik Lundh.
          #
          # See the README file for information on usage and redistribution.
          #
      
      CLASSES
          builtins.object
              Image
              ImagePointHandler
              ImageTransformHandler
      
          class Image(builtins.object)
           |  Methods defined here:
           |
           |  __getattr__(self, name)
           |
           |  __init__(self)
           |
           |  __repr__(self)
           |
           |  convert(self, mode=None, data=None, dither=None, palette=0, colors=256)
           |      Convert to other pixel format
           |
           |  copy(self)
           |      Copy raster data
           |
           |  crop(self, box=None)
           |      Crop region from image
           |
           |  draft(self, mode, size)
           |      Configure image decoder
           |
           |  filter(self, filter)
           |      Apply environment filter to image
           |
           |  frombytes(self, data, decoder_name='raw', *args)
           |      Load data to image from a bytes object
           |
           |  fromstring(self, *args, **kw)
           |      Deprecated alias to frombytes
           |
           |  getbands(self)
           |      Get band names
           |
           |  getbbox(self)
           |      Get bounding box of actual data (non-zero pixels) in image
           |
           |  getcolors(self, maxcolors=256)
           |      Get colors from image, up to given limit
           |
           |  getdata(self, band=None)
           |      Get image data as sequence object.
           |
           |  getextrema(self)
           |      Get min/max value
           |
           |  getim(self)
           |      Get capsule pointer to internal image memory
           |
           |  getpalette(self)
           |      Get palette contents.
           |
           |  getpixel(self, xy)
           |      Get pixel value
           |
           |  getprojection(self)
           |      Get projection to x and y axes
           |
           |  histogram(self, mask=None, extrema=None)
           |      Take histogram of image
           |
           |  load(self)
           |      Explicitly load pixel data.
           |
           |  offset(self, xoffset, yoffset=None)
           |      (deprecated) Offset image in horizontal and/or vertical direction
           |
           |  paste(self, im, box=None, mask=None)
           |      Paste other image into region
           |
           |  point(self, lut, mode=None)
           |      Map image through lookup table
           |
           |  putalpha(self, alpha)
           |      Set alpha layer
           |
           |  putdata(self, data, scale=1.0, offset=0.0)
           |      Put data from a sequence object into an image.
           |
           |  putpalette(self, data, rawmode='RGB')
           |      Put palette data into an image.
           |
           |  putpixel(self, xy, value)
           |      Set pixel value
           |
           |  quantize(self, colors=256, method=0, kmeans=0, palette=None)
           |
           |  resize(self, size, resample=0)
           |      Resize image
           |
           |  rotate(self, angle, resample=0, expand=0)
           |      Rotate image.  Angle given as degrees counter-clockwise.
           |
           |  save(self, fp, format=None, **params)
           |      Save image to file or stream
           |
           |  seek(self, frame)
           |      Seek to given frame in sequence file
           |
           |  show(self, title=None, command=None)
           |      Display image (for debug purposes only)
           |
           |  split(self)
           |      Split image into bands
           |
           |  tell(self)
           |      Return current frame number
           |
           |  thumbnail(self, size, resample=0)
           |      Create thumbnail representation (modifies image in place)
           |
           |  tobitmap(self, name='image')
           |      Return image as an XBM bitmap
           |
           |  tobytes(self, encoder_name='raw', *args)
           |      Return image as a bytes object
           |
           |  tostring(self, *args, **kw)
           |      # Declare tostring as alias to tobytes
           |
           |  transform(self, size, method, data=None, resample=0, fill=1)
           |      Transform image
           |
           |  transpose(self, method)
           |      Transpose image (flip or rotate in 90 degree steps)
           |
           |  verify(self)
           |      Verify file contents.
           |
           |  ----------------------------------------------------------------------
           |  Data descriptors defined here:
           |
           |  __dict__
           |      dictionary for instance variables (if defined)
           |
           |  __weakref__
           |      list of weak references to the object (if defined)
           |
           |  ----------------------------------------------------------------------
           |  Data and other attributes defined here:
           |
           |  format = None
           |
           |  format_description = None
      
          class ImagePointHandler(builtins.object)
           |  Data descriptors defined here:
           |
           |  __dict__
           |      dictionary for instance variables (if defined)
           |
           |  __weakref__
           |      list of weak references to the object (if defined)
      
          class ImageTransformHandler(builtins.object)
           |  Data descriptors defined here:
           |
           |  __dict__
           |      dictionary for instance variables (if defined)
           |
           |  __weakref__
           |      list of weak references to the object (if defined)
      
      FUNCTIONS
          alpha_composite(im1, im2)
              Alpha composite im2 over im1.
      
          blend(im1, im2, alpha)
              Interpolate between images.
      
          coerce_e(value)
      
          composite(image1, image2, mask)
              Create composite image by blending images using a transparency mask
      
          eval(image, *args)
              Evaluate image expression
      
          fromarray(obj, mode=None)
      
          frombuffer(mode, size, data, decoder_name='raw', *args)
              Load image from bytes or buffer
      
          frombytes(mode, size, data, decoder_name='raw', *args)
              Load image from byte buffer
      
          fromstring(*args, **kw)
              Deprecated alias to frombytes
      
          getmodebandnames(mode)
      
          getmodebands(mode)
      
          getmodebase(mode)
      
          getmodetype(mode)
      
          init()
              Load all file format drivers.
      
          isDirectory(f)
      
          isImageType(t)
      
          isStringType(t)
      
          merge(mode, bands)
              Merge a set of single band images into a new multiband image.
      
          new(mode, size, color=0)
              Create a new image
      
          open(fp, mode='r')
              Open an image file, without loading the raster data
      
          preinit()
              Load standard file format drivers.
      
          register_extension(id, extension)
      
          register_mime(id, mimetype)
      
          register_open(id, factory, accept=None)
      
          register_save(id, driver)
      
      DATA
          ADAPTIVE = 1
          AFFINE = 0
          ANTIALIAS = 1
          BICUBIC = 3
          BILINEAR = 2
          CONTAINER = 2
          CUBIC = 3
          DEBUG = 0
          DEFAULT_STRATEGY = 0
          EXTENSION = {'.bmp': 'BMP', '.gif': 'GIF', '.pbm': 'PPM', '.pgm': 'PPM...
          EXTENT = 1
          FASTOCTREE = 2
          FILTERED = 1
          FIXED = 4
          FLIP_LEFT_RIGHT = 0
          FLIP_TOP_BOTTOM = 1
          FLOYDSTEINBERG = 3
          HUFFMAN_ONLY = 2
          ID = ['BMP', 'GIF', 'PPM', 'PNG']
          LINEAR = 2
          MAXCOVERAGE = 1
          MEDIANCUT = 0
          MESH = 4
          MIME = {'GIF': 'image/gif', 'PNG': 'image/png'}
          MODES = ['1', 'CMYK', 'F', 'I', 'L', 'P', 'RGB', 'RGBA', 'RGBX', 'YCbC...
          NEAREST = 0
          NONE = 0
          NORMAL = 0
          OPEN = {'BMP': (<class 'PIL.BmpImagePlugin.BmpImageFile'>, <function _...
          ORDERED = 1
          PERSPECTIVE = 2
          QUAD = 3
          RASTERIZE = 2
          RLE = 3
          ROTATE_180 = 3
          ROTATE_270 = 4
          ROTATE_90 = 2
          SAVE = {'BMP': <function _save>, 'GIF': <function _save>, 'PNG': <func...
          SEQUENCE = 1
          VERSION = '1.1.7'
          WEB = 0
          print_function = _Feature((2, 6, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0)...
      
      FILE
          c:\python33\lib\site-packages\pil\image.py
      
      


      Merci pour la rapidité de réponse
      1. Bonjour,

        la commande print en python 3+ ce fait comme ceci:

        print("mon texte")
        print(variable)


        print(img.size)
        1. Tu est mon dieu!
          Merci infiniment, cela fessais 3 ans que je n'avais pas refait de Python x)
          Problème résolu
          1. Contributeur
            Oui, en effet, "invalid syntax", pas "invalid member"
            D'ailleurs, je suis étonné que le membre "size" n'apparaisse pas dans la doc.