Oasys.REPORTER.Image class

Constants

Image.BMP

Save image as BMP

Image.JPG

Save image as JPG

Image.PNG

Save image as PNG

Properties

property Image.antialiasing: bool

Whether or not lines, shapes and text are drawn with antialiasing (true by default)

property Image.fillColour: string

Colour to use when filling shapes on the Image. Can be “none”, a valid colour from the X colour database (For Linux users, see /etc/X11/rgb.txt) e.g. “Blue”, or #RRGGBB (each of R, G and B is a single hex digit) e.g. “#0000FF” for blue

property Image.font: string

Font to use when drawing text on the Image e.g. “Courier”. Can be any font accessible by REPORTER

property Image.fontAngle: integer

Angle (degrees) text is drawn at on the Image. Can be between -360 and 360 degrees

property Image.fontColour: string

Colour to use when drawing text on the Image. Can be “none”, a valid colour from the X colour database (For Linux users, see /etc/X11/rgb.txt) e.g. “Blue”, or #RRGGBB (each of R, G and B is a single hex digit) e.g. “#0000FF” for blue

property Image.fontJustify: constant

Justification to use when drawing text on the Image. Can be Reporter.JUSTIFY_CENTRE, Reporter.JUSTIFY_LEFT or Reporter.JUSTIFY_RIGHT

property Image.fontSize: integer

Size of font (in points) to use when drawing text on the Image

property Image.fontStyle: constant

Style of font to use when drawing text on the Image. Can be any combination of Reporter.TEXT_NORMAL, Reporter.TEXT_BOLD, Reporter.TEXT_ITALIC and Reporter.TEXT_UNDERLINE

property Image.height: integer

Height of the Image

property Image.lineCapStyle: constant

Style to use for the end of lines on an Image. Can be Reporter.CAP_FLAT, Reporter.CAP_SQUARE or Reporter.CAP_ROUND

property Image.lineColour: string

Colour to use when drawing lines on the Image. Can be “none”, a valid colour from the X colour database (For Linux users, see /etc/X11/rgb.txt) e.g. “Blue”, or #RRGGBB (each of R, G and B is a single hex digit) e.g. “#0000FF” for blue

property Image.lineJoinStyle: constant

Style to use for the line join at vertices of polygons and polylines on an Image. Can be Reporter.JOIN_MITRE, Reporter.JOIN_BEVEL or Reporter.JOIN_ROUND

property Image.lineStyle: constant

Style to use when drawing lines on an Image. Can be Reporter.LINE_NONE, Reporter.LINE_SOLID, Reporter.LINE_DASH, Reporter.LINE_DOT, Reporter.LINE_DASH_DOT or Reporter.LINE_DASH_DOT_DOT

property Image.lineWidth: integer

Width to use when drawing lines on an Image value

property Image.width: integer

Width of the Image

Constructor

classmethod Image(width, height, backgroundcolour=Oasys.gRPC.defaultArg)

Create a new Image object for creating an image. If only 2 arguments are given they are used as the width and height of the image. The third argument can be used to define the initial background colour (the default is white)

Parameters:
  • width (integer) – Width of image

  • height (integer) – Height of image

  • backgroundcolour (string) – Optional. Initial background colour for the image (default is white). Can be “none”, a valid colour from the X colour database (For Linux users, see /etc/X11/rgb.txt) e.g. “Blue”, or #RRGGBB (each of R, G and B is a single hex digit) e.g. “#0000FF” for blue

Returns:

Image object

Return type:

dict

Example

To create a new image object 100 pixels wide by 50 pixels high

img = Oasys.REPORTER.Image(100, 50)

Instance methods

Image.Ellipse(x1, y1, x2, y2)

Draw an ellipse on an image

Parameters:
  • x1 (integer) – X coordinate of start position for ellipse

  • y1 (integer) – Y coordinate of start position for ellipse

  • x2 (integer) – X coordinate of end position for ellipse

  • y2 (integer) – Y coordinate of end position for ellipse

Returns:

no return value

Return type:

None

Example

To draw an ellipse with no fill and solid red border line width 2 pixels, on image ‘idata’, starting at point 30, 20 and finishing at point 100, 50

idata.lineColour = "red"
idata.fillColour = "none"
idata.lineWidth = 2
idata.lineStyle = Oasys.REPORTER.Reporter.LINE_SOLID
idata.Ellipse(30, 20, 100, 50)
Image.Fill(x, y, tol=Oasys.gRPC.defaultArg)

Fill an area in an image with a colour

Parameters:
  • x (integer) – X coordinate of start position for fill

  • y (integer) – Y coordinate of start position for fill

  • tol (integer) – Optional. Tolerance for colour matching (0-255). Default is 0. When filling a shape if the red, green and blue components are within tol of the colour of pixel (x, y) the pixel will be filled with the current fill colour

Returns:

no return value

Return type:

None

Example

To fill an area of image ‘idata’, starting at point 30, 20 with red:

idata.fillColour = "red"
idata.Fill(30, 20)
Image.Line(x1, y1, x2, y2)

Draw a line on an image

Parameters:
  • x1 (integer) – X coordinate of start position for line

  • y1 (integer) – Y coordinate of start position for line

  • x2 (integer) – X coordinate of end position for line

  • y2 (integer) – Y coordinate of end position for line

Returns:

no return value

Return type:

None

Example

To draw a blue, dashed line width 2 pixels, on image ‘idata’, starting at point 30, 20 and finishing at point 100, 50

idata.lineColour = "blue"
idata.lineWidth = 2
idata.lineStyle = Oasys.REPORTER.Reporter.LINE_DASH
idata.Line(30, 20, 100, 50)
Image.Load(filename)

Load an image file (gif, png, bmp or jpeg)

Parameters:

filename (string) – Imagename you want to load

Returns:

no return value

Return type:

None

Example

To load the image file “/data/test/image.jpg” into the image object ‘idata’

idata.Load("/data/test/image.jpg")
Image.PixelCount(colour, tol=Oasys.gRPC.defaultArg)

Count the number of pixels in an image that have a specific colour

Parameters:
  • colour (string) – A valid colour from the X colour database (For Linux users, see /etc/X11/rgb.txt) e.g. “Blue”, or #RRGGBB (each of R, G and B is a single hex digit) e.g. “#0000FF” for blue

  • tol (integer) – Optional. Tolerance for colour matching (0-255). Default is 0. When looking at pixels if the red, green and blue components are within tol of the colour of pixel (x, y) the pixel will be counted

Returns:

Number of pixels (integer) with the colour

Return type:

int

Example

To count the number of red pixels in image ‘idata’:

nred = idata.PixelCount("red")
Image.Polygon(points)

Draw a polygon on an image. The last point is always connected back to the first point

Parameters:

points (list) – List of point coordinates

Returns:

no return value

Return type:

None

Example

To draw a blue polygon with a solid red border line width 2 pixels, on image ‘idata’, connecting points (10,10) (20,10) (20,20) (10,20)

idata.fillColour = "blue"
idata.lineColour = "red"
idata.lineWidth = 2
idata.lineStyle = Oasys.REPORTER.Reporter.LINE_SOLID
a = [10,10, 20,10, 20,20, 10,20]
idata.Polygon(a)
Image.Polyline(points)

Draw a line with multiple straight segments on an image

Parameters:

points (list) – List of point coordinates

Returns:

no return value

Return type:

None

Example

To draw a blue, dashed polyline width 2 pixels, on image ‘idata’, connecting points (10,10) (20,10) (20,20) (10,20)

idata.lineColour = "blue"
idata.lineWidth = 2
idata.lineStyle = Oasys.REPORTER.Reporter.LINE_DASH
a = [10,10, 20,10, 20,20, 10,20]
idata.Polyline(a)
Image.Rectangle(x1, y1, x2, y2)

Draw a rectangle on an image

Parameters:
  • x1 (integer) – X coordinate of start position for rectangle

  • y1 (integer) – Y coordinate of start position for rectangle

  • x2 (integer) – X coordinate of end position for rectangle

  • y2 (integer) – Y coordinate of end position for rectangle

Returns:

no return value

Return type:

None

Example

To draw a rectangle with no fill and solid red border line width 2 pixels, on image ‘idata’, starting at point 30, 20 and finishing at point 100, 50

idata.lineColour = "red"
idata.fillColour = "none"
idata.lineWidth = 2
idata.lineStyle = Oasys.REPORTER.Reporter.LINE_SOLID
idata.Rectangle(30, 20, 100, 50)
Image.Save(filename, filetype)

Save an image to file (png, bmp or jpeg)

Parameters:
  • filename (string) – Imagename you want to save

  • filetype (constant) – Type you want to save as. Can be: Image.BMP, Image.JPG or Image.PNG

Returns:

no return value

Return type:

None

Example

To save the image object ‘idata’ to file “/data/test/image.jpg” as a jpeg

idata.Save("/data/test/image.jpg", Oasys.REPORTER.Image.JPG)
Image.Star(x, y, r)

Draw a star on an image

Parameters:
  • x (integer) – X coordinate of centre of star

  • y (integer) – Y coordinate of centre of star

  • r (integer) – Radius of star

Returns:

no return value

Return type:

None

Example

To draw a blue star with yellow fill, on image ‘idata’, centred at point 30, 20 with radius 10

idata.lineColour = "blue"
idata.fillColour = "yellow"
idata.Star(30, 20, 10)
Image.Text(x, y, text)

Draw text on an image

Parameters:
  • x (integer) – X position for text

  • y (integer) – Y position for text

  • text (string) – Text to write on image

Returns:

no return value

Return type:

None

Example

To write the text ‘Test’ in Helvetica 12pt bold underlined, coloured red on image ‘idata’, at point 30, 20

idata.fontColour = "red"
idata.fontSize = 12
idata.fontStyle = Oasys.REPORTER.Reporter.TEXT_BOLD | Oasys.REPORTER.Reporter.TEXT_UNDERLINE
idata.Text(30, 20, "Test")