# File lib/vcard/vcard.rb, line 1271
      def add_photo # :yield: photo
        x = Struct.new(:image, :link, :type).new
        yield x
        if x[:image] && x[:link]
          raise ::Vcard::InvalidEncodingError, "Image is not allowed to be both inline and a link."
        end

        value = x[:image] || x[:link]

        if !value
          raise ::Vcard::InvalidEncodingError, "A image link or inline data must be provided."
        end

        params = {}

        # Don't set type to the empty string.
        params["TYPE"] = x[:type] if( x[:type] && x[:type].length > 0 )

        if x[:link]
          params["VALUE"] = "URI"
        else # it's inline, base-64 encode it
          params["ENCODING"] = :b64
          if !x[:type]
            raise ::Vcard::InvalidEncodingError, "Inline image data must have it's type set."
          end
        end

        @card << ::Vcard::DirectoryInfo::Field.create( "PHOTO", value, params )
        self
      end