\HeaderA{readImage}{Image I/O}{readImage}
\aliasA{writeImage}{readImage}{writeImage}
\begin{Description}\relax
Functions to read and write images from/to files and URL's.
The supported image formats depend on the capabilities of ImageMagick.
\end{Description}
\begin{Usage}
\begin{verbatim}
  readImage(files, colormode)
  writeImage(x, files, quality = 100)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{files}] A character vector of file names or URLs. If missing, an
interactive file chooser is displayed.
\item[\code{x}] An \code{\LinkA{Image}{Image.Rdash.class}} object or an array.
\item[\code{quality}] A numeric, ranging from 1 to 100. Default is 100.
\item[\code{colormode}] Deprecated.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
When writing images in formats supporting lossy compression (like JPEG),
the quality can be specified used a \code{quality} value in the
range \code{[1,100]}. The best quality is obtained with 100.

The file format is deduced from the file name extension.

\code{ImageMagick} is used to perform all image I/O operations. Therefore,
the package supports all the file types supported by \code{ImageMagick}.

When reading images, files of different formats can be mixed in any
sequence, including mixing single 2D images with TIFF image stacks.
The result will contain a stack with all images and stacks,
at the size of the first image read. Subsequent images are cropped (if
larger) or filled with background (if smaller).
\end{Details}
\begin{Value}
\code{readImage} returns a new \code{Image} object.
\code{writeImage} returns \code{invisible(files)}.
\end{Value}
\begin{Author}\relax
Oleg Sklyar, \email{osklyar@ebi.ac.uk}, 2005-2006
\end{Author}
\begin{References}\relax
ImageMagick: \url{http://www.imagemagick.org}
\end{References}
\begin{Examples}
\begin{ExampleCode}
   ## Reads and display images
   f = system.file("images", "lena-color.png", package="EBImage")
   x = readImage(f)
   if (interactive()) display(x)

   x = readImage(system.file("images", "nuclei.tif", package="EBImage"))
   if (interactive()) display(x)
   
   try({
     im = readImage("http://www.google.com/intl/en/images/logo.gif")
     if (interactive()) display(im)
   })

   ## Converts a TIFF file into JPEG
   f1 = system.file("images", "lena-color.png", package="EBImage")
   x1 = readImage(f1)
   f2 = paste(tempfile(), "jpeg", sep=".")
   writeImage(x1, f2)
   cat("Converted '", f1, "' into '", f2, "'.\n", sep='')
\end{ExampleCode}
\end{Examples}

