调整从链接中提取的照片的大小

时间:2013-03-20 16:08:30

标签: php image-processing

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

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

以下是代码:

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,如您所知,大多数图片都不是完美的正方形!

你们都在想什么?

1 个答案:

答案 0 :(得分: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;