0

我正在从包含链接到照片的 URL 的数据库中提取推文。

我已经能够在我的网站上显示这些照片,但它们太大了。

这是代码:

foreach ( $entities->media as $media ) {

$tweet_text =str_ireplace($media->url,  '<a href="'.$media->expanded_url.'">'
.$media->display_url.'</a>', $tweet_text);

{
$media_html = '';
$url = $media->media_url_https;
$link = $media->url;
$width = $media->sizes->w;
$height = $media->sizes->h;

  $media_html = "<a href=\"" . $url . "\" target='_blank'>";
  $media_html .=  "<img src=\"" . $url . "\" width=\"" .$width.
     "\" height=\"" .$height. "\" />";
  $media_html .= "</a><br />";          
 $media_html .= $tweet_text;    

    }
return $media_html;

我试过做:

$width = $media->sizes->w;
$height = $media->sizes->h;
$width = ($width)/2;
$height = ($height)/2;

但它只是在那之后没有显示。我尝试了很多变化,我唯一能开始工作的就是如果我添加

$width = $media->sizes->w+100;
$height = $media->sizes->h+100;

但这只是将 w 和 h 更改为 100,而且如您所知,大多数图片都不是完美的正方形!

大家怎么看?

4

1 回答 1

0

通过添加

$RESULT = list($width, $height) = getimagesize($url);

我能够返回值。这是一个数组,所以我不能先除$width$height不加它。

   {
$media_html = '';
$url = $media->media_url_https;
$link = $media->url;
$width = $media->sizes->w;
$height = $media->sizes->h;

$RESULT = list($width, $height) = getimagesize($url);

$width = ($width)/2;
$height = ($height)/2;

  $media_html = "<a href=\"" . $url . "\" target='_blank'>";
  $media_html .=  "<img src=\"" . $url . "\" width=\"" .$width.
  "\" height=\"" .$height. "\" />";
  $media_html .= "</a><br />";          
  $media_html .= $tweet_text;

    }

return $media_html;
于 2013-03-25T17:22:47.510 回答