【问题标题】:Retina iconLink with Google Drive APIRetina iconLink 与 Google Drive API
【发布时间】:2016-03-03 19:34:39
【问题描述】:

我正在获取文件夹中的文件列表。对于返回的每个文件,响应都包含一个 iconLink。此图标为 16x16 像素。

有人知道检索视网膜图像的方法吗?或者另一种检索更大图标图像的方法?

https://developers.google.com/drive/v2/reference/files

顶部:Google 云端硬盘用户界面

底部:Google Drive API 集成

【问题讨论】:

  • 到目前为止你做了什么?在每个返回的文件中,您是否尝试过将图标图像调整为更大的图标?
  • 返回的图标 url 指向一个 16x16 像素的图像。 (例如ssl.gstatic.com/docs/doclist/images/icon_12_pdf_list.png)。我尝试添加 @2x 以查看是否可用,但到目前为止没有运气
  • 您找到解决方案了吗?
  • 还没有;-(也许我们会得到一个悬赏的答案

标签: php google-drive-api


【解决方案1】:

好消息是虽然没有官方文档记录的驱动程序确实有 2x 分辨率图标。坏消息是它们的文件名不一致。例如,您在 cmets 中链接的图标在此处有 32px 版本可用:ssl.gstatic.com/docs/doclist/images/mediatype/icon_3_pdf_x32.png

现在这是我的解决方案,它并不完美,但它会在一段时间内完成这项工作:

function getIcons($file_type)
{ 
    $icons = [
        'pdf' => [
            'icon' => 'icon_12_pdf_list.png',
            'retina' => 'icon_3_pdf_x32.png'
         ],
        'document' => [
            'icon' => 'icon_1_document_x16.png',
            'retina' => 'icon_1_document_x32.png'
        ],
        'image' => [
            'icon' => 'con_1_image_x16.png',
            'retina' => 'icon_1_image_x32.png'
        ],
        'word' => [
            'icon' => 'icon_1_word_x16.png',
            'retina' => 'icon_1_word_x32.png'
        ],
        'text' => [
            'icon' => 'icon_1_text_x16.png',
            'retina' => 'icon_1_text_x32.png'
        ],
        'spreadsheet' => [
            'icon' => 'icon_1_spreadsheet_x16.png',
            'retina' => 'icon_1_spreadsheet_x32.png'
        ],
        'form' => [
            'icon' => 'icon_2_form_x16.png',
            'retina' => 'icon_2_form_x32.png'
        ],
        'audio' => [
            'icon' => 'icon_1_audio_x16.png',
            'retina' => 'icon_1_audio_x32.png'
        ]
    ];

    return isset($icons[$file_type]) ? $icons[$file_type] : $icons['text'];
}

我说它会工作一段时间的原因是我假设 pdf 图标文件名中的 _3_ 是版本号。因此,如果 Google 将来再次更新它的图标,这个解决方案可能会失败。

【讨论】:

    【解决方案2】:

    我正在使用 drive rest api,我观察到iconLink 属性具有明确的模式。 "https://drive-thirdparty.googleusercontent.com/" + size + mimetype 默认大小为 16。因此,在将图标添加到 Image 之前,请使用:

        String iconLink = (String) jsonObject.get("iconLink");
        iconLink=iconLink.replace("16","128");
    

    查看这两个链接: https://drive-thirdparty.googleusercontent.com/128/type/application/pdf https://drive-thirdparty.googleusercontent.com/16/type/application/pdf

    【讨论】:

      【解决方案3】:

      看起来像 x128 的图像也为各种版本添加/呈现:

      Ver. 1

      Ver. 2

      Ver. 3

      最好将获取到的iconLink中的x16替换为x128

      【讨论】:

        猜你喜欢
        • 2012-10-27
        • 1970-01-01
        • 2013-02-10
        • 1970-01-01
        • 2015-09-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多