[英]Resize photo that is extracted from a link
I am pulling tweets from a database that include URLs that link to a photo. 我正在从包含链接到照片的URL的数据库中提取推文。
I've been able to display the photos on my site but they are just too big. 我已经可以在我的网站上显示照片,但是它们太大了。
Here is the code: 这是代码:
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;
I've tried doing: 我试着做:
$width = $media->sizes->w;
$height = $media->sizes->h;
$width = ($width)/2;
$height = ($height)/2;
but it just isn't displaying after that. 但此后不再显示。 I've tried many variations and the only thing I can get to work is if I add
我已经尝试了许多变体,并且唯一可以使用的就是
$width = $media->sizes->w+100;
$height = $media->sizes->h+100;
But this just changes the w and h to 100, and as you know, most pictures aren't perfect squares! 但这只会将w和h更改为100,并且您知道,大多数图片都不是完美的正方形!
What do you all think? 你们怎么想
By adding 通过增加
$RESULT = list($width, $height) = getimagesize($url);
I was able to return the value. 我能够返回该值。 It was an array so I couldn't divide the
$width
or $height
without adding that first. 这是一个数组,所以我不能在不先加
$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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.