Copyright | (c) Alexey Kuleshevich 2017 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <[email protected]> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Graphics.Image.IO
Description
- readImage :: Readable (Image arr cs Double) InputFormat => FilePath -> IO (Either String (Image arr cs Double))
- readImageExact :: Readable (Image arr cs e) format => format -> FilePath -> IO (Either String (Image arr cs e))
- writeImage :: (Array VS cs e, Array arr cs e, Exchangable arr VS, Writable (Image VS cs e) OutputFormat) => FilePath -> Image arr cs e -> IO ()
- writeImageExact :: Writable (Image arr cs e) format => format -> [SaveOption format] -> FilePath -> Image arr cs e -> IO ()
- data ExternalViewer = ExternalViewer FilePath [String] Int
- displayImage :: (Array VS cs e, Array arr cs e, Exchangable arr VS, Writable (Image VS cs e) TIF) => Image arr cs e -> IO ()
- displayImageUsing :: Writable (Image arr cs e) TIF => ExternalViewer -> Bool -> Image arr cs e -> IO ()
- displayImageFile :: ExternalViewer -> FilePath -> IO ()
- defaultViewer :: ExternalViewer
- eogViewer :: ExternalViewer
- gpicviewViewer :: ExternalViewer
- fehViewer :: ExternalViewer
- gimpViewer :: ExternalViewer
- module Graphics.Image.IO.Formats
Reading
readImage :: Readable (Image arr cs Double) InputFormat => FilePath -> IO (Either String (Image arr cs Double)) Source #
This function will try to guess an image format from file's extension,
then it will attempt to read it as such. It will fall back onto the rest of
the supported formats and will try to read them regarless of file's
extension. Whenever image cannot be decoded, Left
containing all errors for
each attempted format will be returned, and Right
containing an image
otherwise. Image will be read into a type signature specified ColorSpace
(Y
, YA
,
RGB
and RGBA
only)
with Double
precision, while doing all necessary conversions.
Arguments
:: Readable (Image arr cs e) format | |
=> format | A file format that an image should be read as. See Supported Image Formats |
-> FilePath | Location of an image. |
-> IO (Either String (Image arr cs e)) |
This function allows for reading any supported image in the exact colorspace
and precision it is currently encoded in. For instance, frog image can be
read into it's YCbCr
colorspace with
Word8
precision and into any supported array
representation.
>>>
readImageExact JPG "images/frog.jpg" :: IO (Either String (Image RP YCbCr Word8))
Right <Image RepaParallel YCbCr (Word8): 200x320>
The drawback here is that colorspace and precision has to match exactly, otherwise it will return an error:
>>>
readImageExact JPG "images/frog.jpg" :: IO (Either String (Image RP RGB Word8))
Left "JuicyPixel decoding error: Input image is in YCbCr8 (Pixel YCbCr Word8), cannot convert it to RGB8 (Pixel RGB Word8) colorspace."
Attempt to read an image in a particular color space that is not supported by
the format, will result in a compile error. Refer to Readable
class for all
images that can be decoded.
Writing
Arguments
:: (Array VS cs e, Array arr cs e, Exchangable arr VS, Writable (Image VS cs e) OutputFormat) | |
=> FilePath | Location where an image should be written. |
-> Image arr cs e | An image to write. |
-> IO () |
Just like readImage
, this function will guess an output file format from the
extension and write to file any image that is in one of Y
, YA
, RGB
or
RGBA
color spaces with Double
precision. While doing necessary
conversions the choice will be given to the most suited color space supported
by the format. For instance, in case of a PNG
format, an (Image
arr
RGBA
Double
) would be written as RGBA16
, hence preserving transparency
and using highest supported precision Word16
. At the same time, writing
that image in GIF
format would save it in RGB8
, since Word8
is the
highest precision GIF
supports and it currently cannot be saved with
transparency.
Arguments
:: Writable (Image arr cs e) format | |
=> format | A file format that an image should be saved in. See Supported Image Formats |
-> [SaveOption format] | A list of format specific options. |
-> FilePath | Location where an image should be written. |
-> Image arr cs e | An image to write. Can be a list of images in case of formats supporting animation. |
-> IO () |
Write an image in a specific format, while supplying any format specific options. Precision and color space, that an image will be written as, is decided from image's type. Attempt to write image file in a format that does not support color space and precision combination will result in a compile error.
Displaying
data ExternalViewer Source #
External viewing application to use for displaying images.
Constructors
ExternalViewer FilePath [String] Int | Any custom viewer, which can be specified:
|
Instances
Arguments
:: (Array VS cs e, Array arr cs e, Exchangable arr VS, Writable (Image VS cs e) TIF) | |
=> Image arr cs e | Image to be displayed |
-> IO () |
Makes a call to an external viewer that is set as a default image viewer by the OS. This is a non-blocking function call, so it will take some time before an image will appear.
>>>
frog <- readImageRGB VU "images/frog.jpg"
>>>
displayImage frog
Arguments
:: Writable (Image arr cs e) TIF | |
=> ExternalViewer | External viewer to use |
-> Bool | Should the call be blocking |
-> Image arr cs e | Image to display |
-> IO () |
An image is written as a .tiff
file into an operating system's temporary
directory and passed as an argument to the external viewer program.
displayImageFile :: ExternalViewer -> FilePath -> IO () Source #
Displays an image file by calling an external image viewer.
Common viewers
eogViewer :: ExternalViewer Source #
eog tmphip/img.tiff
Eye of GNOME
gpicviewViewer :: ExternalViewer Source #
gpicview tmphip/img.tiff
GPicView
fehViewer :: ExternalViewer Source #
feh --fullscreen --auto-zoom tmphip/img.tiff
FEH
gimpViewer :: ExternalViewer Source #
gimp tmphip/img.tiff
GIMP
Supported Image Formats
module Graphics.Image.IO.Formats