Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何使用RubyonRails应用程序或Javascript将经过身份验证的html网页转换为图像_Jquery_Ruby_Ruby On Rails 3_Wkhtmltoimage_Imgkit - Fatal编程技术网

Jquery 如何使用RubyonRails应用程序或Javascript将经过身份验证的html网页转换为图像

Jquery 如何使用RubyonRails应用程序或Javascript将经过身份验证的html网页转换为图像,jquery,ruby,ruby-on-rails-3,wkhtmltoimage,imgkit,Jquery,Ruby,Ruby On Rails 3,Wkhtmltoimage,Imgkit,我有一个“设计”网页,其中有一些设计模板框架和一些主题图像和颜色。我想把这个网页转换成图像。我尝试使用imgKit,wkhtml2imagegem,但它只是以图像的形式显示登录页面,而没有显示我们需要的页面。我也尝试使用“html2canvas”,但它只显示布局。它不显示页面内容。请参阅代码: def design_update respond_to do |f| f.json do just_promo_params = promotion_params t

我有一个“设计”网页,其中有一些设计模板框架和一些主题图像和颜色。我想把这个网页转换成图像。我尝试使用
imgKit
wkhtml2image
gem,但它只是以图像的形式显示登录页面,而没有显示我们需要的页面。我也尝试使用“html2canvas”,但它只显示布局。它不显示页面内容。请参阅代码:

def design_update
  respond_to do |f|
    f.json do
      just_promo_params = promotion_params
      theme_params = just_promo_params.delete(:theme_attributes)

      if ThemeEngine::UpdatesThemeWithHistory.update_with_promotion(
        promotion,
        just_promo_params,
        theme_params,
        current_user)

        ASNWithControllerContext.instrument 'promotion.saved_design',
        context: self,
        promotion: promotion

        render status: 200, json: {errors: []}
      else
        render status: 200, json: {errors: [promotion.errors.full_messages]}
      end
    end
  end
end

我必须将这个json内容转换成图像。有没有办法做到这一点?

您的意思是要生成呈现网页的图像文件,就像从屏幕抓图中获得的一样?如果是这样的话,我相信
htmlcanvas2
会成功:如果您尝试了这个方法,但它不起作用,那么您应该尝试找出原因并修复它。是的,@MaxWilliams我正在获取JSON格式的内容。我们必须将其转换为图像JPG/pngy您的第一步应该是简单地将其呈现为网页,并使其看起来像您希望的那样。然后通过rails(即服务器端)或javascript(客户端)截图。您说您尝试了一些gem,它显示了登录页面:当它尝试加载页面时,它似乎被您的身份验证系统反弹到登录页面。这一定是一个常见的问题,我相信有很多有良好记录的方法可以克服它。