def capture(self, output, format=None, use_video_port=False, resize=None, splitter_port=0, bayer=False, **options):
    '\n        Capture an image from the camera, storing it in *output*.\n\n        If *output* is a string, it will be treated as a filename for a new\n        file which the image will be written to. If *output* is not a string,\n        but is an object with a ``write`` method, it is assumed to be a\n        file-like object and the image data is appended to it (the\n        implementation only assumes the object has a ``write`` method - no\n        other methods are required but ``flush`` will be called at the end of\n        capture if it is present). If *output* is not a string, and has no\n        ``write`` method it is assumed to be a writeable object implementing\n        the buffer protocol. In this case, the image data will be written\n        directly to the underlying buffer (which must be large enough to accept\n        the image data).\n\n        If *format* is ``None`` (the default), the method will attempt to guess\n        the required image format from the extension of *output* (if it\'s a\n        string), or from the *name* attribute of *output* (if it has one). In\n        the case that the format cannot be determined, a\n        :exc:`PiCameraValueError` will be raised.\n\n        If *format* is not ``None``, it must be a string specifying the format\n        that you want the image output in. The format can be a MIME-type or\n        one of the following strings:\n\n        * ``\'jpeg\'`` - Write a JPEG file\n        * ``\'png\'`` - Write a PNG file\n        * ``\'gif\'`` - Write a GIF file\n        * ``\'bmp\'`` - Write a Windows bitmap file\n        * ``\'yuv\'`` - Write the raw image data to a file in YUV420 format\n        * ``\'rgb\'`` - Write the raw image data to a file in 24-bit RGB format\n        * ``\'rgba\'`` - Write the raw image data to a file in 32-bit RGBA format\n        * ``\'bgr\'`` - Write the raw image data to a file in 24-bit BGR format\n        * ``\'bgra\'`` - Write the raw image data to a file in 32-bit BGRA format\n        * ``\'raw\'`` - Deprecated option for raw captures; the format is taken\n          from the deprecated :attr:`raw_format` attribute\n\n        The *use_video_port* parameter controls whether the camera\'s image or\n        video port is used to capture images. It defaults to ``False`` which\n        means that the camera\'s image port is used. This port is slow but\n        produces better quality pictures. If you need rapid capture up to the\n        rate of video frames, set this to ``True``.\n\n        When *use_video_port* is ``True``, the *splitter_port* parameter\n        specifies the port of the video splitter that the image encoder will be\n        attached to. This defaults to ``0`` and most users will have no need to\n        specify anything different. This parameter is ignored when\n        *use_video_port* is ``False``. See :ref:`mmal` for more information\n        about the video splitter.\n\n        If *resize* is not ``None`` (the default), it must be a two-element\n        tuple specifying the width and height that the image should be resized\n        to.\n\n        .. warning::\n\n            If *resize* is specified, or *use_video_port* is ``True``, Exif\n            metadata will **not** be included in JPEG output. This is due to an\n            underlying firmware limitation.\n\n        Certain file formats accept additional options which can be specified\n        as keyword arguments. Currently, only the ``\'jpeg\'`` encoder accepts\n        additional options, which are:\n\n        * *quality* - Defines the quality of the JPEG encoder as an integer\n          ranging from 1 to 100. Defaults to 85. Please note that JPEG quality\n          is not a percentage and `definitions of quality`_ vary widely.\n\n        * *restart* - Defines the restart interval for the JPEG encoder as a\n          number of JPEG MCUs. The actual restart interval used will be a\n          multiple of the number of MCUs per row in the resulting image.\n\n        * *thumbnail* - Defines the size and quality of the thumbnail to embed\n          in the Exif metadata. Specifying ``None`` disables thumbnail\n          generation.  Otherwise, specify a tuple of ``(width, height,\n          quality)``. Defaults to ``(64, 48, 35)``.\n\n        * *bayer* - If ``True``, the raw bayer data from the camera\'s sensor\n          is included in the Exif metadata.\n\n        .. note::\n\n            The so-called "raw" formats listed above (``\'yuv\'``, ``\'rgb\'``,\n            etc.) do not represent the raw bayer data from the camera\'s sensor.\n            Rather they provide access to the image data after GPU processing,\n            but before format encoding (JPEG, PNG, etc). Currently, the only\n            method of accessing the raw bayer data is via the *bayer* parameter\n            described above.\n\n        .. versionchanged:: 1.0\n            The *resize* parameter was added, and raw capture formats can now\n            be specified directly\n\n        .. versionchanged:: 1.3\n            The *splitter_port* parameter was added, and *bayer* was added as\n            an option for the ``\'jpeg\'`` format\n\n        .. versionchanged:: 1.11\n            Support for buffer outputs was added.\n\n        .. _definitions of quality: http://photo.net/learn/jpeg/#qual\n        '
    if (format == 'raw'):
        warnings.warn(PiCameraDeprecated('The "raw" format option is deprecated; specify the required format directly instead ("yuv", "rgb", etc.)'))
    if (use_video_port and bayer):
        raise PiCameraValueError('bayer is only valid with still port captures')
    if ('burst' in options):
        raise PiCameraValueError('burst is only valid with capture_sequence or capture_continuous')
    with self._encoders_lock:
        (camera_port, output_port) = self._get_ports(use_video_port, splitter_port)
        format = self._get_image_format(output, format)
        encoder = self._get_image_encoder(camera_port, output_port, format, resize, **options)
        if use_video_port:
            self._encoders[splitter_port] = encoder
    try:
        if bayer:
            camera_port.params[mmal.MMAL_PARAMETER_ENABLE_RAW_CAPTURE] = True
        encoder.start(output)
        if (not encoder.wait(self.CAPTURE_TIMEOUT)):
            raise PiCameraRuntimeError('Timed out waiting for capture to end')
    finally:
        encoder.close()
        with self._encoders_lock:
            if use_video_port:
                del self._encoders[splitter_port]
Capture an image from the camera, storing it in *output*.

If *output* is a string, it will be treated as a filename for a new
file which the image will be written to. If *output* is not a string,
but is an object with a ``write`` method, it is assumed to be a
file-like object and the image data is appended to it (the
implementation only assumes the object has a ``write`` method - no
other methods are required but ``flush`` will be called at the end of
capture if it is present). If *output* is not a string, and has no
``write`` method it is assumed to be a writeable object implementing
the buffer protocol. In this case, the image data will be written
directly to the underlying buffer (which must be large enough to accept
the image data).

If *format* is ``None`` (the default), the method will attempt to guess
the required image format from the extension of *output* (if it's a
string), or from the *name* attribute of *output* (if it has one). In
the case that the format cannot be determined, a
:exc:`PiCameraValueError` will be raised.

If *format* is not ``None``, it must be a string specifying the format
that you want the image output in. The format can be a MIME-type or
one of the following strings:

* ``'jpeg'`` - Write a JPEG file
* ``'png'`` - Write a PNG file
* ``'gif'`` - Write a GIF file
* ``'bmp'`` - Write a Windows bitmap file
* ``'yuv'`` - Write the raw image data to a file in YUV420 format
* ``'rgb'`` - Write the raw image data to a file in 24-bit RGB format
* ``'rgba'`` - Write the raw image data to a file in 32-bit RGBA format
* ``'bgr'`` - Write the raw image data to a file in 24-bit BGR format
* ``'bgra'`` - Write the raw image data to a file in 32-bit BGRA format
* ``'raw'`` - Deprecated option for raw captures; the format is taken
  from the deprecated :attr:`raw_format` attribute

The *use_video_port* parameter controls whether the camera's image or
video port is used to capture images. It defaults to ``False`` which
means that the camera's image port is used. This port is slow but
produces better quality pictures. If you need rapid capture up to the
rate of video frames, set this to ``True``.

When *use_video_port* is ``True``, the *splitter_port* parameter
specifies the port of the video splitter that the image encoder will be
attached to. This defaults to ``0`` and most users will have no need to
specify anything different. This parameter is ignored when
*use_video_port* is ``False``. See :ref:`mmal` for more information
about the video splitter.

If *resize* is not ``None`` (the default), it must be a two-element
tuple specifying the width and height that the image should be resized
to.

.. warning::

    If *resize* is specified, or *use_video_port* is ``True``, Exif
    metadata will **not** be included in JPEG output. This is due to an
    underlying firmware limitation.

Certain file formats accept additional options which can be specified
as keyword arguments. Currently, only the ``'jpeg'`` encoder accepts
additional options, which are:

* *quality* - Defines the quality of the JPEG encoder as an integer
  ranging from 1 to 100. Defaults to 85. Please note that JPEG quality
  is not a percentage and `definitions of quality`_ vary widely.

* *restart* - Defines the restart interval for the JPEG encoder as a
  number of JPEG MCUs. The actual restart interval used will be a
  multiple of the number of MCUs per row in the resulting image.

* *thumbnail* - Defines the size and quality of the thumbnail to embed
  in the Exif metadata. Specifying ``None`` disables thumbnail
  generation.  Otherwise, specify a tuple of ``(width, height,
  quality)``. Defaults to ``(64, 48, 35)``.

* *bayer* - If ``True``, the raw bayer data from the camera's sensor
  is included in the Exif metadata.

.. note::

    The so-called "raw" formats listed above (``'yuv'``, ``'rgb'``,
    etc.) do not represent the raw bayer data from the camera's sensor.
    Rather they provide access to the image data after GPU processing,
    but before format encoding (JPEG, PNG, etc). Currently, the only
    method of accessing the raw bayer data is via the *bayer* parameter
    described above.

.. versionchanged:: 1.0
    The *resize* parameter was added, and raw capture formats can now
    be specified directly

.. versionchanged:: 1.3
    The *splitter_port* parameter was added, and *bayer* was added as
    an option for the ``'jpeg'`` format

.. versionchanged:: 1.11
    Support for buffer outputs was added.

.. _definitions of quality: http://photo.net/learn/jpeg/#qual
def capture(self, output, format=None, use_video_port=False, resize=None, splitter_port=0, bayer=False, **options):
    '\n        Capture an image from the camera, storing it in *output*.\n\n        If *output* is a string, it will be treated as a filename for a new\n        file which the image will be written to. If *output* is not a string,\n        but is an object with a ``write`` method, it is assumed to be a\n        file-like object and the image data is appended to it (the\n        implementation only assumes the object has a ``write`` method - no\n        other methods are required but ``flush`` will be called at the end of\n        capture if it is present). If *output* is not a string, and has no\n        ``write`` method it is assumed to be a writeable object implementing\n        the buffer protocol. In this case, the image data will be written\n        directly to the underlying buffer (which must be large enough to accept\n        the image data).\n\n        If *format* is ``None`` (the default), the method will attempt to guess\n        the required image format from the extension of *output* (if it\'s a\n        string), or from the *name* attribute of *output* (if it has one). In\n        the case that the format cannot be determined, a\n        :exc:`PiCameraValueError` will be raised.\n\n        If *format* is not ``None``, it must be a string specifying the format\n        that you want the image output in. The format can be a MIME-type or\n        one of the following strings:\n\n        * ``\'jpeg\'`` - Write a JPEG file\n        * ``\'png\'`` - Write a PNG file\n        * ``\'gif\'`` - Write a GIF file\n        * ``\'bmp\'`` - Write a Windows bitmap file\n        * ``\'yuv\'`` - Write the raw image data to a file in YUV420 format\n        * ``\'rgb\'`` - Write the raw image data to a file in 24-bit RGB format\n        * ``\'rgba\'`` - Write the raw image data to a file in 32-bit RGBA format\n        * ``\'bgr\'`` - Write the raw image data to a file in 24-bit BGR format\n        * ``\'bgra\'`` - Write the raw image data to a file in 32-bit BGRA format\n        * ``\'raw\'`` - Deprecated option for raw captures; the format is taken\n          from the deprecated :attr:`raw_format` attribute\n\n        The *use_video_port* parameter controls whether the camera\'s image or\n        video port is used to capture images. It defaults to ``False`` which\n        means that the camera\'s image port is used. This port is slow but\n        produces better quality pictures. If you need rapid capture up to the\n        rate of video frames, set this to ``True``.\n\n        When *use_video_port* is ``True``, the *splitter_port* parameter\n        specifies the port of the video splitter that the image encoder will be\n        attached to. This defaults to ``0`` and most users will have no need to\n        specify anything different. This parameter is ignored when\n        *use_video_port* is ``False``. See :ref:`mmal` for more information\n        about the video splitter.\n\n        If *resize* is not ``None`` (the default), it must be a two-element\n        tuple specifying the width and height that the image should be resized\n        to.\n\n        .. warning::\n\n            If *resize* is specified, or *use_video_port* is ``True``, Exif\n            metadata will **not** be included in JPEG output. This is due to an\n            underlying firmware limitation.\n\n        Certain file formats accept additional options which can be specified\n        as keyword arguments. Currently, only the ``\'jpeg\'`` encoder accepts\n        additional options, which are:\n\n        * *quality* - Defines the quality of the JPEG encoder as an integer\n          ranging from 1 to 100. Defaults to 85. Please note that JPEG quality\n          is not a percentage and `definitions of quality`_ vary widely.\n\n        * *restart* - Defines the restart interval for the JPEG encoder as a\n          number of JPEG MCUs. The actual restart interval used will be a\n          multiple of the number of MCUs per row in the resulting image.\n\n        * *thumbnail* - Defines the size and quality of the thumbnail to embed\n          in the Exif metadata. Specifying ``None`` disables thumbnail\n          generation.  Otherwise, specify a tuple of ``(width, height,\n          quality)``. Defaults to ``(64, 48, 35)``.\n\n        * *bayer* - If ``True``, the raw bayer data from the camera\'s sensor\n          is included in the Exif metadata.\n\n        .. note::\n\n            The so-called "raw" formats listed above (``\'yuv\'``, ``\'rgb\'``,\n            etc.) do not represent the raw bayer data from the camera\'s sensor.\n            Rather they provide access to the image data after GPU processing,\n            but before format encoding (JPEG, PNG, etc). Currently, the only\n            method of accessing the raw bayer data is via the *bayer* parameter\n            described above.\n\n        .. versionchanged:: 1.0\n            The *resize* parameter was added, and raw capture formats can now\n            be specified directly\n\n        .. versionchanged:: 1.3\n            The *splitter_port* parameter was added, and *bayer* was added as\n            an option for the ``\'jpeg\'`` format\n\n        .. versionchanged:: 1.11\n            Support for buffer outputs was added.\n\n        .. _definitions of quality: http://photo.net/learn/jpeg/#qual\n        '
    if (format == 'raw'):
        warnings.warn(PiCameraDeprecated('The "raw" format option is deprecated; specify the required format directly instead ("yuv", "rgb", etc.)'))
    if (use_video_port and bayer):
        raise PiCameraValueError('bayer is only valid with still port captures')
    if ('burst' in options):
        raise PiCameraValueError('burst is only valid with capture_sequence or capture_continuous')
    with self._encoders_lock:
        (camera_port, output_port) = self._get_ports(use_video_port, splitter_port)
        format = self._get_image_format(output, format)
        encoder = self._get_image_encoder(camera_port, output_port, format, resize, **options)
        if use_video_port:
            self._encoders[splitter_port] = encoder
    try:
        if bayer:
            camera_port.params[mmal.MMAL_PARAMETER_ENABLE_RAW_CAPTURE] = True
        encoder.start(output)
        if (not encoder.wait(self.CAPTURE_TIMEOUT)):
            raise PiCameraRuntimeError('Timed out waiting for capture to end')
    finally:
        encoder.close()
        with self._encoders_lock:
            if use_video_port:
                del self._encoders[splitter_port]