This tool allows easy transparent resizing of images to properly fit mobile screens.
To use it, prepend your <img>
tag URL with http://tools.citymedia.no/tools/scale/
and add some URL parameters (description follows).
Device widths are determined according to USER_AGENT_STRING from WURFL database;
Types of resize supported:
Scales image so that it's width becomes equal to device's width; height is scaled proportionally.
http://tools.citymedia.no/tools/scale/http://moz.gov.ua/i//00003682_001.jpg
Base part – http://tools.citymedia.no/tools/scale/
Example URL to scale – http://moz.gov.ua/i//00003682_001.jpg
Scales image so that it's width becomes equal to device's width minus the URL value supplied; height is scaled proportionally.
http://tools.citymedia.no/tools/scale/-10/http://moz.gov.ua/i//00003682_001.jpg
Base part – http://tools.citymedia.no/tools/scale/-10/
Example URL to scale – http://moz.gov.ua/i//00003682_001.jpg
Scales image so that it's width becomes equal to device's width multipled by the URL value supplied; height is scaled proportionally.
http://tools.citymedia.no/tools/scale/prop/0.33/http://moz.gov.ua/i//00003682_001.jpg
Base part – http://tools.citymedia.no/tools/scale/0.33/
Example URL to scale – http://moz.gov.ua/i//00003682_001.jpg
This link multipies max_image_width of device by modifier (0.33) and scales image to that width; this is named *prop*ortional scaling
This type of scaling sets image width equal to URL parameter supported. Aspect ratio is also maintained.
http://tools.citymedia.no/tools/scale/111/http://moz.gov.ua/i//00003682_001.jpg
Base part – http://tools.citymedia.no/tools/scale/111/
Example URL to scale – http://moz.gov.ua/i//00003682_001.jpg
This tool returns WURFL database entry for the USER_AGENT_STRING supported in GET request header; e.g. for PHP, $_SERVER['HTTP_USER_AGENT'] should be set in request headers, to get proper result.
Return values can be received in a number of formats.
http://tools.citymedia.no/tools/wurfl/raw — simple var_dump()
http://tools.citymedia.no/tools/wurfl/json — encoded via json_encode()
http://tools.citymedia.no/tools/wurfl/yaml — converted to YAML with Spyc library
Also there is a function determining if device is wireless. It is called by this URL:
http://tools.citymedia.no/tools/is_wireless
Returns 1 if device is, obviously, wireless. Otherwise returns 0.
function PostToHost($host, $path, $referer, $accept, $data_to_send)
{
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$fp = fsockopen($host, 80);
fputs($fp, "GET $path HTTP/1.1\r\n");
fputs($fp, "Host: $hostrn");
fputs($fp, "Referer: $referer\r\n");
fputs($fp, "Accept: $accept\r\n");
fputs($fp, "User-Agent: ".$user_agent."\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencodedrn");
fputs($fp, "Content-length: ". strlen($data_to_send) ."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data_to_send);
while(!feof($fp)) {
$res .= fgets($fp, 128);
}
fclose($fp);
return $res;
}
echo urldecode(PostToHost("http://tools.citymedia.no",
"http://tools.citymedia.no/tools/wurfl/json",
"", "text/plain", $_SERVER['HTTP_USER_AGENT']) );
Above returns JSON array containing full WURFL db record.
#!/usr/bin/ruby
require 'net/http'
require 'net/https'
require 'yaml'
http = Net::HTTP.new('http://tools.citymedia.no', 80)
path = '/tools/wurfl/yaml'
data = ''
headers = {
'User-Agent' => 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)'
# our user-agent from Rails goes here
}
resp, data = http.post(path, data, headers)
yaml_data = YAML::load(data)
puts yaml_data['display']['max_image_width']
ABOVE RETURNS SIMPLY: 320