class Zebra::Zpl::Image

Attributes

compress[W]
invert[W]
path[R]

Public Instance Methods

black_threshold() click to toggle source
# File lib/zebra/zpl/image.rb, line 56
def black_threshold
  @black_threshold || 0.5
end
black_threshold=(value) click to toggle source
# File lib/zebra/zpl/image.rb, line 51
def black_threshold=(value)
  raise InvalidThresholdError.new('Invalid black threshold') unless value.to_f >= 0 && value.to_f <= 1
  @black_threshold = value.to_f
end
compress() click to toggle source
# File lib/zebra/zpl/image.rb, line 64
def compress
  @compress || true
end
height() click to toggle source
# File lib/zebra/zpl/image.rb, line 38
def height
  @height || @img.height
end
height=(value) click to toggle source
# File lib/zebra/zpl/image.rb, line 33
def height=(value)
  raise InvalidSizeError.new('Invalid image height') unless value.to_i.positive?
  @height = value.to_i
end
invert() click to toggle source
# File lib/zebra/zpl/image.rb, line 60
def invert
  @invert || false
end
path=(p) click to toggle source
# File lib/zebra/zpl/image.rb, line 13
def path=(p)
  @img = Img2Zpl::Image.open(p)
  @path = @img.path
end
rotation() click to toggle source
# File lib/zebra/zpl/image.rb, line 47
def rotation
  @rotation || 0
end
rotation=(rot) click to toggle source
# File lib/zebra/zpl/image.rb, line 42
def rotation=(rot)
  raise InvalidRotationError unless (true if Float(rot) rescue false)
  @rotation = rot
end
source() click to toggle source
# File lib/zebra/zpl/image.rb, line 18
def source
  @img
end
Also aliased as: src
src()
Alias for: source
to_zpl() click to toggle source
# File lib/zebra/zpl/image.rb, line 68
def to_zpl
  check_attributes
  modify
  graphics = @img.to_zpl(
    black_threshold: black_threshold,
    invert: invert,
    compress: compress
  )
  "^FO#{x},#{y}#{graphics}"
end
width() click to toggle source
# File lib/zebra/zpl/image.rb, line 29
def width
  @width || @img.width
end
width=(value) click to toggle source
# File lib/zebra/zpl/image.rb, line 24
def width=(value)
  raise InvalidSizeError.new('Invalid image width') unless value.to_i.positive?
  @width = value.to_i
end

Private Instance Methods

check_attributes() click to toggle source
Calls superclass method Zebra::Zpl::Printable#check_attributes
# File lib/zebra/zpl/image.rb, line 90
def check_attributes
  super
  raise MissingAttributeError.new("the path is invalid or not given") unless @path
end
has_data?() click to toggle source
# File lib/zebra/zpl/image.rb, line 81
def has_data?
  false
end
modify() click to toggle source
# File lib/zebra/zpl/image.rb, line 85
def modify
  @img.resize("#{width}x#{height}") if @width || @height
  @img.rotate(@rotation) if @rotation
end