568: def add_image(image, x, y, width = nil, height = nil, image_info = nil, link = nil)
569: if image.kind_of?(PDF::Writer::External::Image)
570: label = image.label
571: image_obj = image
572: image_info ||= image.image_info
573: else
574: image_info ||= PDF::Writer::Graphics::ImageInfo.new(image)
575:
576: tt = Time.now
577: @images << tt
578: id = @images.index(tt)
579: label = "I#{id}"
580: image_obj = PDF::Writer::External::Image.new(self, image, image_info, label)
581: @images[id] = image_obj
582: end
583:
584: if width.nil? and height.nil?
585: width = image_info.width
586: height = image_info.height
587: end
588:
589: width ||= height / image_info.height.to_f * image_info.width
590: height ||= width * image_info.height / image_info.width.to_f
591:
592: tt = "\nq\n%.3f 0 0 %.3f %.3f %.3f cm\n/%s Do\nQ"
593: add_content(tt % [ width, height, x, y, label ])
594:
595: if link
596: case link[:type]
597: when :internal
598: add_internal_link(link[:target], x, y, x + width, y + height)
599: when :external
600: add_link(link[:target], x, y, x + width, y + height)
601: end
602: end
603:
604: image_obj
605: end