Compressing Text by converting into Images

Compressing Text by Images
This is an algorithm that can be used to Compress files.This can be used to compress the files by converting files into images.

Zip format and Rar format:
You must have heard about Zip and RAR formats which are used to compress files so that they occupy smaller space.Those Zip and RAR formats use Central Directory and insert a backdoor entry for those

My format:

Compression:

This algorithm can be used to compress characters by converting them into pixels of a image.E.g 3 characters in the file are converted into RGB values of a pixel and pixels are combined to get a image

RGB- Red,Green,Blue values of a pixel.Each pixel is defined by it’s RGB values .In real time there are 256X256X256 colors

(compressed format)

Decompression:

The pixels of the image(compressed) are read by the script and the RGB values are converted into characters.

Steps involved in it :
First Step:
Get the Contents of the File.

Second Step:
Split the characters in the file into chunk of 3.

Third Step:
Get the count of chunks

Fourth Step:
Convert of each of the character into Decimal using ASCII table

Fifth Step:
Then set the pixel it a particular point using (R,G,B)

Sixth Step:
Then increment it to next level

Seventh Step:
Then repeat steps 4-7 for another chunk.

Eight Step:
Join the pixels to get the image

.

E.g
Let us take the word Sachin
Step 1:
“Sachin”

Step 2:
1—>”Sac”
2—>”hin”

Step 3:
Count of chunks:2 (Since “Sac”,”hin”)

Step 4:

For Sac:
Converting each character into ASCII value
So
“Sac”==>”83,97,99″
“hin”==>”104,105,110″

step 5:
RGB values of pixel at x=1 and y=1 would be (83,97,99) ===>(Sac)
RGB values of pixel at x=2 and y=1 would be (104,105,110)===>(hin)

Step 6:
these pixels would be combined to form a image..

Decompression:

Step 7:

pixels of the image would be read by the script and converted into RGB values
In this case
pixel 1: (83,97,99)
pixel 2: (104,105,110)

Step 8:
RGB Values would converted to ASCII characters

83—->S
97—->A
99—->C
104—>H
105—>I
110—>N

We will get the original Text..”SACHIN”

Compression:
This algorithm is used to compress characters by converting them into pixels of a image.E.g 3 characters in file are converted into RGB values of a pixel and pixels are combined to get a image

Decompression:
Pixels are converted into characters and they are joined at the end to get the original file.

Results:
Original File Size:3.00 MB
Zip:2.35 MB
My format~2.40 MB

Difference is just 2~4% between my format and Zip. I think this can be further reduced by using mathematical techniques in reducing the RGB values which is possible..

I was able to reduce a 721 KB Media file into 649 KB file by manipulation techniques..(Zip format and Rar format were able to reduce only to 700KB)

I think someone better than me who have more time would be able to bring in some new methods using this algorithm.

Files are attached with this post..

Compress.php

Decompress.php

http://www.ramanean.com/Compression-Images.zip

a)There would be two variables sourcefilename and targetfilenamesourcefilename=>name of the file that would be compressed (the file has to be in the same folder as compress.php)
targetfilename->name of the compressed file (after compressing)

b)At the top of the file decompress.php ,there would be two variables sourcefilename and targetfilename sourcefilename=>name of the file that would be decompressed (the file has to be in the same folder as decompress.php) targetfilename->name of the decompressed file (after decompressing)

This entry was posted on Thursday, May 14th, 2009 at 12:58 am and is filed under General. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

Post a Comment