Previous IDL Reference Guide: Procedures and Functions Next

WRITE_PNG

Syntax | Arguments | Keywords | Examples | Version History | See Also

The WRITE_PNG procedure writes a 2-D or 3-D IDL variable into a Portable Network Graphics (PNG) file. The data in the file is stored using lossless compression with either 8 or 16 data bits per channel, based on the input IDL variable type. 3-D IDL variables must have the number of channels as their leading dimension (pixel interleaved). For BYTE format 2-D IDL variables, an optional palette may be stored in the image file along with a list of pixel values which are to be considered transparent by a reading program.


Note
IDL supports version 1.2.7 of the PNG Library.

Syntax

WRITE_PNG, Filename, Image[, R, G, B] [, /ORDER] [, /VERBOSE] [, TRANSPARENT=array]

Arguments

Filename

A scalar string containing the full pathname of the PNG file to write.

Image

The array to write into the new PNG file. If Image is one of the integer data types, it is converted to type unsigned integer (UINT) and written out at 16 data bits per channel. All other data types are converted to bytes and written out at 8-bits per channel.


Note
If Image is two-dimensional (single-channel) and R, G, and B are provided, all input data types (including integer) are converted to bytes and written out as 8-bit data.

R, G, B

For single-channel images, R, G, and B should contain the red, green, and blue color vectors, respectively. For multi-channel images, these arguments are ignored.

Keywords

ORDER

Set this keyword to indicate that the rows of the image should be written from bottom to top. The rows are written from top to bottom by default. ORDER provides compatibility with PNG files written using versions of IDL prior to IDL 5.4, which wrote PNG files from bottom to top.

VERBOSE

Produces additional diagnostic output during the write.

TRANSPARENT

Set this keyword to an array of pixel index values which are to be treated as "transparent" for the purposes of image display. This keyword is valid only if Image is a single-channel (color indexed) image and the R, G, B palette is provided.

Examples

Create an RGBA (16-bits/channel) and a Color Indexed (8-bits/channel) image with a palette.

rgbdata = UINDGEN(4,320,240)  
cidata = BYTSCL(DIST(256))  
red = INDGEN(256)  
green = INDGEN(256)  
blue = INDGEN(256)  
WRITE_PNG,'rgb_image.png',rgbdata  
WRITE_PNG,'ci_image.png',cidata,red,green,blue  
  
; Query and Read the data:  
names = ['rgb_image.png','ci_image.png','unknown.png']  
FOR i=0,N_ELEMENTS(names)-1 DO BEGIN  
   ok = QUERY_PNG(names[i],s)  
   IF (ok) THEN BEGIN  
      HELP,s,/STRUCTURE  
      IF (s.HAS_PALETTE) THEN BEGIN  
         img = READ_PNG(names[i],rpal,gpal,bpal)  
         HELP,img,rpal,gpal,bpal  
      ENDIF ELSE BEGIN  
         img = READ_PNG(names[i])  
         HELP,img  
      ENDELSE  
   ENDIF ELSE BEGIN  
      PRINT,names[i],' is not a PNG file'  
   ENDELSE  
ENDFOR  

Version History

5.2
Introduced

See Also

READ_PNG, QUERY_* Routines

  IDL Online Help (June 16, 2005)