Write - Maple Help

ImageTools

 Write
 write an image to a file

 Calling Sequence Write( file, img, opts )

Parameters

 file - string; filename img - Image; image to write opts - (optional) equation(s) of the form option = value; specify options for the Write command

Options

 • format = BMP, JPEG, PNG, or TIFF
 Specifies the image format. It must be one of the values in ImageTools[Formats]. If not specified, the Write command guesses the format from the extension of file.
 • quality = numeric
 Specifies the JPEG format quality. This option is allowed only if the file is being written in JPEG format, and must be a value from 0 to 100 inclusive. Lower quality settings produce smaller files; higher settings produce better image quality. The default is 75, which is suitable for most photographic images.

Description

 • The Write command writes an image into a file in one of the supported formats and returns the number of bytes written. After completing the write, the file is closed.
 • The file parameter is the name of the file and it must be a Maple string. If the format option is not provided, the file format is determined from the extension of the file name. For example, the string image.jpg is written as a JPEG file.
 • The img parameter must be of type Image.
 • If img is of type GrayImage, the image is assumed to be grayscale and is written to the file accordingly. A ColorImage image is written as RGB and a ColorAImage is written as RGBA.
 The first two dimensions of img correspond to the height and width, respectively, in pixels. Note that this is the reverse of the way image sizes are typically specified (width x height), but this allows the arrangement of pixels in an image to correspond to the Matrix terminology of rows and columns.
 • If img has a color depth of 4 (red, green, blue, and alpha) and the format being written to (JPEG or BMP) does not support this depth, the last channel (alpha) is dropped.
 • Color values in img are assumed to range from 0.0 to 1.0, and are scaled to range from 0 to 255 when written into the file. Color values less than 0.0 become 0; values greater than 1.0 become 255.
 • The Write command can only write RGB, RGBA, or grayscale images, depending on the dimensions of img. Other formats, such as CMYK or color-mapped images cannot be written. See ImageTools[Formats] for further information.

Examples

 > $\mathrm{with}\left(\mathrm{ImageTools}\right):$
 > $\mathrm{img}≔\mathrm{Create}\left(100,200,\left(r,c\right)↦\mathrm{evalf}\left(0.5\cdot \mathrm{sin}\left(\frac{r}{50}\right)\cdot 0.5\cdot \mathrm{sin}\left(\frac{c}{30}\right)\right)\right):$
 > $\mathrm{img_c}≔\mathrm{Create}\left(100,200,\mathrm{channels}=3\right):$
 > $\mathrm{SetLayer}\left(\mathrm{img_c},0.7\mathrm{img},1,\mathrm{inplace}\right):$
 > $\mathrm{SetLayer}\left(\mathrm{img_c},0.1\mathrm{img},2,\mathrm{inplace}\right):$
 > $\mathrm{SetLayer}\left(\mathrm{img_c},0.5\mathrm{img},3,\mathrm{inplace}\right):$
 > $\mathrm{Write}\left("good_img.jpg",\mathrm{img_c}\right)$
 ${1203}$ (1)
 > $\mathrm{Write}\left("little_img.jpg",\mathrm{img_c},\mathrm{quality}=20\right)$
 ${1018}$ (2)
 > $\mathrm{Write}\left("big_img.tif",\mathrm{img_c},\mathrm{format}=\mathrm{TIFF}\right)$
 ${9249}$ (3)