3

Context:

  • I am using python 2.6.5

Goal:

  • Read a binary image file and represent it in-memory. Then run a checksum on it. Deliver the binary representation to be stored as a blob in mysql.

Comments:

  • I have read this SO thread.
  • I have looked at the struct module.
  • I also have bumped into the io module.
  • With all the available options, I am not certain which is the best solution. The BytesIO data structure seems to be suitable for my needs. Which one do you think will meet my requirements ?
2
  • When you read the blob back from mysql, will you be working with it as an image or just writing it back to a file? Commented Feb 22, 2012 at 21:42
  • Please up vote and select one of the 2 below and select an answer if applicable Commented Feb 23, 2012 at 0:13

2 Answers 2

4

I'd recommend using PIL (Python Image Library)

http://effbot.org/imagingbook/pil-index.htm

Save it down to a string and then write to the db. Then you can use the string butter interface to PIL to read it back out.

Sign up to request clarification or add additional context in comments.

Comments

0
>>> from binascii import crc32
>>> with open(filename, "rb") as f:
...     data = f.read()
...
>>> crc32(data)
361260080

1 Comment

This calculates a checksum of the file, not the checksum of image data. . This means it will generate a different checksum for 2 .pngs with identical image but different metadata. Might be relevant

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.