# File lib/juicer/image_embed.rb, line 42
    def save(file, output = nil)
      return unless @type == :data_uri

      output_file = output || file
      @contents = File.read(file)
      used = []

      @path_resolver = Juicer::Asset::PathResolver.new(:document_root => @document_root,
                                                       :hosts => @hosts,
                                                       :base => File.dirname(file))

      assets = urls(file)

      # TODO: Remove "?embed=true" from duplicate urls
      duplicates = duplicate_urls(assets)

      if duplicates.length > 0
        Juicer::LOGGER.warn("Duplicate image urls detected, these images will not be embedded: #{duplicates.collect { |v| v.gsub('?embed=true', '') }.inspect}")
      end

      assets.each do |asset|
        begin
          next if used.include?(asset) || duplicates.include?(asset.path)
          used << asset

          # make sure we do not exceed SIZE_LIMIT
          new_path = embed_data_uri(asset.filename)

          if new_path.length < SIZE_LIMIT
            # replace the url in the css file with the data uri
            @contents.gsub!(asset.path, embed_data_uri(asset.filename)) if @force || asset.filename.match( /\?embed=true$/ )
          else
            Juicer::LOGGER.warn("The final data uri for the image located at #{asset.path.gsub('?embed=true', '')} exceeds #{SIZE_LIMIT} and will not be embedded to maintain compatability.")
          end
        rescue Errno::ENOENT
          puts "Unable to locate file #{asset.path}, skipping image embedding"
        end
      end

      File.open(output || file, "w") { |f| f.puts @contents }
      @contents = nil
    end