I am pulling tweets from a database that include URLs that link to a photo.
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!
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.
{
$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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.