日曜日, 2月 15, 2009

PHP: Resizing image files

The way to resize image files in PHP is straight foward yet not as simple as it should be. Nevertheless, the PHP image library is equipped with image manipulation functions. Here is a function that does the job -- resizing factor should be edited to suit your needs.



function resizePhoto($fileName,$dest)
{
header('Content-type: image/jpeg');

list($width, $height) = getimagesize($fileName);
$ratio=((float)$height)/$width;
$newWidth=90;
$newHeight=(int)($newWidth*$ratio);

$thumb = imagecreatetruecolor($newWidth, $newHeight);
$source = imagecreatefromjpeg($fileName);

imagecopyresized($thumb, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);

imagejpeg($thumb,$dest);
}

RP2040 Zero で MicroPython を使う

  埋め込み用マイコンでも Python を動かせる MicroPython というものがあります。 リアルタイムでコマンドラインからマイコンを動かせる画期的なシステムなので、ちょっとした感動が味わえます。 使い方としては、まずファームウエアをアップロードしてドライブとして認識さ...