Method: FPDF#Image

Defined in:
lib/fpdf.rb

#Image(file, x, y, w, h = 0, type = '', link = '') ⇒ Object



819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
# File 'lib/fpdf.rb', line 819

def Image(file,x,y,w,h=0,type='',link='')
    # Put an image on the page
    unless @images.has_key?(file)
        # First use of image, get info
        if type==''
            pos=file.rindex('.')
            if pos.nil?
                self.Error('Image file has no extension and no type was '+
                    'specified: '+file)
            end
            type=file[pos+1..-1]
        end
        type.downcase!
        if type=='jpg' or type=='jpeg'
            info=parsejpg(file)
        elsif type=='png'
            info=parsepng(file)
        else
            self.Error('Unsupported image file type: '+type)
        end
        info['i']=@images.length+1
        @images[file]=info
    else
        info=@images[file]
    end
    # Automatic width or height calculation
    w=h*info['w']/info['h'] if w==0
    h=w*info['h']/info['w'] if h==0
    out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q',
        w*@k,h*@k,x*@k,(@h-(y+h))*@k,info['i']))
    Link(x,y,w,h,link) if link and link != ''
end