Friday, 3 September 2010

create flash(swf) file using PHP libming

My boss ask me to make a flash website, something like twinkle star. Since we don't have the Adobe Flash software so I think there should be some alternative. After google it, spend a day to search and learn some alternative, finally I choose Ming.

The Ming has support for PHP and it called libming. It make swf(flash) file using PHP. I learned PHP before so it is easy for me.

My server is running Debian Lenny 5.0. The lastest libming version is 0.4.3. In Debian 5.0 libming is 0.3.0 and in Ubuntu 10.04 the libming is 0.4.3.
I don't what to install any unstable package in the Debian server so I install a Ubuntu client.

After install ubuntu, I only install some PHP packages :

$sudo apt-get install php-cli php-common php5-ming

and others necessary packages will be installed automatically. php-cli is command line interface, that means we can run php file in console mode, not in web server.

This is the star.png file with transparency background:






Example ONE :
This php script creates a very simple static swf file. It place a star.png file on movieclips only.
<?php
Ming_useSWFVersion(5); // set flash version 5
$png= new SWFBitmap(file_get_contents("star.png","r"));
$m = new SWFMovie();
$m->add($png);
$m->setDimension(143, 143); // the flash dimension
$m->setBackground(0, 0, 0); // background color is black since star is white
$m->setRate(12.0);
$m->setFrames(20);
header('Content-type: application/x-shockwave-flash');
$m->save("static.swf",9); // save to file, compression rate: 1 - minimun , 9 - maximum
?>

Save the file as static.php In console, type
$php static.php

then it will create a static.swf file at same directory.

If you have a web server installed, you may see the result on browser. At last line, change
$m->save("static.swf",9);
to
$m->output(); // to screen

Let's the server ip is 192.168.1.1. In browser, type http://192.168.1.1/static.php, then the flash file will show on screen. It is a static flash, like a picture display on screen.

To make the star twinkle, we need some transition effect : fade in then fade out so that it look like twinkle.

Here is some tutorial for transition effect,
http://www.opaque.net/ming/tutorial/index9.html

To use transition effect, you need to download the file flashdot.tag or lashdot.zip, extract it(there are 5 files) and copy 2 files : infuncs.php and outfuncs.php.

In infuncs.php you have to comment out the line 8, like this :
// $i->moveTo(600,30);

Example TWO :
It has fade in then fade out effect :
<?php
Ming_useSWFVersion(5); // set flash version 5
include('infuncs.php');
include('outfuncs.php');
$png= new SWFBitmap(file_get_contents("star.png","r"));
$m = new SWFMovie();
$instance = fadein($m, $png);
fadeout($m, $png, $instance);
$m->setDimension(143, 143); // the flash dimension
$m->setBackground(0, 0, 0); // black color since star is white
$m->setRate(12.0);
$m->setFrames(20);
header('Content-type: application/x-shockwave-flash');
$m->save("twinkle.swf",9); // save to file, compression rate: 1 - minimun , 9 - maximum
?>


Save the file as twinkle.php. In console, type
$php twinkle.php

It made a twinkle.swf flash file.

This is the swf file :



Ming core library is under the LGPL license. Ming's command line ActionScript compiler (makeswf) is distributed under the GPL license.

That means, it is free.

Wednesday, 11 August 2010

make bootable CD in win32

Usually we use mkisofs to make bootable CD in Linux. There is also mkisofs win32 package :

http://www.student.tugraz.at/thomas.plank/index_en.html

Download 3 zip files, save into d:\cdrtools folder and uncompress all files.
- cdrtools-xxx-win32-bin.zip
- dlls.zip
- DLL version 1.7.5

I use grub4DOS as boot loader, download it at http://sourceforge.net/projects/grub4dos/files/
Get the grub4dos-0.4.4.zip and uncompress. I will save the zip file into d:\grub4dos folder.

At DOS console, type

D:\cdrtools>copy d:\grub4dos\grlder
D:\cdrtools>mkisofs -R -b grldr -no-emul-boot -boot-load-size 4 -o grldr.iso .
Setting input-charset to 'UTF-8' from locale.
mkisofs: './grldr.iso' is the archive. Not dumped.
Size of boot image is 4 sectors -> No emulation
Total translation table size: 2048
Total rockridge attributes bytes: 5027
Total directory bytes: 6144
Path table size(bytes): 34
Max brk space used 30000
4910 extents written (9 MB)

Caution : The last character of mkisofs command IS "."

Output file is grldr.iso. Burn the grldr.iso file into CD. Finished.

Monday, 2 August 2010

Debian 5 Lenny NFS

Just setup a NFS server on Debian Lenny, then mount the nfs folder and got error message :

support@client03:~$ sudo mount -t nfs 192.168.0.9:/media/HD /media/iso
mount.nfs: 192.168.0.9:/media/HD failed, reason given by server: Permission denied

Usually the problem is file /etc/exports, /etc/hosts.allow and /etc/hosts.deny

For file /etc/exports, usually many people say I can do like this to share the folder for while subnet :
/media/HD 192.168.0.0/24 (ro)

But it doesn't work.

In Debian Lenny, I have to make it as below. It solved the "Permission denied" problem.
/media/HD 192.168.0.0/255.255.255.0 (ro)

Saturday, 24 July 2010

校園O嘴事件簿 - 作者華容道



這書是說有關於校園內外發生事情, 主⻆大多是學生。 家長們只能在家內觀察自己子女,在家外便一無所知。讀過這書, 或多或少可了解時下學生行為和心態, 家長們亦可多些了解自己子女。

作者華容道是我舊同學, 他第一次出書, 期代有第二集、第三集、....第N集。

Thursday, 22 July 2010

由繁體中文 utf8 檔案轉為簡體中文 utf8 檔案

由 繁體中文 utf8 -> BIG5 ->GB -> 簡體中文 utf8
$ iconv -f utf8 -t big5 note.tw.utf8 > note.big5
$ iconv -f big5 -t gb2312 note.big5 > note.gb
$ iconv -f gb2312 -t utf8 note.gb > note.cn.utf8

可用pipe簡化 為一 command :
$ iconv -f utf8 -t big5 note.tw.utf8 | \
> iconv -f big5 -t gb2312 | \
> iconv -f gb2312 -t utf8 > note.cn.utf8

參考 :
http://samuelololol.blogspot.com/2009/11/mplayer-iconv.html


最簡單方法 :
$ cconv -f UTF8-TW -t UTF8-CN note.tw.utf8

cconv 是很新的程式, 但很好用,希望它繼續發展, 令翻譯工作更加方便。

它的homepage :
http://code.google.com/p/cconv/

Friday, 9 July 2010

Joomla SEO (二) : 404

網頁顯示404有很多原因, 例如輸入錯誤網址。

有二種方法解決Joomla 404 問題 :
1. 安裝 extension
2. 改 Joomla code

1. Joomla extension :
http://extensions.joomla.org/extensions/site-management/sef
這些 extension 是幫助你的site在SEO 做得更好, 解決404是功能之一。

各extension比較, 一目了然 :
http://www.alledia.com/blog/seo/joomla-15-seo-extension-comparison/

最有名是 sh404SEF, 但是收費的。

2. 改 Joomla code

其實網頁顯示404都有二種error message :
I.
中間紅色box 和顯示404 - Component not found

II.
Not Found
The requested URL /xxx was not found on this server.

這是Joomla official tutorial
http://docs.joomla.org/Tutorial:Create_a_Custom_404_Error_Page

如果看不明, 可以跟我方法, 我是用JA_Puity template

解決 I) 問題 :
1. 複製檔案 由 /templates/system/error.php 去 /templates/ja_purity/error.php
2. 修改檔案 error.php :

在這行之下(約第14行)
defined( '_JEXEC' ) or die( 'Restricted access' );
加入

if (($this->error->code) == '404') {
header('Location: index.php');
exit;
}

儲存


解決 II) 問題 :
在website目錄最上層新加檔案 .htaccess

.htaccess 內容 :
ErrorDocument 404 /index.php


完成後每次user打錯網址, 都會自動轉到首頁。

Wednesday, 7 July 2010

Joomla SEO : 改 page title

幫朋友做完了website, backend 是Joomla v1.5。 現在要優化它, 第一步要做就是Search Engine Optimization,SEO, 這 topic 一直很hit。

我要每一page title 都加上公司名稱, (即在browser最頂那一行) ,這功能對於 SEO 是重要的。但不知可解, 在Joomla就是沒有項功能。

通常有二種方法解決Joomla 問題 :
1. 安裝 extension (component/plugins)
2. 改 Joomla code

1. 安裝 extension 是最快捷方法, 功能多, 而且一定成功。在 Joomla Extension -> Site Management->SEO &Metadata, 有很多好用的extension :
http://extensions.joomla.org/extensions/site-management/seo-a-metadata

如只想改page title , 可以選擇 :
Title Manager Plugin
http://extensions.joomla.org/extensions/site-management/seo-a-metadata/3521

Website Name PluginLanguage
http://extensions.joomla.org/extensions/site-management/seo-a-metadata/3352

從安裝到完成, 不須五分鐘。


2. 改 Joomla code是很麻煩的, 又不一定成功。

這是英文教學 :
http://www.howtojoomla.net/2008060586/how-tos/templates/how-to-display-your-page-title-in-your-template-joomla-15

這是中文教學 :
http://www.hksilicon.com/kb/articles/648/1/Joomla-15----lttitlegt/Page1.html

但他們方法都有一個小問題, 是發生在 home page上, 如果你的公司名稱是"美好公司" , 而在front page又設定顯示"美好公司", home page title 會顯示 :

美好公司 - 美好公司


解決方法很簡單, 這是我的 code :


<?php

$mydoc =& JFactory::getDocument();
$mytitle = $mydoc->getTitle();

$conf =& JFactory::getConfig();
$sitename = $conf->getValue('config.sitename'); // get site name

if ($mytitle == $sitename) // check same title and sitename
$mydoc->setTitle($sitename);
else
$mydoc->setTitle($mytitle.' - '.$sitename);

?>

Tuesday, 18 May 2010

Joomla : QContacts 繁體中文 language pack

Joomla 內的 contact module 基本上是好用的, 但中文化後有點問題, 所以要轉用其他 module。 我選擇了 QContacts。 在 QContacts official site 只簡體中文 language pack, 沒有繁體中文(或稱正體中文, traditional chinese),我把簡體language pack轉為繁體,QContacts 版本是v1.06, 你們可在這裡下載, :

http://www.4shared.com/file/69DDSXWw/zh-tw_com_qcontacts_site.html

下載後請留言, 謝謝。

Thursday, 29 April 2010

Linux作業系統之奧義



http://www.delightpress.com.tw/book.aspx?book_id=SKNS00001

這書說明 Linux 開機流程 由 BIOS -> MBR -> GRUB -> init -> command shell 或 X Windows。

目錄 :
 第1章 BIOS
     BIOS和作業系統的關係,將在本章完全展現出來。
     何謂BIOS‧Power On‧POST‧BIOS資訊‧BIOS修護‧硬碟第零軌(MBR)‧BIOS與作業系統的交接
 第2章 開機管理程式
     何謂MBR?與GRUB的關係為何?GRUB的運作模式又如何?
     何謂GRUB‧GRUB的設定方式‧多重開機的管理‧GRUB安裝‧除錯方式‧拯救無法開機的情況
 第3章 Kernel與initrd
     開機時,為何會需要Kernel與initrd兩個檔案?
     何謂Kernel‧編譯Kernel‧何謂initrd‧開機時常用的Kernel參數
 第4章 initrd中的init
     說明initrd的init檔所扮演的角色與其重要性。
     認識nash‧掛載主要的檔案系統‧建立設備檔所需要的檔案系統‧轉移前的準備
 第5章 init
     在Linux作業系統中另外存在的一個init執行檔,與initrd的init有何差異?
     Init的基本結構‧/etc/rc.d/rc.sysinit‧/etc/rc.d/rcX.d‧透過登入程式進入Shell
 第6章 系統檢查
     當一台主機裝好Linux,有哪些隱藏在系統背後的問題是平常看不到的?
     硬體部份‧ext3與Journaling‧韌體部份
 第7章 系統效能
     如何針對不同的系統運用測試正確的系統效能項目。
     效能調校‧硬體測試
 第8章 X Window System
     X Window的啟動原理以及各元件的介紹。
     X重要元件‧進入X Window流程之差異‧實作X Window之Client-Server
 第9章 Virtual Machine
     目前最新的XEN是如何運作。

這是一本很好的工具書, 了解開機過程後, trobule-shoot 都變得容易。

第二版都出版了 :
http://www.delightpress.com.tw/book.aspx?book_id=SKNS00005

這裹有更加詳細解釋 :
http://www.csl.mtu.edu/~machoudh/blog/?p=258

很多時都見到網友問: install linux 之後, 不能進入 linux。 這問題發生次數比 windows 多, 是主機版(motherboard)太新/太多, linux 開發人員不能每項都測試, 還是主機板開發商只在 Widnows 上測試呢 ? 看來 linux 開發人員要加把勁了。

Thursday, 8 April 2010

Joomla

Joomla 近來好hit, 我也正在學習, 真係幾好用, 可以用很短時間起個 website。 我係問題兒童, 我又開始對Joomla 有問題 :

1. 它是行php, 雖然php 對電腦power要求很低, 但有一定影響。大部分公司website 是 host 在 web-hosting 公司, 如果很多公司都轉用Joomla, web-hosting 電腦相對會變慢, 即係load 網頁時會慢。
2. 它要用 database (e.g. MySQL)來儲存資料。第一項已說出大部分公司website 是 host 在 web-hosting 公司,一般公司都是用平價plan, 是沒有 database 功能, 如果有 database 每月加 30-50元不等, web-hosting 公司生意會否因此而多了呢?

Friday, 12 March 2010

不可!為什麼? 陳雪濤著



這本書是向你說不, 不要這樣做, 不要那樣做, 例如 :
-不要胡亂放置水晶物品
-不要在大門前放置鞋 (這個我同意)

至於應該怎樣做才對呢, 他不會說的。因為做錯了後果會很嚴重。

Monday, 8 March 2010

仲有好多問題

我而家經常有好多問題想問, 但係又無人答我。有時我發問, 他們不想答, 時常說我煩。