I was wondering how or if this can be done.
I would like to use the following code but modify it to grab custom size thumbnails using the xmax variable, is that possible and if so does someone have a suggestion on how to modify the code below to construct the correct call to Shrink the Web?
My understanding is that the code below was written to always grab the xlg thumbnail but basically my question is how can it be modified to grab a custom size thumbnail for local cache?
I realize there is a function in the class that allows you to scale the xlg thumbnail but scaling produces a fuzzy image and I would rather have a crisp image, if this is even possible.
public static function queryRemoteThumbnail($url, $args = null, $debug = false) {
$args = is_array($args) ? $args : array();
$defaults["Service"] = "ShrinkWebUrlThumbnail";
$defaults["Action"] = "Thumbnail";
$defaults["STWAccessKeyId"] = self::ACCESS_KEY;
$defaults["stwu"] = self::SECRET_KEY;
foreach ($defaults as $k=>$v)
if (!isset($args[$k]))
$args[$k] = $v;
$args["Url"] = $url; // now url is last
$request_url = urldecode("http://www.shrinktheweb.com/xino.php?".http_build_query($args));
$line = self::make_http_request($request_url);
if ($debug) {
echo '<pre style=font-size:10px>';
unset($args["STWAccessKeyId"]);
unset($args["stwu"]);
print_r($args);
echo '</pre>';
echo '<div style=font-size:10px>';
highlight_string($line);
echo '</div>';
}
$regex = '/<[^:]*:Thumbnail\\s*(?:Exists=\"((?:true)|(?:false))\")?[^>]*>([^<]*)<\//';
if (preg_match($regex, $line, $matches) == 1 && $matches[1] == "true")
return $matches[2];
return null;
}
public static function getThumbnail($url, $args = null, $force = false) {
$args = $args ? $args : array("Size"=>"lg");
$name = md5($url.serialize($args)).".jpg";
$src = self::THUMBNAIL_URI."/$name";
$path = self::THUMBNAIL_DIR.$src;
$cutoff = time() - 3600 * 24 * self::CACHE_DAYS;
if ($force || !file_exists($path) || filemtime($path) <= $cutoff)
if (($jpgurl = self::queryRemoteThumbnail($url, $args)))
if (($im = imagecreatefromjpeg($jpgurl)))
imagejpeg($im, $path, 100);
if (file_exists($path))
return $src;
if (!file_exists($path))
$src='/images/stwsitequeued.jpg';
return $src;
return null;
}