Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need ideas for a compression algorithm

Tags:

compression

Background: I'm making a web-based avatar generation system, where a user can select pieces for his avatar (like body, background, eyes, mouth, jacket, pants, etc.) and then a picture is generated from these selections. For performance reasons I then intend to do the following: from the list of selected items generate a filename which contains their IDs and save the picture under this filename. Then, when a request comes for a picture, the webserver will serve it directly. If a picture is not found, the 404-handler will generate it. And here then is the problem:

Question: I would like to compress a list of integers in as short a string as possible, consisting only of ASCII characters (usable for filenames and URLs). The integers will be unique, and greater than 0 (0 itself will not be among them). I expect that there might be around 20 of them and they would not exceed 200, but that is only a guess (though I'd be surprised if they got past 500). The order is not important.

What do you recommend I should do?

Update: Whoops, it seems I have made a fundamental mistake. I wanted to avoid storing every generated avatar in the DB, instead storing all necessary information in the filename. This way I hoped to avoid unnecessary use of DB and thus increased performance. However today it struck me that people might want to change their avatars, and expect them to update everywhere where they've been used. Thus, the filename has to be constant. This then leaves just one option - I'll have to save info about the avatar in the DB. And then I might as well use GUIDs or some other random strings for the filenames.

Thank you for your help, everyone, and sorry for the false alarm. :(

like image 679
Vilx- Avatar asked Apr 15 '26 02:04

Vilx-


1 Answers

Concatenate the integers (9 bits per item) into an array of bytes, and then encode the result in Base64.

like image 129
Doug Currie Avatar answered Apr 17 '26 16:04

Doug Currie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!