I am trying to use the Bing Search API to allow users to map bing images to a message embedded in a website, after they select an image from it, it stores it on the server for use. But sometimes with Bing Search, the results returned by 'MediaUrl' are not images.
Example 1) Search for the Nascar keyword
Returns two images:
1) www.betbigdc.com/wp-content/uploads/2010/02/nascar1.jpg <- this is actually an image, and I can work, it works in <img src=''> .
2) http://images4.fanpop.com/image/photos/23900000/NASCAR-nascar-23962589-425-425.jpg .. this url is actually uploaded to www.fanpop.com/clubs/nascar/images/23962589/ title / nascar-photo? l = true ..
Example 2) Searching for the keyword Jason Aldean
Returns two images:
1) www.greenobles.com/data_images/jason-aldean/jason-aldean-01.jpg <- the actual URL of the image, which works in <img src=''> .
2) http://www.cmtradiolive.com/wp-content/uploads/2009/10/jason-aldean.jpg a funny url that actually loads a web page.
<?php // Search Bing Api $articles = sitesearch('Jason Aldean', $_SERVER['HTTP_HOST'], $accountKey, 4); $i = 0; // Process Results starting with reszing image within aspect ration to display to user foreach ($articles['d']['results'] as $article) { $i++; $dimensions = array( $article['Width'], $article['Height'] ); $dimensionsNew = array( 125, 125 ); // What scale do we need to go to $scaleRequired = min($dimensionsNew[0] / $dimensions[0], $dimensionsNew[1] / $dimensions[1]); if ($scaleRequired < 1) { $twidth = $dimensions[0] * $scaleRequired; $theight = $dimensions[1] * $scaleRequired; // Resize to $finalDimensions } else { $twidth = $article['Width']; $theight = $article['Height']; } // Display images resized within ration to =< 125PX echo "<img alt='bimage' width='$twidth' height='$theight' src='" . $article['MediaUrl'] . "' style='magin: 10px !important; border: thin solid #666666;' /> "; } ?>
Is there any way to verify that a given URL is or is not a direct URL ?!
source share