How To Read And Write Windows Folder Or File in UTF8

When you are working on Windows, sometimes you may meet a problem like your code cannot find the folder or file by the giving name. But when you manually check it, the specific folder or file exists in the give path. This problem always comes out when your folder name or file name is Unicode characters, such as Chinese, Japanese, or Tamil.

For example, the Chinese character in Windows is not encoded by UTF8, but CP936 (CP936 is considered the same as GBK, though they are different). Code page 936 (CP936) is Microsoft’s character encoding for simplified Chinese. Though it was superseded by BG18030(code page 54936), but it was still used in Windows 7 and later version.

This encoding problem also happens when you copy some files from windows to linux. In Linux, the locale is set to UTF-8. Hence, when you copy the files from windows, whose file name is encoded in gbk or gb18030, the files name will become unreadable.
Read more

Create Transparent PNG Image in PHP

This is a very old topic. When I search this title online, I can get some articles which are published as early as 2003. Though there are so many reference, it still takes me a huge amount of time to figure this out when I am working on my open source project “Free Online Sprite Sheet Decomposer“. The concept of this project is dividing the PNG sprite sheet into pieces of frame by frame png files. The challenge is copying the color info from source image to the destination image and keeping the transparent info as the same. However, PNGs have several different types and each type supports the transparency feature in different way. For more details, you can check this article: Transparency Concept in PNG.
Read more

Transparency Concept in PNG

Transparency is fully supported in PNG, but it is very complicated to manipulate in program. PNG supports three main types: truecolor(rgb or 24-bit), grayscale, and palette-based(8-bit). All of them can have alpha information, but it’s most commonly used with truecolor image. The truecolor (RGB) PNGS, are supported in only two depths: 8 and 16 bits per sample (for each pixel, generally 8 bits or 16 bits are used for each channel), corresponding to 24 and 48 bits per pixel. Normally, the truecolor is 24 bits per pixel. The truecolor png with alpha channel is known as RGBA (32-bit). This transparency feature is important to create special effects such as making a central oval region fully opaque, the outer regions fully transparent, and the transition region that varies smoothly between the two extremes. A real case is a square picture with a solid red ball with shadow. The solid red ball is fully opaque, the shadow is transition region, the rest of space is fully transparent.
Read more

Build A SVN Backup System With Microsoft OneDrive

If you have some private projects and you want to use SVN to take the version control, you may meet the problem I have met. I am hosting the svn on my Window desktop in private network, but sometimes I am doing my job on laptop when I am travelling. It’s very hard to synchronise the code between each other. So I find a solution by hosting the SVN repository on Microsoft OneDrive then I set up a SVN on both my home desktop PC and my laptop. On each computer, I also install the Microsoft OneDrive software which will synchronise the repository automatically. The only problem here is I must make sure the repository is up to date before I make any changes (commit usually) in the repository.
Read more