Archive for February, 2009
Image Resize with PHP and ImageMagick Maintaining Proportions
There are many examples found on the web on resizing images using PHP while maintaining aspect ratio. However most of them are based on a single maximum dimension i.e. should not exceed a certain size with on either height or width.
I have written the code below that will accept a desired height and width and downsize the source image without exceeding either $maxheight or $maxwidth but still maintain proportions.
Adjust your path to ImageMagick accordingly (/usr/bin/convert)
function resizeimage($source,$dest,
$maxwidth = 200,$maxheight = 160)
{
list($width,$height) = getimagesize($source);
/**
* We need to get both ratios so we can
* find which reduced height and width
* will fix the max allowed dimensions.
*/
$hRatio = $maxheight / $height;
$wRatio = $maxwidth / $width;
/**
* Test Dimensions based on height reduction ratio.
*/
$tHeightHR = $maxheight;
$tWidthHR = ceil($hRatio * $width);
/**
* Test dimenstions based on width reduction ratio.
*/
$tWidthWR = $maxwidth;
$tHeightWR = ceil($wRatio * $height);
if($width < $maxwidth AND $height < $maxheight)
{
echo 'Source already below maximum dimensions: '
. $source . " {$width}x{$height}\n";
return false;
}
if($tWidthHR <= $maxwidth) {
$height = $tHeightHR; $width = $tWidthHR;
}
if($tHeightWR <= $maxheight) {
$height = $tHeightWR; $width = $tWidthWR;
}
$cmd = "/usr/bin/convert -resize {$width}x{$height} "
. "\"{$source}\" \"{$dest}\" 2>&1";
@exec($cmd,$output,$retvar);
if($retvar != 0)
{
echo implode(" -- ",$output);
return false;
}
return true;
}
Stealing your RFID Enabled Cards
Posted by jervin in Application Security, Linux on February 2, 2009
Security researcher Chris Paget recently drove around downtown San Francisco to clone RFID base Passports and Drivers Licenses using an inexpensive kit of wireless tools. More at theregister.co.uk:
Using inexpensive off-the-shelf components, an information security expert has built a mobile platform that can clone large numbers of the unique electronic identifiers used in US passport cards and next generation drivers licenses.
The $250 proof-of-concept device - which researcher Chris Paget built in his spare time - operates out of his vehicle and contains everything needed to sniff and then clone RFID, or radio frequency identification, tags. During a recent 20-minute drive in downtown San Francisco, it successfully copied the RFID tags of two passport cards without the knowledge of their owners.
http://www.theregister.co.uk/2009/02/02/low_cost_rfid_cloner/