Skip to content

:getWidth()

Returns height of the named loaded image or video.

Note: Currently L5 can only work with ogv (Ogg Theora) video files. Use an external program such as Handbrake or ffmpeg (command line) to convert mp4, avi, mkv, and mov codecs first.

Examples

image :getWidth() example 1

local img
require("L5")

function setup()
  size(100, 100)
  windowTitle('image :getWidth() example')

  -- Load the image
  img = loadImage('assets/flower.jpg')
  -- Draw the image.
  image(img, 0, 0, width, height)
  -- Print the width of the image source, not the window
  print(img:getWidth())

  describe('Image of a pink flower in bloom.')
end

Video :getWidth() Example

require("L5")

function setup()
  windowTitle("loadVideo example")

  video = loadVideo("assets/heads.ogv")

  -- get the video file's pixel width
  print(video:getWidth())

  video:play()

  describe("A basic example of loading a video, then playing it by drawing frames in the draw loop. Prints video width.")
end

function draw()
  background(51) 

  image(video, 0, 0, width, height)
end 

Syntax

image:getWidth()
video:getWidth()

Returns

Number: width of loaded image or video