使用适用于PHP的Dropbox API下载图像的缩略图 [英] Download a thubnails of an image using Dropbox API for php
问题描述
我制作了一个脚本,在其中使用PHP将图像从保管箱文件夹下载到计算机上。
现在我要做的是下载图像的缩略图而不是整个图像。
为此,我使用了Dropbox API中的GetThumbNail方法。
这是代码的一部分:
I made a script where I download the images from a dropbox folder to my computer using PHP. What I try to do now is to download thumbnail of the images instead of the whole image. For this I use the: GetThumbNail method from the Dropbox API. Here is part of the code:
// download the files
$f = fopen($img_name, "w+b");
$fileMetadata = $dbxClient->getThumbnail($path, 'jpeg','xl');
fclose($f);
当我运行此图像时,得到的图像大小为0,没有任何内容。有什么想法我想念的吗?
谢谢
D。
When I run this the images I get are 0 size and they have no content. Any ideas what I am missing? Thanks D.
已编辑
$f = fopen($img_name, 'w+b');
$thumbnailData = $dbxClient->getThumbnail($path, 'jpeg', 'xl');
fwrite($f, $thumbnailData);
fclose($f);
推荐答案
您要打开和关闭 $ f
而不写任何东西。
You're opening and closing $f
without ever writing anything into it.
getThumbnail
返回一个数组有两个元素:文件的元数据和缩略图数据。
getThumbnail
returns an array with two elements: the metadata for the file and the thumbnail data.
所以我想您会想要这样的东西:
So I think you'll want something like this:
$f = fopen($img_name, 'w+b');
list($fileMetadata, $thumbnailData) = $dbxClient->getThumbnail($path, 'jpeg', 'xl');
fwrite($f, $thumbnailData);
fclose($f);
这篇关于使用适用于PHP的Dropbox API下载图像的缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!