【问题标题】:Couldn't fetch remote media on Cloudinary无法在 Cloudinary 上获取远程媒体
【发布时间】:2021-10-30 09:23:22
【问题描述】:

我想在 Cloudinary 中的 smaple.jpg 上覆盖远程媒体。但是:type=>"fetch" 不起作用,图像也不会显示。

只需阅读Document,但这不适用于当前案例。

<%= cl_image_tag(
  "ogp.png", 
  :transformation=>[
    {:color=> '#fff', :overlay=>{:color=> "#ffffff", :font_family => 'Open Sans', :font_size=> 20, :text_align=> 'center', :text=> @channel.user.name},},
    {:flags=>"layer_apply", :gravity=>"north", :y=>90},
    {:type=> 'fetch'},
    {:overlay=> Base64.encode64('https://[PUBLI IMAGE URL].jpg'), :type=>"fetch"},
  ],
) %>

=> https://res-4.cloudinary.com/remotehour/image/upload/co_rgb:fff,l_text:Open%20Sans_20_center:Shun/fl_layer_apply,g_north,y_90/l_aHRXXXXXXXXXXXXXXXXXwMC5qcGc=/sampple.jpg

【问题讨论】:

    标签: ruby-on-rails ruby cloudinary


    【解决方案1】:

    您需要使用 url 参数指定图像,而不是使用 base64 编码版本。您无需指定 fetch,因为 SDK 会自动处理它。你可以找到一个例子here

    这里是 Python 中的代码,因为我对 PHP 不太熟悉。

    import cloudinary
    
    resp = cloudinary.CloudinaryImage('sample').image(
        transformation = [
            {"overlay": {"text": "hi",'font_family': 'roboto', 'font_size':30},'gravity': 'north_west','x':20,'y':20,'color':'blue'},
            {"overlay": {'url': 'https://images.pexels.com/photos/3948546/pexels-photo-3948546.png'},'gravity':'south_east','width':250,'height':250,'crop':'fill','x':10,'y':10}
        ]
    )
    print(resp)
    

    这将生成一个图像,左上角有文字,右下角有叠加图像。

    输出网址:https://res.cloudinary.com/akshayranganath/image/upload/co_blue,g_north_west,l_text:roboto_30:hi,x_20,y_20/c_fill,g_south_east,h_250,l_fetch:aHR0cHM6Ly9pbWFnZXMucGV4ZWxzLmNvbS9waG90b3MvMzk0ODU0Ni9wZXhlbHMtcGhvdG8tMzk0ODU0Ni5wbmc=,w_250,x_10,y_10/sample

    【讨论】:

    • 非常感谢您的友好回答。真的很有帮助!!但是尝试&lt;%= cl_image_tag("sample.jpg", :overlay=&gt;{:url=&gt;"https://res.cloudinary.com/demo/image/upload/logos/cloudinary_full_logo_white_small.png"}) %&gt;时出现错误Must supply public_id for resource_type layer_parameter
    • 您不能在overlay 中使用url。您需要提供资源的public_id,例如:cl_image_tag("sample.jpg", :overlay=&gt;"overlayPublicId")请查看相关文档-cloudinary.com/documentation/layers
    猜你喜欢
    • 2021-09-15
    • 1970-01-01
    • 2019-04-18
    • 2018-01-21
    • 2017-08-28
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    相关资源
    最近更新 更多