0

我正在尝试使用Embedly为给定的 url 生成缩略图。我需要缩略图小于最大尺寸,所以我这样调用 api:

url = "http://embed.ly"
embedly_api = Embedly::API.new(key: ENV['EMBEDLY_KEY'])
obj = embedly_api.oembed(url: url, maxwidth: 50, type: 'photo').first

json_obj = JSON.pretty_generate(obj.marshal_dump)

或者

http://api.embed.ly/1/oembed?key=[KEY_VALUE]&url=http://embed.ly&maxwidth=50&type=photo

无论哪种情况,结果都是:

{
  provider_url: "http://embed.ly",
  description: "Embedly delivers the ultra-fast,...",
  title: "Embedly makes your content more engaging and easier...",
  mean_alpha: 32.7480314961,
  thumbnail_width: 399,
  url: "http://embed.ly",
  thumbnail_url: "http://embed.ly/static/images/logos/logo_color.png?v=4b245",
  version: "1.0",
  provider_name: "Embedly",
  type: "link",
  thumbnail_height: 127
}

请注意,它thumbnail_width是 399(大于我为maxwidth参数传入的值)。我在这里遗漏了一些明显的东西吗?

4

1 回答 1

1

maxwidth仅适用于 html,图片可以是任意宽度。

Embedly 确实允许您设置一个image_width。尝试:

embedly_api.oembed(url: url, maxwidth: 50, type: 'photo', image_width: 50)

http://embed.ly/docs/api/display/integration

于 2015-08-18T21:07:49.250 回答