Hayk Saakian
Hayk Saakian

Reputation: 2036

Turn a human readable string into an image to be displayed with data-uris

Is there any conventional way to turn an arbitrary string into an image?

In my use case, lets say I want to have an image for each user that maps directly to that user's name.

The concept is similar to QR codes, except the output image is not designed to be readable, simple pretty and consistent.

ultimately i want something like:

def to_image(a_string)
    ... #magic
    return a_data_uri
end

such that

# is always true
to_image("specific string") == to_image("specific string")

Ideally you'd end up with some nice looking fractal-art like image.

If what I'm describing is nonsensical, a function that can convert a string to a data-uri containing a qr code will do.

Upvotes: 0

Views: 194

Answers (1)

user2166954
user2166954

Reputation: 1

One possibility would be to hash the strings - this gives you unique numbers as output. Then you can pass these numbers as input param to a fractal generating function.

For hashing either use a real hash function, or (in case the number of users is limited) you can use a CRC function (CRC16, CRC32). Both approaches will give you uniques numbers as output. For CRC you must be a little bit more careful - for instance having 60K input strings and using CRC16 might end up with some clashes (different strings - same CRC16 number).

Upvotes: 0

Related Questions