Pages

2009年4月21日星期二

php image manipulation

Create a thumbnail

function createThumbnail($img, $imgPath, $suffix, $newWidth, $newHeight, $quality)
{
// Open the original image.
$original = imagecreatefromjpeg("$imgPath/$img") or die("Error Opening original");
list($width, $height, $type, $attr) = getimagesize("$imgPath/$img");

// Resample the image.
$tempImg = imagecreatetruecolor($newWidth, $newHeight) or die("Cant create temp image");
imagecopyresized($tempImg, $original, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height) or die("Cant resize copy");

// Create the new file name.
$newNameE = explode(".", $img);
$newName = . $newNameE[0] .. $suffix .‘.’. $newNameE[1] .;

// Save the image.
imagejpeg($tempImg, "$imgPath/$newName", $quality) or die("Cant save image");

// Clean up.
imagedestroy($original);
imagedestroy($tempImg);
return true;
}
?>

Rotate

function rotateImage($img, $imgPath, $suffix, $degrees, $quality, $save)
{
// Open the original image.
$original = imagecreatefromjpeg("$imgPath/$img") or die("Error Opening original");
list($width, $height, $type, $attr) = getimagesize("$imgPath/$img");

// Resample the image.
$tempImg = imagecreatetruecolor($width, $height) or die("Cant create temp image");
imagecopyresized($tempImg, $original, 0, 0, 0, 0, $width, $height, $width, $height) or die("Cant resize copy");

// Rotate the image.
$rotate = imagerotate($original, $degrees, 0);

// Save.
if($save)
{
// Create the new file name.
$newNameE = explode(".", $img);
$newName = . $newNameE[0] .. $suffix .‘.’. $newNameE[1] .;

// Save the image.
imagejpeg($rotate, "$imgPath/$newName", $quality) or die("Cant save image");
}

// Clean up.
imagedestroy($original);
imagedestroy($tempImg);
return true;
}

?>

Resize

function resizeImage($img, $imgPath, $suffix, $by, $quality)
{
// Open the original image.
$original = imagecreatefromjpeg("$imgPath/$img") or die("Error Opening original ($imgPath/$img)");
list($width, $height, $type, $attr) = getimagesize("$imgPath/$img");

// Determine new width and height.
$newWidth = ($width/$by);
$newHeight = ($height/$by);

// Resample the image.
$tempImg = imagecreatetruecolor($newWidth, $newHeight) or die("Cant create temp image");
imagecopyresized($tempImg, $original, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height) or die("Cant resize copy");

// Create the new file name.
$newNameE = explode(".", $img);
$newName = . $newNameE[0] .. $suffix .‘.’. $newNameE[1] .;

// Save the image.
imagejpeg($tempImg, "$imgPath/$newName", $quality) or die("Cant save image");

// Clean up.
imagedestroy($original);
imagedestroy($tempImg);
return true;
}

?>

Reduce

function reduceImage($img, $imgPath, $suffix, $quality)
{
// Open the original image.
$original = imagecreatefromjpeg("$imgPath/$img") or die("Error Opening original ($imgPath/$img)");
list($width, $height, $type, $attr) = getimagesize("$imgPath/$img");

// Resample the image.
$tempImg = imagecreatetruecolor($width, $height) or die("Cant create temp image");
imagecopyresized($tempImg, $original, 0, 0, 0, 0, $width, $height, $width, $height) or die("Cant resize copy");

// Create the new file name.
$newNameE = explode(".", $img);
$newName = . $newNameE[0] .. $suffix .‘.’. $newNameE[1] .;

// Save the image.
imagejpeg($tempImg, "$imgPath/$newName", $quality) or die("Cant save image");

// Clean up.
imagedestroy($original);
imagedestroy($tempImg);
return true;
}

?>

The simple instructions I used for the examples

$thumb = createThumbnail($img, $imgPath, "-thumb", 120, 100, 100);
$rotate = rotateImage($img, $imgPath, "-rotated", 270, 100, 1);
$resize = resizeImage($img, $imgPath, "-resized", 2, 100);
$reduce = reduceImage($img, $imgPath, "-reduced", 70);
?>

Those are the function calls i used to create the images linked to below.

createThumbnail variables
image file
image file path
suffix to append to the name before the .jpg
thumbnail width
thumbnail height
thumbnail quality

rotateImage variables
image file
image file path
suffix to append to the name before the .jpg
degrees to rotate (anticlockwise i think) by
image quality
save or not (if you wanted to output to a temp to preview, i dont use it, so leave as 1

resize variables
image file
image file path
suffix to append to the name before the .jpg
resize by (i used 2 which i thought was half.. not so hot on the maths)
image quality

reduce variables
image file
image file path
suffix to append to the name before the .jpg
quality (100 best, 0 worst… Duhh).

Here are the links to my examples
Original File (904k (1840×1232))
Thumbnail (16k (120×100))
Resized and Reduced (24k (368×246))


ref: http://nodstrum.com/2006/12/09/image-manipulation-using-php/#more-7

2009年4月16日星期四

電腦跑得太慢, 有何妙法?

電腦跑得太慢, 有何妙法?

灌軟體也能輕鬆清除系統垃圾檔案(加強版)+發揮你網路應有的速度!! 是否注意到你的電腦系統磁盤的可用空間正在一天天在減少呢?是不是動作一天比一天遲緩呢?


在Windows在安裝和使用過程中都會產生相當多的垃圾文件,包括臨時文件(如:*.tmp、*._mp)日誌文件(*.log)、臨時幫助文件(*.gid)、磁盤檢查文件(*.chk)、臨時備份文件(如:*.old、*.bak)以及其他臨時文件。特別是如果一段時間不清理IE的臨時文件夾「Temporary Internet Files」,其中的緩存文件有時會佔用上百MB的磁盤空間。這些LJ文件不僅僅浪費了寶貴的磁盤空間,嚴重時還會使系統運行慢如蝸牛。現在就讓我們一起來快速清除系統垃圾吧!!

下面是步驟很簡單就兩步!

打開「記事本」,把下面的字複製進去,點「另存為」,把文件名定為「清除系統垃圾.bat」就完成,記住後副檔名一定要是.bat,好ok了!你的垃圾清除器就這樣製作成功了!雙擊它就能很快地清理垃圾文件,大約一分鐘不到。

@echo off
echo 正在清除系統垃圾檔案中,請稍候......
del /f /s /q %systemdrive%\*.tmp
del /f /s /q %systemdrive%\*._mp
del /f /s /q %systemdrive%\*.log
del /f /s /q %systemdrive%\*.gid
del /f /s /q %systemdrive%\*.chk
del /f /s /q %systemdrive%\*.old
del /f /s /q %systemdrive%\recycled\*.*
del /f /s /q %windir%\*.bak
del /f /s /q %windir%\prefetch\*.*
del /f /q %userprofile%\cookies\*.*
del /f /q %userprofile%\recent\*.*
del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*"
del /f /s /q "%userprofile%\Local Settings\Temp\*.*"
del /f /s /q "%userprofile%\recent\*.*"
DEL /S /F /Q "%systemroot%\Temp\*.*"
DEL /S /F /Q "%AllUsersProfile%\「開始」功能表\程式集\Windows Messenger.lnk"
RD /S /Q %windir%\temp & md %windir%\temp
RD /S /Q "%userprofile%\Local Settings\Temp"
MD "%userprofile%\Local Settings\Temp"
RD /S /Q "%systemdrive%\Program Files\Temp"
MD "%systemdrive%\Program Files\Temp"
RD /S /Q "%systemdrive%\d"
net user aspnet /delete
echo 清除系統垃圾檔案完成!!
echo. & pause

==============================
複製上面的字

以後只要雙擊運行該文件,當屏幕提示「清除系統垃圾完成!就還你一個「苗條」的系統了!!到時候再看看你的電腦,是不是急速如飛呢?

電腦當了不用重灌

電腦當了不用重灌

有時候,會因為某些不明原因造成無法進入Windows系統中,甚至連安全模式都沒辦法起動。
若你的硬碟資料都還在的話,那可以利用scanreg這個登錄檔程式,讓你的系統恢復至幾天前的模樣......

操作方式如下:
1當開機進入Windows之前,按[F8]
2選擇[5.Cmmand prompt only]項
3出現C:\\>後,輸入scanreg /restore
4選擇一個日期檔,注意日期盡量是電腦未死當機前的日期,輕輕地按下ENTER.....就可恢愎原貌

2009年4月1日星期三

幫xp減肥

咁簡單啦...

首先....關閉 "系統還原" 及 關閉 "分頁檔案"

再來...刪除以下的檔案

C:\WINDOWS\Driver Cache\i386 (刪除入便所有檔案)

C:\WINDOWS\system32\dllcache (刪除入便所有檔案)

C:\WINDOWS\ime (只係保留要用的輸入法,刪除唔要的檔案)

C:\WINDOWS\Help (刪除入便所有檔案)

刪除左以上的野...應該都清左唔少出來嫁啦..